Perl Weekly Challenge #016
Task #1: Pythagoras Pie Puzzle
This puzzle’s connection with Pythagoras is tenuous indeed: it originally appeared in the Dutch magazine Pythagoras (see here and here)! But the puzzle is interesting. Of course, the real challenge is to work out the answer mathematically, but for those of us who are mathematically declined a Perl script is the way to go.
The first draft of my solution was tied to the 100 guests specified in the puzzle statement, but it’s easy to extend the puzzle to allow any (positive integer) number of guests. So I include the number of guests as a constant $GUESTS and the central calculation becomes:
$piece = ($guest / $GUESTS) * $pie;
where $guest is any number in the series 1 .. $GUESTS and $pie is the fraction of original pie remaining at this point in the distribution.
Perl 5 solution
For my own interest I added code to display the size of each guest’s piece of pie. This code can be omitted from compilation by setting DEBUG to a false value.

