commit 6cb5d671bfaa2e46a955532d349b8bb5f2604fc9
parent 7c838655156d264576068f5f4a97e3fd1b777bbf
Author: alex wennerberg <alex@alexwennerberg.com>
Date: Sun, 4 Dec 2022 00:30:04 -0800
cleanup day 4
Diffstat:
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/2022/04.fs b/2022/04.fs
@@ -1,6 +1,3 @@
-\ a b -- a includes b
-\ end is greater than end and start is less than start
-\ end is less than start OR start is less than end
45 constant dash
44 constant comma
@@ -19,10 +16,11 @@
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 )
read-str
-\ uggo
+\ 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
@@ -32,14 +30,10 @@ to-num
variable total1
variable total2
: solve
- 1000 0 do
- read-pairs
- 4dup
+ 1000 0 do read-pairs 4dup
either-includes if 1 total1 +! then
.s overlaps .s cr if 1 total2 +! then
loop
- total1 ? cr \ part 1
- total2 ? \ part 1
- bye
+ total1 ? cr total2 ? bye
;
solve