day 2 part 2
This commit is contained in:
parent
737bd7c239
commit
f097b78760
25
day2.retro
25
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
|
:read-move (s-) ASCII:SPACE s:split/char
|
||||||
'forward [ s:trim s:to-number @hpos + !hpos ] s:case
|
'forward [ s:trim s:to-number @hpos + !hpos ] s:case
|
||||||
'up [ s:trim s:to-number @depth swap - !depth ] 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:
|
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
|
## 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
|
||||||
|
~~~
|
||||||
|
|
Loading…
Reference in New Issue