aoc-forth

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.alexwennerberg.com/aoc-forth
Log | Files | Refs | README

commit 24ebccd2013c7b899a6e7d5a753644a17b73e7ca
parent 34c1027157e7775b5aede370b8f972bb820a9db1
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 26 Aug 2022 10:55:39 -0400

add day 2

Diffstat:
M2021/02.fs | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/2021/02.fs b/2021/02.fs @@ -1,2 +1,40 @@ +h# 5000 constant filespace +: chartonum h# 30 - ; +: readline \ read a line to filespace + 0 begin dup + filespace + dup 1 fileread + swap c@ h# 0a <> and while ( not [newline or eof] ) + 1+ repeat drop +; + +variable xpos +variable ydepth + +: solvea + 1000 0 do readline + filespace c@ \ get direction + filespace 20 32 scan drop 1+ \ read until space + c@ chartonum swap \ get number + dup 102 = if \ 'f' + over xpos +! + then dup 100 = if \ 'd' + over ydepth +! + then dup 117 = if \ 'u' + over negate ydepth +! + then + 2drop loop + xpos @ ydepth @ . +; + +: solveb + 10 +; + +: boot + s" input02.txt" filename + solvea . cr \ TODO double math?? + bye ; +save 02.rom \ Replace with soln number +bye