day 2 part 1 done
This commit is contained in:
parent
00c29ca217
commit
737bd7c239
|
@ -0,0 +1,31 @@
|
|||
# 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
|
Loading…
Reference in New Issue