Skip to content

Commit 25efd58

Browse files
committed
[Euler] Add my solution to Euler #188.
1 parent 79b721d commit 25efd58

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

euler/prob188-shlomif.pl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use v6;
2+
3+
# Solve Project Euler’s Problem No. 188:
4+
# http://projecteuler.net/problem=188
5+
# “The Hyperexponentiation of a number.”
6+
7+
sub hyperexp_modulo(int $base, int $exp, int $mod) returns int
8+
{
9+
if $exp == 1
10+
{
11+
return ($base % $mod);
12+
}
13+
14+
my Int $mod1 = $base;
15+
my Int $e = 1;
16+
17+
while $mod1 != 1
18+
{
19+
($mod1 *= $base) %= $mod;
20+
$e++;
21+
}
22+
23+
my int $mod_recurse = hyperexp_modulo($base, $exp - 1, $e);
24+
25+
return $base.expmod($mod_recurse, $mod);
26+
}
27+
28+
# print hyperexp_modulo(3, 3, 1000), "\n";
29+
30+
printf "Result == %08d\n", hyperexp_modulo(1777, 1855, 100_000_000);

0 commit comments

Comments
 (0)