aoc-forth

Advent of code solutions in UF forth
git clone git://git.alexwennerberg.com/aoc-forth
Log | Files | Refs | README

commit 11134aa4de8a6433811789e805ced603bb9cee2f
parent d02e98c662fead6f9c983f5744c77859017dd9ec
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 30 Nov 2022 23:34:17 -0800

failed day 1.......... python fallback

Diffstat:
A2022/01.py | 20++++++++++++++++++++
A2022/01a.fs | 35+++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/2022/01.py b/2022/01.py @@ -0,0 +1,20 @@ +import sys + +cur = 0 +top = 0 +second = 0 +third = 0 + +alllines = [] + +for line in sys.stdin: + if line == "\n": + alllines.append(cur) + cur = 0 + else: + cur += int(line[:-1]) + +alllines.sort() +alllines.reverse() + +print(alllines[0] + alllines[1] + alllines[2]) diff --git a/2022/01a.fs b/2022/01a.fs @@ -0,0 +1,35 @@ +\ failure + +include ../utils/dmath.f + +variable cals +variable top +variable second +variable third + +\ hell +: push-var +cals 2@ +2dup 2dup 2dup +top 2@ swap d< if +second 2@ third 2! top 2@ second 2! 2dup top 2! +then 2drop 2drop 2drop exit +second 2@ swap d< if +second 2@ third 2! 2dup second 2! +then 2drop 2drop exit +third 2@ swap d< if +2dup third 2! +then 2drop exit +; + +: to-num ( a u -- n ) 0 -rot 0 do dup r@ + c@ h# 30 - rot 10 * + swap loop drop ; +: read-line ( -- a n ) pad pad 10 accept ; +: add-calories to-num 0 cals 2@ d+ cals 2! ; +: group-done? ( -- f ) dup 0= if push-var +top 2@ second 2@ third 2@ d. d. d. cr +1 exit then 0 ; +: solve + 2250 0 do read-line group-done? if read-line then add-calories + loop +; +solve