aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <39702500+threadless-screw@users.noreply.github.com>2019-07-09 06:48:23 +0000
committerGitHub <noreply@github.com>2019-07-09 06:48:23 +0000
commit07fd19d2dd5b19dd54693b6b15a7abd6c2ea3263 (patch)
tree6deff60db45b5149327180429980216664127fb4
parentea3a62e5bb2fe9dbacd3cd0d990fcf1f070ed517 (diff)
downloadperlweeklychallenge-club-07fd19d2dd5b19dd54693b6b15a7abd6c2ea3263.tar.gz
perlweeklychallenge-club-07fd19d2dd5b19dd54693b6b15a7abd6c2ea3263.tar.bz2
perlweeklychallenge-club-07fd19d2dd5b19dd54693b6b15a7abd6c2ea3263.zip
Create ch-1.p6
-rw-r--r--challenge-016/ozzy/perl6/ch-1.p614
1 files changed, 14 insertions, 0 deletions
diff --git a/challenge-016/ozzy/perl6/ch-1.p6 b/challenge-016/ozzy/perl6/ch-1.p6
new file mode 100644
index 0000000000..047406455c
--- /dev/null
+++ b/challenge-016/ozzy/perl6/ch-1.p6
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl6
+# Pythagoras pie puzzle
+
+sub s ($j) { $j > 0 ?? r($j-1)*($j / 100) !! 0 }; # Mutually recursive share and remainder functions;
+sub r ($k) { $k > 0 ?? r($k-1) - s($k) !! 100 }; # $j and $k represent guest numbers
+
+my @as = 0, { state $j=0; s(++$j) } ... *; # Memory for calculated values, just to speed
+my @ar = 0, { state $k=0; s(++$k) } ... *; #+ things up
+
+my $i=1; # Guest number
+my $m=0; # Guest number associated with biggest share
+
+until @ar[$i-1] < @as[$m] { if @as[$i] > @as[$m] { $m=$i }; $i++ };
+printf "Guest $m takes the biggest piece: %.2f%% of the cake.\n", s($m);