diff options
Diffstat (limited to 'challenge-330/roger-bell-west/postscript/ch-2.ps')
| -rw-r--r-- | challenge-330/roger-bell-west/postscript/ch-2.ps | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/challenge-330/roger-bell-west/postscript/ch-2.ps b/challenge-330/roger-bell-west/postscript/ch-2.ps new file mode 100644 index 0000000000..ad8a3b895f --- /dev/null +++ b/challenge-330/roger-bell-west/postscript/ch-2.ps @@ -0,0 +1,145 @@ +%!PS + +% begin included library code +% see https://codeberg.org/Firedrake/postscript-libraries/ +/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.start { + print (:) print + /test.pass 0 def + /test.count 0 def +} bind def + +/strconcat % (a) (b) -> (ab) +{ + [ + 3 -1 roll + s2a aload length + 2 add -1 roll + s2a aload pop + ] a2s +} bind def + +/tolower { + s2a + [ exch + { + dup dup 65 ge exch 90 le and { + 32 add + } if + } forall + ] a2s +} bind def + +/strsplit % (ajbjc) (j) -> [ (a) (b) (c) ] +{ + 1 dict begin + /sep exch def + [ exch + { + dup length 0 eq { + pop + exit + } { + sep search { + exch pop + dup length 0 eq { + pop + } { + exch + } ifelse + } { + () + } ifelse + } ifelse + } loop + ] + 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 + +/s2a { + [ exch { } forall ] +} 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 + +/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 + +/titlecapital { + 0 dict begin + [ exch + ( ) strsplit + { + tolower + dup length 2 gt { + s2a /c exch def + c 0 c 0 get 223 and put + c a2s + } if + } forall + ] ( ) strjoin + end +} bind def + +(titlecapital) test.start +(PERL IS gREAT) titlecapital (Perl is Great) eq test +(THE weekly challenge) titlecapital (The Weekly Challenge) eq test +(YoU ARE A stAR) titlecapital (You Are a Star) eq test +test.end |
