day 2 part 2

This commit is contained in:
Nico 2021-12-02 09:24:12 +00:00
parent 737bd7c239
commit f097b78760
1 changed files with 22 additions and 3 deletions

View File

@ -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
~~~