Forked from dogbert17/gist:f663fabba14ffe6fda2fc33182b78c46
Last active
August 13, 2018 16:21
-
-
Save AlexDaniel/227c34f20d638d0b339947c744d05bc8 to your computer and use it in GitHub Desktop.
Perf regression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
my Int @cache is default(0); | |
my $sum89 = 0; | |
for (1..567) -> $i { | |
@cache[$i] = calc-chain($i); | |
} | |
for (1..400_000) -> $i { | |
$sum89++ if @cache[get-sq-sum($i)] == 89; | |
} | |
#say $sum89; | |
my $x = now - INIT now; | |
say $x; | |
#exit 42 if $x > 3.4; | |
sub calc-chain($n) { | |
my $sq-sum = get-sq-sum($n); | |
$sq-sum != 1|89 ?? calc-chain($sq-sum) !! $sq-sum; | |
} | |
sub get-sq-sum(int $i is copy) { | |
my $sum = 0; | |
while $i > 0 { | |
$sum += ($i % 10) ** 2; | |
$i = $i div 10; | |
} | |
$sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment