diff --git a/day2.retro b/day2.retro index 5a5aba7..825cf5e 100644 --- a/day2.retro +++ b/day2.retro @@ -15,8 +15,7 @@ The `read-move` word is used for every command in the file. :read-move (s-) ASCII:SPACE s:split/char 'forward [ s:trim s:to-number @hpos + !hpos ] s:case 'up [ s:trim s:to-number @depth swap - !depth ] s:case - 'down [ s:trim s:to-number @depth + !depth ] s:case -; + 'down [ s:trim s:to-number @depth + !depth ] s:case ; ~~~ And run this on the whole file, printing the results: @@ -28,4 +27,24 @@ And run this on the whole file, printing the results: ## part 2 -TODO +basically like part 1 but we need a new variable and to change some of the move-reading logic. + +~~~ +#0 !depth +#0 !hpos +'aim var +~~~ + +~~~ +:read-aim (s-) ASCII:SPACE s:split/char + 'forward [ s:trim s:to-number dup @hpos + !hpos @aim * @depth + !depth ] s:case + 'up [ s:trim s:to-number @aim swap - !aim ] s:case + 'down [ s:trim s:to-number @aim + !aim ] s:case ; +~~~ + +And run this on the whole file, printing the results: + +~~~ +'input2 [ read-aim ] file:for-each-line +@depth @hpos * n:put ASCII:LF c:put +~~~