%!PS % begin included library code % see https://github.com/Firedrake/postscript-libraries/ /quicksort { % [ a c b ] -> [ a b c ] 1 dict begin /arr exch def 0 arr length 1 sub quicksort.main arr end } bind def /quicksort.partition { 3 dict begin /pivot arr hi lo add 2 idiv get def /i lo 1 sub def /j hi 1 add def { { /i i 1 add def arr i get pivot ge { exit } if } loop { /j j 1 sub def arr j get pivot le { exit } if } loop i j ge { j exit } if i j quicksort.swap } loop end } bind def /quicksort.main { % lo hi -> (null) 3 dict begin /hi exch def /lo exch def /xit false def lo 0 lt { /xit true def } if hi 0 lt { /xit true def } if lo hi ge { /xit true def } if xit not { /p quicksort.partition def lo p quicksort.main p 1 add hi quicksort.main } if end } bind def /quicksort.swap { 2 dict begin /bi exch def /ai exch def arr ai get arr bi get arr exch ai exch put arr exch bi exch put end } bind def /test.end { ( ) print test.count 0 gt { (Passed ) print test.pass (...) cvs print (/) print test.count (...) cvs print ( \() print test.pass 100 mul test.count idiv (...) cvs print (%\)) print (\r\n) print } if } bind def /ymd2jd { 4 dict begin aload pop /d exch def /m exch def /y exch def /mn m 14 sub 12 idiv def y 4800 add mn add 1461 mul 4 idiv mn 12 mul neg 2 sub m add 367 mul 12 idiv add y 4900 add mn add 100 idiv 3 mul 4 idiv sub d add 32075 sub end } bind def /test.start { print (:) print /test.pass 0 def /test.count 0 def } bind def /test { /test.count test.count 1 add def { /test.pass test.pass 1 add def } { ( ) print test.count (....) cvs print (-fail) print } ifelse } bind def % end included library code /daystogether { 2 dict begin /starts 2 array def /ends 2 array def dup 0 get s2jd starts exch 1 exch put 1 get s2jd ends exch 1 exch put dup 0 get s2jd starts exch 0 exch put 1 get s2jd ends exch 0 exch put starts quicksort ends quicksort ends 0 get starts 1 get ge { ends 0 get starts 1 get sub 1 add } { 0 } ifelse end } bind def /s2jd { [ exch 2022 exch dup 3 2 getinterval cvi exch 0 2 getinterval cvi ] ymd2jd } bind def (daystogether) test.start [ (12-01) (20-01) ] [ (15-01) (18-01) ] daystogether 4 eq test [ (02-03) (12-03) ] [ (13-03) (14-03) ] daystogether 0 eq test [ (02-03) (12-03) ] [ (11-03) (15-03) ] daystogether 2 eq test [ (30-03) (05-04) ] [ (28-03) (02-04) ] daystogether 4 eq test test.end