Skip to content

Commit 8a8cb90

Browse files
committed
[euler] add docs for solution to problem 151
1 parent 9702a33 commit 8a8cb90

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

categories/euler/prob151-shlomif.p6

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
use v6;
22

3+
=begin pod
4+
5+
=TITLE Paper sheets of standard sizes: an expected-value problem
6+
7+
=AUTHOR Shlomi Fish
8+
9+
L<https://projecteuler.net/problem=151>
10+
11+
A printing shop runs 16 batches (jobs) every week and each batch requires a
12+
sheet of special colour-proofing paper of size A5.
13+
14+
Every Monday morning, the foreman opens a new envelope, containing a large
15+
sheet of the special paper with size A1.
16+
17+
He proceeds to cut it in half, thus getting two sheets of size A2. Then he
18+
cuts one of them in half to get two sheets of size A3 and so on until he
19+
obtains the A5-size sheet needed for the first batch of the week.
20+
21+
All the unused sheets are placed back in the envelope.
22+
23+
At the beginning of each subsequent batch, he takes from the envelope one
24+
sheet of paper at random. If it is of size A5, he uses it. If it is larger,
25+
he repeats the 'cut-in-half' procedure until he has what he needs and any
26+
remaining sheets are always placed back in the envelope.
27+
28+
Excluding the first and last batch of the week, find the expected number of
29+
times (during each week) that the foreman finds a single sheet of paper in
30+
the envelope.
31+
32+
Give your answer rounded to six decimal places using the format x.xxxxxx.
33+
34+
Expected result: 0.464398
35+
36+
=end pod
37+
338
my $sum = 0;
439

540
# rec is short for "recurse".
@@ -36,3 +71,5 @@ sub rec($n, $d, @counts, $result)
3671
rec(1, 1, [1],0);
3772

3873
say "Result == ", ($sum - 2).fmt("%.6f");
74+
75+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)