/kyrel

Learn Control Flow with Kyrel

Primary LanguageJavaScript

Kyrel

Kyrel is a simple browser-based game for learning about control flow and loops in javascript. It is reminiscent of a turing machine that manipulates a strip of tape, transforming it from an initial state to a final state.

Methods

The following special methods are available for traversing/transforming the row:

  • moveRight();
  • moveLeft();
  • useGreen();
  • useBlue();
  • draw();
  • erase();
  • onGreen();
  • onBlue();

Example Problem

Write a program which draws a green circle at the end of the row.

  function main() {
    moveRight();
    moveRight();
    moveRight();
    moveRight();
    useGreen();
    draw();
  }

This would result in the following transformation:

 ['.', '.', '.', '.', '.'] // start row (initial state)
 ['.', '.', '.', '.', 'g'] // end row (end state)

####Start:

####End:

Instructions

Fork and clone this repo!

There are three problem sets, organized by difficulty: day_1, day_2, day_3.

Solutions will be given at the end of the work session. Note that this means the solution links on the challenges sheets will be dead links at the beginning. Try your darndest to get to a solution before then. At the least, we are expecting to see an attempt at all challenges.

Using kyrel.js

If you look in kyrel.js you'll see this:

var initial_state = [ '.', '.', '.', '.', '.' ];

function main(n) {

  //////////////////////////////////
  ////                          ////
  //// v YOUR CODE BELOW HERE v ////
  ////                          ////
  //////////////////////////////////



  //////////////////////////////////
  ////                          ////
  //// ^ YOUR CODE ABOVE HERE ^ ////
  ////                          ////
  //////////////////////////////////

} // END MAIN
  • First, you need to manually configure your "starting row" (see kyrel.js#L22) to match the initial state of the problem you're solving.

    • var initial_state = ['.', 'b', '.', 'g', '.'] // kyrel.js#L22
      • 'b' means blue
      • 'g' mean green
      • '.' means empty
  • Next, write your instructions inside the main function in kyrel.js.

    • TIP: If you declare your variables at the very TOP of the kyrel.js file, your values will be in the "global scope". This will make it easier for you to see them in your console / play with them.
  • To run the program, open index.html in your browser and press "Play". This will execute the code you put in main.js.

    • TIP: Make sure to refresh the page whenever you make changes to your javascript!
    • PRO-TIP: Always have your Chrome Developer Console open (here's how), and make sure to check for error messages!
  • When you've completed a problem, save your work! Copy-paste your entire main function, as well as any variables you've declared above it, into a separate file called solutions.txt. Please record all solutions in a single document. It should look like sample_solutions.txt (but with more solutions, of course).

Inspiration

Adapted from Kyrel.

More information about turing machines:

Possible slides: Kyrel.pdf or: google docs