Skip to content

Commit cfc205a

Browse files
committed
Add verbose cmd line option to problem 288
This reduces the amount of output to check in the tests.
1 parent 664b498 commit cfc205a

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

categories/euler/prob288-shlomif.p6

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,37 @@ sub factorial_factor_exp($n , $f)
3737
}
3838
}
3939

40-
my @t_n;
40+
sub MAIN(:$verbose = False) {
41+
my @t_n;
4142

42-
my $N_LIM = 10;
43-
my $BASE = 61;
44-
my $LIM = 10_000_000;
43+
my $N_LIM = 10;
44+
my $BASE = 61;
45+
my $LIM = 10_000_000;
4546

46-
my $S_0 = 290797;
47-
my $s = $S_0;
47+
my $S_0 = 290797;
48+
my $s = $S_0;
4849

49-
for (0 .. $N_LIM-1) -> $n {
50-
@t_n.push($s % $BASE);
51-
$s = (($s * $s) % 50515093);
52-
}
50+
for (0 .. $N_LIM-1) -> $n {
51+
@t_n.push($s % $BASE);
52+
$s = (($s * $s) % 50515093);
53+
}
5354

54-
my $sum = 0;
55-
for ($N_LIM .. $LIM) -> $n {
56-
if $n % 10_000 == 0 {
57-
say "Reached $n";
55+
my $sum = 0;
56+
for ($N_LIM .. $LIM) -> $n {
57+
if $n % 10_000 == 0 {
58+
say "Reached $n" if $verbose;
59+
}
60+
$sum += ($s % $BASE);
61+
$s = (($s * $s) % 50515093);
5862
}
59-
$sum += ($s % $BASE);
60-
$s = (($s * $s) % 50515093);
61-
}
6263

63-
sub f($n)
64-
{
65-
return factorial_factor_exp($n, ($BASE)) % (($BASE) ** $N_LIM);
66-
}
64+
sub f($n)
65+
{
66+
return factorial_factor_exp($n, ($BASE)) % (($BASE) ** $N_LIM);
67+
}
6768

68-
say "Solution == ", +([+] (
69-
(map { f(($BASE) ** $_) * @t_n[$_] }, 1 .. @t_n-1),
70-
$sum * f(($BASE) ** $N_LIM)
71-
)) % (($BASE) ** $N_LIM);
69+
say "Solution == ", +([+] (
70+
(map { f(($BASE) ** $_) * @t_n[$_] }, 1 .. @t_n-1),
71+
$sum * f(($BASE) ** $N_LIM)
72+
)) % (($BASE) ** $N_LIM);
73+
}

0 commit comments

Comments
 (0)