aoc-forth

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

commit 0700ab22c61bfbb306365d694f2a07e1450c1ee5
parent 65a54fb997f77a720978ee94729638331666e0db
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun,  4 Dec 2022 02:19:35 -0800

cleanup input

Diffstat:
M2022/04.fs | 22++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/2022/04.fs b/2022/04.fs @@ -3,25 +3,15 @@ : 4dup 3 pick 3 pick 3 pick 3 pick ; : not-num ( u -- f ) dup 0 < swap 9 > or ; - -\ reads until nonnumeric char -: to-num ( a u -- n ) - 0 -rot 0 do dup r@ + c@ h# 30 - - dup not-num if unloop drop drop exit then - rot 10 * + swap loop drop ; - +: c>num ( c -- u ) 48 - ; +: next-num ( a1 -- u a2 ) + 0 swap 1- begin 1+ dup c@ + c>num dup not-num if drop 1+ exit then + rot 10 * + swap again ; : includes ( u1 u2 u3 u4 -- f ) 4dup rot <= -rot <= and >r rot >= -rot >= and r> or ; : overlaps ( u1 u2 u3 u4 -- f ) -rot >= -rot <= and ; - : read-str pad 12 erase pad pad 12 accept ; -: read-pairs ( -- u1 u2 u3 u4 ) -read-str -\ ugly -2dup to-num -rot dash scan swap 1+ swap -2dup to-num -rot comma scan swap 1+ swap -2dup to-num -rot dash scan swap 1+ swap -to-num -; +: read-pairs ( -- u1 u2 u3 u4 ) read-str drop next-num next-num next-num next-num drop ; variable total1 variable total2