Created
March 7, 2014 16:59
-
-
Save TimToady/9415288 to your computer and use it in GitHub Desktop.
This file contains 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
sub digits($n) { | |
my int $i = $n; | |
my int $b = 1000; | |
gather while $i { take $i % $b; $i = $i div $b } | |
} | |
constant narcissistic = map -> $d { | |
my @t = 0..9 X** $d; | |
my @table = @t X+ @t X+ @t; | |
sub is-narcissistic(\n) { n == [+] @table[digits(n)] } | |
gather take $_ if is-narcissistic($_) for 10**($d-1) ..^ 10**$d; | |
}, 1..*; | |
for narcissistic { | |
say ++state $n, "\t", $_; | |
last if $n == 25; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment