diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-07-15 11:03:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-15 11:03:06 +0100 |
| commit | 8c4f9a2a3d2ff1d7d3bd764a6b9767e61f0b6d31 (patch) | |
| tree | 5f2334995f37ffb4e9e94c8fc5bfcd4cd4371e5e /challenge-016 | |
| parent | 3e21c6370fb0e5d3cb522fba714489e515ed1746 (diff) | |
| parent | 4e5b1eefe38954201ef70b6322b76b872fe7ce82 (diff) | |
| download | perlweeklychallenge-club-8c4f9a2a3d2ff1d7d3bd764a6b9767e61f0b6d31.tar.gz perlweeklychallenge-club-8c4f9a2a3d2ff1d7d3bd764a6b9767e61f0b6d31.tar.bz2 perlweeklychallenge-club-8c4f9a2a3d2ff1d7d3bd764a6b9767e61f0b6d31.zip | |
Merge pull request #359 from gnustavo/016
Gustavo Chaves solution to challenge 016
Diffstat (limited to 'challenge-016')
| -rwxr-xr-x | challenge-016/gustavo-chaves/perl5/ch-1.pl | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-016/gustavo-chaves/perl5/ch-1.pl b/challenge-016/gustavo-chaves/perl5/ch-1.pl new file mode 100755 index 0000000000..02df6f8946 --- /dev/null +++ b/challenge-016/gustavo-chaves/perl5/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +# 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 5.026; +use strict; +use warnings; +use bignum; + +my $pie = 100/100; + +my $largest_slice = 0; + +my $guest = 0; + +for my $i (1 .. 100) { + my $slice = $pie * $i / 100; + $pie -= $slice; + if ($slice > $largest_slice) { + $largest_slice = $slice; + $guest = $i; + } + # say "The ${i}º guest got $slice of the total."; + last if $pie < $largest_slice; +} + +say "The ${guest}º guest got the larget pie, which is $largest_slice of the total."; |
