diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-07-10 12:23:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-10 12:23:52 +0100 |
| commit | 3c61a8f0ab38c07936147c4d95f8fdb604b18a2f (patch) | |
| tree | 9ac9474f9e32d555de9ef12593eb1217a075aa47 | |
| parent | 5fb6fa5ed8f7dbef7192ff76fb0dd70cb89b09d7 (diff) | |
| parent | 205aaa3aebf3492bb4521fedf243b6aaff488809 (diff) | |
| download | perlweeklychallenge-club-3c61a8f0ab38c07936147c4d95f8fdb604b18a2f.tar.gz perlweeklychallenge-club-3c61a8f0ab38c07936147c4d95f8fdb604b18a2f.tar.bz2 perlweeklychallenge-club-3c61a8f0ab38c07936147c4d95f8fdb604b18a2f.zip | |
Merge pull request #358 from oWnOIzRi/week016
add solution to task 1
| -rw-r--r-- | challenge-016/steven-wilson/perl5/ch-1.pl | 35 |
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."; |
