Skip to content

Instantly share code, notes, and snippets.

@VienosNotes
Created October 1, 2012 22:33
Show Gist options
  • Select an option

  • Save VienosNotes/3814873 to your computer and use it in GitHub Desktop.

Select an option

Save VienosNotes/3814873 to your computer and use it in GitHub Desktop.
10進数から任意のN進数への変換 with Perl6
use v6;
sub MAIN ($n! is copy, $radix = "2**31") {
my $num_radix = eval $radix.Str;
my $num_n = eval $n.Str;
CATCH {
die "something is wrong!";
}
my @ans;
while ($num_n != 0) {
@ans.push: $num_n % $num_radix;
$num_n = ($num_n / $num_radix).Int;
}
say (eval $n.Str) ~ " -> $radix based";
say "[", @ans.join("; "), "]";
}
@VienosNotes

Copy link
Copy Markdown
Author

宣言型プログラム論ミニプロジェクトの検算用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment