aoc-forth

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

commit 65a54fb997f77a720978ee94729638331666e0db
parent 63f805734724d48e5b1c48f15406e6c715cddc07
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun,  4 Dec 2022 01:55:08 -0800

cleanup day 4

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

diff --git a/2022/04.fs b/2022/04.fs @@ -10,12 +10,8 @@ dup not-num if unloop drop drop exit then rot 10 * + swap loop drop ; -: includes ( u1 u2 u3 u4 -- f ) rot <= -rot <= and ; +: 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 ; -: either-overlaps ( u1 u2 u3 u4 -- f ) - 4dup overlaps >r 2swap overlaps r> and ; -: either-includes ( u1 u2 u3 u4 -- f ) - 4dup includes >r 2swap includes r> or ; : read-str pad 12 erase pad pad 12 accept ; : read-pairs ( -- u1 u2 u3 u4 ) @@ -30,10 +26,8 @@ to-num variable total1 variable total2 : solve - 1000 0 do read-pairs 4dup - either-includes if 1 total1 +! then - overlaps if 1 total2 +! then - loop - total1 ? cr total2 ? bye -; + 1000 0 do read-pairs 4dup + includes if 1 total1 +! then + overlaps if 1 total2 +! then loop + total1 ? cr total2 ? bye ; solve