32 lines
617 B
Plaintext
32 lines
617 B
Plaintext
|
# Day 2: Dive!
|
||
|
|
||
|
## part 1
|
||
|
|
||
|
This one doesn't seem too difficult. Parsing a text file line-by-line and updating 2 variables based on that.
|
||
|
|
||
|
~~~
|
||
|
'depth var
|
||
|
'hpos var
|
||
|
~~~
|
||
|
|
||
|
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
|
||
|
;
|
||
|
~~~
|
||
|
|
||
|
And run this on the whole file, printing the results:
|
||
|
|
||
|
~~~
|
||
|
'input2 [ read-move ] file:for-each-line
|
||
|
@depth @hpos * n:put ASCII:LF c:put
|
||
|
~~~
|
||
|
|
||
|
## part 2
|
||
|
|
||
|
TODO
|