Skip to content

Instantly share code, notes, and snippets.

@TimToady
Created March 7, 2014 16:59
Show Gist options
  • Save TimToady/9415288 to your computer and use it in GitHub Desktop.
Save TimToady/9415288 to your computer and use it in GitHub Desktop.
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