04.fs (679B) - raw
1 : 4dup 3 pick 3 pick 3 pick 3 pick ; 2 : not-num ( u -- f ) dup 0 < swap 9 > or ; 3 : c>num ( c -- u ) 48 - ; 4 : next-num ( a1 -- u a2 ) 5 0 swap 1- begin 1+ dup c@ 6 c>num dup not-num if drop 1+ exit then 7 rot 10 * + swap again ; 8 : includes ( u1 u2 u3 u4 -- f ) 4dup rot <= -rot <= and >r rot >= -rot >= and r> or ; 9 : overlaps ( u1 u2 u3 u4 -- f ) -rot >= -rot <= and ; 10 : read-str pad 12 erase pad 12 accept drop ; 11 : read-pairs ( -- u1 u2 u3 u4 ) read-str pad next-num next-num next-num next-num drop ; 12 13 variable total1 14 variable total2 15 : solve 16 1000 0 do read-pairs 4dup 17 includes if 1 total1 +! then 18 overlaps if 1 total2 +! then loop 19 total1 ? cr total2 ? bye ; 20 solve