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 34c1027157e7775b5aede370b8f972bb820a9db1
parent 90cde4e604580828f5932525347472e715d2b8b2
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu, 25 Aug 2022 10:31:15 -0400

finishd day 1 part 2

Diffstat:
M2021/01.fs | 26++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/2021/01.fs b/2021/01.fs @@ -1,5 +1,7 @@ h# 5000 constant filespace +: initfile s" input01.txt" filename ; + : readnum 0 ( return val ) begin @@ -13,6 +15,7 @@ h# 5000 constant filespace : solvea + initfile 0 readnum 2000 1 do @@ -22,13 +25,32 @@ h# 5000 constant filespace drop ; +: 3dup 2 pick 2 pick 2 pick ; + + + +variable total +variable last + : solveb -200 + initfile + readnum readnum readnum \ read 3 nums + 2000 3 do + 3dup + + dup \ sum + last @ + swap < 0<> negate total +! + last ! \ store variable + rot drop \ remove oldest value + readnum + loop + total @ ; + : boot s" input01.txt" filename - solvea . solveb . + solvea . cr + solveb . bye ; save 01.rom \ Replace with soln number