Back to Browse

Swift Playgrounds - Roll Right, Roll Left - Modular & Simple Solution

1.1K views
Jan 26, 2017
2:43

Here is my modular & simple solution to the "Roll Right, Roll Left" exercise in Apple's Swift Playgrounds. This exercise can be found under "Learn to Code 1 - Fundamentals of Swift". Basically, there are two different types of actions we're taking here. One for the gem row and another for the switch row. Each one is represented with its own function - g() and s(). Notice that there are 6 rows in total, in the order starting from in front of Byte; they're gem, switch, switch (split into two rows with a teleport - which is a bit tricky), gem, switch and finally a gem row. Gem rows start with a gem and end at the platform edge. The switch rows also starts with a switch, however they do end with another switch - not at the platform edge. So for the switch row processor, which is the function named s(), we keep going until we see another switch - whereas on the gem row processor, we continue until hitting the edge of the platform. Finally, we understand that our mission is complete thanks to the unique tile that is at the top left corner of the platform - which is blocked on 3 sides.

Download

1 formats

Video Formats

360pmp45.3 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Swift Playgrounds - Roll Right, Roll Left - Modular & Simple Solution | NatokHD