SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl6
  2. use v6;
  3.  
  4. use Test;
  5.  
  6. # 16.1
  7. # Pythagoras Pie Puzzle, proposed by Jo Christian Oterhals.
  8. #
  9. # 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.
  10. #
  11. # Write a script that figures out which guest gets the largest piece of pie.
  12.  
  13.  
  14. #| Figures which guests is the happy party pie guest.
  15. multi sub MAIN($guests=100) {
  16.     my $pie=1.0;
  17.     my $biggestSlice=0;
  18.     my $fattestGuest=Nil;
  19.     for 1..$guests -> $g {
  20.         my $slice=$pie*($g/100);
  21.         $pie-=$slice;
  22.         if $slice>$biggestSlice {
  23.             $fattestGuest=$g;
  24.             $biggestSlice=$slice;
  25.         }
  26.         say "guest {$g} gets $slice of the pie";
  27.     }
  28.     say "guest {$fattestGuest} gets the largest slice $biggestSlice";
  29.    
  30. };
  31.  
  32. multi sub MAIN("test") {
  33.  
  34.     done-testing;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top