Created
October 1, 2012 22:33
-
-
Save VienosNotes/3814873 to your computer and use it in GitHub Desktop.
10進数から任意のN進数への変換 with Perl6
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; | |
| 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("; "), "]"; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
宣言型プログラム論ミニプロジェクトの検算用