Skip to content

Commit 9640e56

Browse files
committed
Add solution to Euler #601.
Based on: https://github.com/shlomif/project-euler/blob/master/project-euler/601/euler_601_v1.py It emits identical output to it, but it is much slower than when the original code is ran by cpython2, cpython3 or especially pypy2.
1 parent 13312f1 commit 9640e56

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

categories/euler/prob601-shlomif.p6

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use v6;
2+
3+
=begin pod
4+
5+
=TITLE Divisibility streaks
6+
7+
=AUTHOR Shlomi Fish
8+
9+
L<http://projecteuler.net/problem=601>
10+
11+
12+
=head2 Usage
13+
14+
=end pod
15+
16+
sub calc_P($s, $N)
17+
{
18+
my $l = [lcm] 1 .. $s;
19+
my $i = $l;
20+
my $ret = 0;
21+
my $t = $s + 1;
22+
my $M = $N - 1;
23+
while $i < $M
24+
{
25+
if $i % $t
26+
{
27+
++$ret;
28+
}
29+
$i += $l;
30+
}
31+
return $ret;
32+
}
33+
34+
sub print_P($s, $N)
35+
{
36+
my $ret = calc_P($s, $N);
37+
say "calc_P(s=$s, N=$N) = $ret";
38+
return $ret;
39+
}
40+
41+
sub MAIN(Bool :$verbose = False)
42+
{
43+
print_P(3, 14);
44+
print_P(6, 10**6);
45+
print_P(2, 4**2);
46+
my $mysum = 0;
47+
my $p = 4;
48+
for 1 .. 31 -> $i
49+
{
50+
$mysum += print_P($i, $p);
51+
say "mysum($i) = $mysum";
52+
$p *= 4;
53+
}
54+
}
55+
56+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)