Created
November 1, 2012 21:08
-
-
Save masak/3996552 to your computer and use it in GitHub Desktop.
All your base (and unbase) are belong to us
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
use v6; | |
sub base(@rad, @a) { [+] ([\*] 1, @rad.reverse) Z* @a.reverse }; | |
sub unbase(@rad, $val is copy) { | |
reverse gather { | |
for @rad.reverse { | |
take $val % $_; | |
last unless ($val /= $_).=Int; | |
} | |
take $val if $val; | |
} | |
} | |
use Test; | |
is base([10, 10, 10, 10], <4 1 2 3>), 4123; | |
is base([0, 3, 12], <3 0 1>), 109; | |
is base([1736, 3, 12], <3 0 1>), 109; | |
is unbase(<10 10 10 10>, 1234), <1 2 3 4>; | |
is unbase(<24 60 60>, 12345), <3 25 45>; | |
is unbase(<24 60 60>, 123456), <1 10 17 36>; | |
is unbase(<24 60 60>, 3), 3; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment