Sha256: 5efc579331ba01f1b2b747a36a138f28ec0631e152280ff02a5b1f19b3280dff
Contents?: true
Size: 636 Bytes
Versions: 73
Compression:
Stored size: 636 Bytes
Contents
package AllYourBase; use strict; use warnings; use Carp; sub convert_base { my( $digits, $in_base, $out_base ) = @_; croak "base must be greater than 1" if grep { $_ <= 1 } $in_base, $out_base; croak 'negative digit not allowed' if grep { $_ < 0 } @$digits; croak 'digit equal of greater than the base' if grep { $_ >= $in_base } @$digits; my $number = 0; $number = $number * $in_base + $_ for @$digits; my @output; while( $number ) { unshift @output, $number % $out_base; $number = int $number / $out_base; } push @output, 0 unless @output; return \@output; } 1;
Version data entries
73 entries across 73 versions & 1 rubygems