aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-08-11 20:24:43 +0100
committerGitHub <noreply@github.com>2021-08-11 20:24:43 +0100
commit9bd4fc4109716dec07c695e10b7205bda2caf2eb (patch)
tree38ef86e8d2115ffcb2993f99a849447170739588
parentca43541e7e6fc67e031f9ca1cf50e8b4fb75c568 (diff)
parent62886f842bcb91f8367217da8b9662cefbd3088f (diff)
downloadperlweeklychallenge-club-9bd4fc4109716dec07c695e10b7205bda2caf2eb.tar.gz
perlweeklychallenge-club-9bd4fc4109716dec07c695e10b7205bda2caf2eb.tar.bz2
perlweeklychallenge-club-9bd4fc4109716dec07c695e10b7205bda2caf2eb.zip
Merge pull request #4689 from Firedrake/rogerbw-challenge-125-postscript
Addendum, PostScript answer to 125 part 2
-rw-r--r--challenge-125/roger-bell-west/postscript/ch-2.ps49
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-125/roger-bell-west/postscript/ch-2.ps b/challenge-125/roger-bell-west/postscript/ch-2.ps
new file mode 100644
index 0000000000..175b9e02ef
--- /dev/null
+++ b/challenge-125/roger-bell-west/postscript/ch-2.ps
@@ -0,0 +1,49 @@
+%! no DSC
+
+/max2 {
+ dup % a b b
+ 3 2 roll % b b a
+ dup % b b a a
+ 3 1 roll % b a b a
+ lt { exch} if
+ pop
+} def
+
+/btd {
+ /tree exch def
+ /st tree length def
+ /depth st array def
+ /diameter st array def
+ 0 1 st 1 sub {
+ dup
+ depth exch 0 put
+ diameter exch 0 put
+ } for
+ st 1 sub 1 neg 0 {
+ /i exch def
+ tree i get 0 ne {
+ /a i 2 mul 1 add def
+ /b a 1 add def
+ b st lt {
+ depth i depth a get depth b get max2 1 add put
+ diameter i
+ depth a get depth b get 1 add add
+ diameter a get
+ diameter b get
+ max2 max2 put
+ } {
+ depth i 1 put
+ diameter i 1 put
+ } ifelse
+ } if
+ } for
+ diameter 0 get
+} def
+
+[ 1
+ 2 5
+ 3 4 6 7
+ 0 0 0 0 0 0 8 10
+ 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 ]
+btd
+=