diff options
| -rwxr-xr-x | challenge-016/jo-37/perl/ch-1.pl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-016/jo-37/perl/ch-1.pl b/challenge-016/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..93fcc919d1 --- /dev/null +++ b/challenge-016/jo-37/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use v5.16; +use warnings; +use List::Gen; +use List::UtilsBy 'max_by'; + +# Build a generator for 100 pie pieces. +my $parts = do { + my $pie = 1; + <1..100>->map(sub { + my $part = $pie * $_ / 100; + $pie -= $part; + $part; + } + ); +}->cache; + +# Find the 1-based index of the maximum. +say scalar max_by {$parts->($_ - 1)} 1 .. 100; |
