aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/roger-bell-west/postscript/ch-1.ps
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2024-09-03 10:54:51 +0100
committerRoger Bell_West <roger@firedrake.org>2024-09-03 10:54:51 +0100
commitcc96d8b038a42f7a0699c43292c32a1e05e66711 (patch)
treef31a55d582e6954dd2af1450db7b4c687cf694b6 /challenge-285/roger-bell-west/postscript/ch-1.ps
parentd580b9b447884482e4d873cd5547bdfb32b52379 (diff)
downloadperlweeklychallenge-club-cc96d8b038a42f7a0699c43292c32a1e05e66711.tar.gz
perlweeklychallenge-club-cc96d8b038a42f7a0699c43292c32a1e05e66711.tar.bz2
perlweeklychallenge-club-cc96d8b038a42f7a0699c43292c32a1e05e66711.zip
RogerBW solutions for challenge no. 285
Diffstat (limited to 'challenge-285/roger-bell-west/postscript/ch-1.ps')
-rw-r--r--challenge-285/roger-bell-west/postscript/ch-1.ps93
1 files changed, 93 insertions, 0 deletions
diff --git a/challenge-285/roger-bell-west/postscript/ch-1.ps b/challenge-285/roger-bell-west/postscript/ch-1.ps
new file mode 100644
index 0000000000..f548e6b3ca
--- /dev/null
+++ b/challenge-285/roger-bell-west/postscript/ch-1.ps
@@ -0,0 +1,93 @@
+%!PS
+
+% begin included library code
+% see https://codeberg.org/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
+
+/set.difference {
+ 4 dict begin
+ /s 0 dict def
+ /b exch def
+ /a exch def
+ a keys {
+ /k exch def
+ b k known not {
+ s k true put
+ } if
+ } forall
+ s
+ end
+} bind def
+
+/keys { % dict -> array of dict keys
+ [ exch
+ {
+ pop
+ } forall
+ ]
+} bind def
+
+/map { % array proc -> array
+ 2 dict begin
+ /p exch def
+ [ exch
+ {
+ p
+ } forall
+ ]
+ 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
+
+/toset { % array -> dict of (value, true)
+ << exch
+ {
+ true
+ } forall
+ >>
+} bind def
+
+/test.start {
+ print (:) print
+ /test.pass 0 def
+ /test.count 0 def
+} bind def
+
+
+% end included library code
+
+/noconnection {
+ 0 dict begin
+ /a exch def
+ /os a { 0 get } map toset def
+ /is a { 1 get } map toset def
+ is os set.difference keys 0 get
+ end
+} bind def
+
+(noconnection) test.start
+[[(B) (C)] [(D) (B)] [(C) (A)]] noconnection (A) eq test
+[[(A) (Z)]] noconnection (Z) eq test
+test.end