Skip to content

Instantly share code, notes, and snippets.

@FCO
Last active July 22, 2022 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FCO/333914ae1c63697d3746f190eb5bc9b2 to your computer and use it in GitHub Desktop.
Save FCO/333914ae1c63697d3746f190eb5bc9b2 to your computer and use it in GitHub Desktop.
use Test;
is disarium-numbers(19),
[ 0,1,2,3,4,5,6,7,8,9,89,135,175,518,598,1306,1676,2427,2646798 ];
done-testing;
sub is-disarium-number(Int $n where $n >= 0 --> Bool) {
$n == ^($n.chars)
.map({
$n.substr( $_, 1 ) ** ( $_ + 1 )
})
.sum
}
sub disarium-numbers(Int $n where $n > 0) {
(^Inf).hyper.grep({ .&is-disarium-number }).head: $n
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment