aboutsummaryrefslogtreecommitdiff
path: root/challenge-016
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2019-07-08 15:18:56 +0100
committerSteven Wilson <steven1170@zoho.eu>2019-07-08 15:18:56 +0100
commit205aaa3aebf3492bb4521fedf243b6aaff488809 (patch)
treea2f300f89bc5b8499607d22e78047e7e3d2cde91 /challenge-016
parent89dec8844d614d182fe3bb444cad495f3510ed67 (diff)
downloadperlweeklychallenge-club-205aaa3aebf3492bb4521fedf243b6aaff488809.tar.gz
perlweeklychallenge-club-205aaa3aebf3492bb4521fedf243b6aaff488809.tar.bz2
perlweeklychallenge-club-205aaa3aebf3492bb4521fedf243b6aaff488809.zip
add solution to task 1
Diffstat (limited to 'challenge-016')
-rw-r--r--challenge-016/steven-wilson/perl5/ch-1.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-016/steven-wilson/perl5/ch-1.pl b/challenge-016/steven-wilson/perl5/ch-1.pl
new file mode 100644
index 0000000000..56e1e99a46
--- /dev/null
+++ b/challenge-016/steven-wilson/perl5/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+# Author: Steven Wilson
+# Date: 2019-07-08
+# Week: 016
+#
+# Task #1
+# Pythagoras Pie Puzzle, proposed by Jo Christian Oterhals.
+#
+# At a party a pie is to be shared by 100 guest. The first guest gets 1%
+# of the pie, the second guest gets 2% of the remaining pie, the third
+# gets 3% of the remaining pie, the fourth gets 4% and so on.
+#
+# Write a script that figures out which guest gets the largest piece of
+# pie.
+
+use strict;
+use warnings;
+use feature qw/ say /;
+
+my $pie = 360;
+my $current_guest = 1;
+my $guest_with_max_share = 1;
+my @share_of_pie;
+
+while ( $pie != 0 ) {
+ my $current_share = $pie * ( $current_guest / 100 );
+ $pie -= $current_share;
+ $share_of_pie[$current_guest] = $current_share;
+ if ( $share_of_pie[$guest_with_max_share] < $current_share ) {
+ $guest_with_max_share = $current_guest;
+ }
+ $current_guest++;
+}
+
+say "Guest $guest_with_max_share gets the largest piece of the pie.";