Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #15 from shlomif/master
Euler: remove trailing space, fix grammar+spelling and add #188 .
  • Loading branch information
timo committed Jan 11, 2014
2 parents 878d9f1 + 25efd58 commit 9c30576
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions euler/README
Expand Up @@ -2,8 +2,8 @@ Project Euler
=============
http://projecteuler.net/

This is a directory to post answers to project euler questions.
This is a directory to post answers to project euler questions.

Use the file format prob000-author.pl replaceing 000 with the problem number and author with your name. For example if I am eric256 and I answer problem one I will save it as prob001-eric256.pl
Use the file format prob000-author.pl, while replacing "000" with the problem number and "author" with your name. For example if I am eric256 and I answer problem No. 1, I will save it as prob001-eric256.pl

Thanks for playing!
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 9c30576

Please sign in to comment.