Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Euler] Add my solution to Euler #188.
  • Loading branch information
shlomif committed Jan 11, 2014
1 parent 79b721d commit 25efd58
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions euler/prob188-shlomif.pl
@@ -0,0 +1,30 @@
use v6;

# Solve Project Euler’s Problem No. 188:
# http://projecteuler.net/problem=188
# “The Hyperexponentiation of a number.”

sub hyperexp_modulo(int $base, int $exp, int $mod) returns int
{
if $exp == 1
{
return ($base % $mod);
}

my Int $mod1 = $base;
my Int $e = 1;

while $mod1 != 1
{
($mod1 *= $base) %= $mod;
$e++;
}

my int $mod_recurse = hyperexp_modulo($base, $exp - 1, $e);

return $base.expmod($mod_recurse, $mod);
}

# print hyperexp_modulo(3, 3, 1000), "\n";

printf "Result == %08d\n", hyperexp_modulo(1777, 1855, 100_000_000);

0 comments on commit 25efd58

Please sign in to comment.