Hello Clodsire, I finally got the first part of the first task done, do you want to see some FORTH code?
(My first idea was a weird Binary Coded Decimal - type version for the PDP-8 in assembly, but I gave up because I'm clearly too stupid for that, so I decided to use the OpenBoot FORTH environment on a Sun JavaStation instead)
Advent of Code, day 1, part 1
variable lock
variable cnt
variable lines
here 5 allot constant buf
: init-lock d# 50 lock ! 0 cnt ! 0 lines ! ;
: dir key dup emit dup
52 ( R ) = if drop 1 else
4c ( L ) = if -1 else 0 then then ;
: getnum base @ decimal
buf 5 2dup 2dup blank expect -trailing $number
if abort" Number conv failed" then
swap base ! ;
: process init-lock
begin dir ?dup while 1 lines +!
getnum * d# 100 + lock @ + d# 100 mod
dup 0= if 1 cnt +! then
lock ! repeat ;
: results cr
." Lock at: " lock @ . cr
." Count: " cnt @ . cr
." Lines processed: " lines @ . ;
Advent of Code, day 1, part 2
Only thing that needs to change is the process function, but it took me too long to get the details right:
: process init-lock
begin dir ?dup while 1 lines +!
getnum d# 100 /mod cnt +!
* lock @ +
dup d# 99 > over 1 < or lock @ and if 1 cnt +! then
d# 100 + d# 100 mod lock !
repeat ;
re: Advent of Code, day 1, part 2
@vaporeon_ i didn't end up getting a working solution for part 2, good job!
re: Advent of Code, day 1, part 2, spoilers
@vaporeon_ that edge case got me too! but something else was wrong after i accounted for it and i gave up haha