%!PS % begin included library code % see https://github.com/Firedrake/postscript-libraries/ /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 /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 /deepeq { 2 dict begin /a exch def /b exch def a type b type eq { a type /dicttype eq { a length b length eq { << a { pop true } forall b { pop true } forall >> true exch { pop dup a exch known { dup b exch known { dup a exch get exch b exch get deepeq not { pop false } if } { false } ifelse } { false } ifelse } forall } { false } ifelse } { a type dup /arraytype eq exch /stringtype eq or { a length b length eq { true 0 1 a length 1 sub { dup a exch get exch b exch get deepeq not { pop false exit } if } for } { false } ifelse } { a b eq } ifelse } ifelse } { false } ifelse end } bind def /apush.right { % [a b] c -> [a b c] exch [ exch aload length 2 add -1 roll ] } bind def % end included library code /widestvalley { 11 dict begin /a exch def /av 0 array def /ac 0 array def /l -1 def a { /v exch def v l eq { ac dup dup length 1 sub dup 3 1 roll get 1 add put } { /av av v apush.right def /ac ac 1 apush.right def /l v def } ifelse } forall /s 0 array def /e 0 array def /c 0 def 0 1 av length 1 sub { /i exch def /peak false def i 0 eq i av length 1 sub eq or { /peak true def } if peak not { av i 1 sub get av i get lt av i get av i 1 add get gt and { /peak true def } if } if peak { /s s c apush.right def /e e c ac i get add 1 sub apush.right def } if /c c ac i get add def } for /out 0 array def 0 1 s length 2 sub { /i exch def /v s i get def e i 1 add get s i get sub 1 add out length gt { /out a s i get dup e i 1 add get exch sub 1 add getinterval def } if } for out end } bind def (widestvalley) test.start [1 5 5 2 8] widestvalley [5 5 2 8] deepeq test [2 6 8 5] widestvalley [2 6 8] deepeq test [9 8 13 13 2 2 15 17] widestvalley [13 13 2 2 15 17] deepeq test [2 1 2 1 3] widestvalley [2 1 2] deepeq test [1 3 3 2 1 2 3 3 2] widestvalley [3 3 2 1 2 3 3] deepeq test test.end