%!PS % begin included library code % see https://codeberg.org/Firedrake/postscript-libraries/ /s2a { [ exch { } forall ] } bind def /strconcat % (a) (b) -> (ab) { [ 3 -1 roll s2a aload length 2 add -1 roll s2a aload pop ] a2s } 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 /a2s { 2 dict begin /i exch def i length dup string /o exch def 1 sub 0 exch 1 exch { dup i 3 -1 roll get o 3 1 roll put } for o end } 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 /enumerate.array { 1 dict begin /a exch def [ 0 1 a length 1 sub { [ exch dup a exch get ] } for ] end } bind def /test.start { print (:) print /test.pass 0 def /test.count 0 def } bind def /strjoin % [(a) (b) (c)] (j) -> (ajbjc) { 3 dict begin /j exch def dup 0 get /out exch def /first true def { first { pop /first false def } { out j strconcat exch strconcat /out exch def } ifelse } forall out end } bind def % end included library code /sortletters { 0 dict begin /c exch def /a exch def /out a length array def a enumerate.array { aload pop /l exch def /i exch def out c i get 1 sub l put } forall out () strjoin end } bind def (sortletters) test.start [(R) (E) (P) (L)] [3 2 1 4] sortletters (PERL) eq test [(A) (U) (R) (K)] [2 4 1 3] sortletters (RAKU) eq test [(O) (H) (Y) (N) (P) (T)] [5 4 2 6 1 3] sortletters (PYTHON) eq test test.end