This file contains materials I created to teach programming. It is more or less a precursor to ΛV. Since then, I have decided to replace the A for the upwards-pointing cursor with a capital lambda. ΛV will also only have one of each condition and use ! to negate them. Prerequisite: ``` _______________ | | | | | | | | | | | | | | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` This needs to show up as a roughly square box. 1) Let’s start out by familiarizing ourselves with what things look like: Cursor: `< A > V` Wall/barrier: `| _ ¯ #` Goal: `$` ``` _______________ | # $# | | # ###### | |#### # | | > # | |###### | | | | | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Available instructions: step left right Possible solution: step step step left step step step right step step step step step 2) That’s quite simple. But it can get tedious really quickly: ``` _______________ |V#$ | | ############# | | # # | | # # | | # # | | ############# | | | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Available instructions: step left right repeat(INSTRUCTIONS) Possible solution: repeat<6>(step) left repeat<14>(step) left repeat<6>(step) left repeat<12>(step) 3) Same concept, different problem: ``` _______________ |>## | | ## | |# ## | |## ## | | ## ## | | ## ## | | ## $# | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Avaliable instructions: step left right repeat(INSTRUCTIONS) Possible solution: repeat<6>(right step left step) 4) Now in actual programming, running code repeatedly is a bit different. Instead of running a set number of times, which is certainly possible but not always desired, they usually run as long as a certain condition is met. This is called a loop. The most basic form it is known as a "while loop". ``` _______________ | | | | |############ | |> $# | |############ | | | | | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Available instructions: step left right while(INSTRUCTIONS) Available conditions: facing wall not facing wall Possible solution: while(step) Additional practice: ``` _______________ | #$ # | | ## # | | # # | | # # | | # # | | # # | | #A# | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` 5) Let’s turn this up a notch (copy+paste is gonna be real handy for this one): ``` _______________ | | | ############# | | #$# # | | # # # | | # # # | | # ########### | |A# | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Available instructions: step left right while(INSTRUCTIONS) Available conditions: facing wall not facing wall Possible solution: while(step) right while(step) right while(step) right while(step) right while(step) 6) Loops can also be nested inside other loops: ``` _______________ | | | ############# | | # # | | # ######### # | | # #$ # | | # ########### | |A# | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Available instructions: step left right while(INSTRUCTIONS) Available conditions: facing wall not facing wall goal reached goal not reached Possible solution: while(while(step) right) 7) We’ve already seen that conditions can be used to control loops. They can also be used to control if/else statements. I am going to introduce a new item here: `ó` apple Pick up all the apples in the area. You cannot use the "take" action when there is no apple to take. ``` _______________ | | | | | ##########| | #$ ó ó <| | ##########| | | | | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Available instructions: step left right take while(INSTRUCTIONS) if(INSTRUCTIONS) if(INSTRUCTIONS) else(INSTRUCTIONS) Available conditions: facing wall not facing wall goal reached goal not reached on apple not on apple Possible solution: while(if(take) step) 8) Let’s do the same but more: ``` _______________ |ó $| | ó ó | | | | ó | | ó | | ó ó | |> ó ó| ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ``` Available instructions: step left right take while(INSTRUCTIONS) if(INSTRUCTIONS) if(INSTRUCTIONS) else(INSTRUCTIONS) Available conditions: facing wall not facing wall goal reached goal not reached on apple not on apple facing north facing south facing east facing west Possible solution: while(if(take) while(step if(take)) if(left step left) else(right step right))