diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-07-11 12:14:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-11 12:14:27 +0100 |
| commit | d7298ad5817a4306f5df759dc67216a6e16d1246 (patch) | |
| tree | 569d1f07d23b94c378cedd779b1530ce25171758 | |
| parent | a2bda546363c042ff537819ed534d55169abdedd (diff) | |
| parent | 1057eb25561662d5f68d7f5ce5b4d759c589cbdf (diff) | |
| download | perlweeklychallenge-club-d7298ad5817a4306f5df759dc67216a6e16d1246.tar.gz perlweeklychallenge-club-d7298ad5817a4306f5df759dc67216a6e16d1246.tar.bz2 perlweeklychallenge-club-d7298ad5817a4306f5df759dc67216a6e16d1246.zip | |
Merge pull request #360 from andrezgz/challenge-016
challenge-016 andrezgz solution ch-1
| -rw-r--r-- | challenge-016/andrezgz/perl5/ch-1.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-016/andrezgz/perl5/ch-1.pl b/challenge-016/andrezgz/perl5/ch-1.pl new file mode 100644 index 0000000000..24dcfe5559 --- /dev/null +++ b/challenge-016/andrezgz/perl5/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-016/ +# Challenge #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; + +my $pie = 100; +my %max; + +for my $g (1..100) { + my $slice = $g * $pie / 100; + last if ($max{slice} && $max{slice} > $slice); + %max = (guest => $g, slice => $slice); + $pie -= $slice; +} + +print sprintf("Guest %d gets the largest piece of the pie (%.2f%% of it)",$max{guest},$max{slice})."\n"; |
