blob: 66e78301c84a5359ca14fc237bb2b0600922eb55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/env perl
my $b=35;
foreach (@ARGV) {
my $power=0;
while (int($_/ $b**++$power) >= 1){};
$power--;
my @out=();
while ($power >= 0) {
my $place=$b**$power;
my $val=int($_ / $place);
my $digit= $val >= 10 ? chr(ord('A')+($val-10)) : $val;
push @out, $digit;
$_= $_- $place*$val;
$power--;
}
$base35=join "", @out;
print "Base 35: $base35\n";
my $place= length $base35;
$_=reverse $base35;
my $sum=0;
while(--$place >=0){
$val=chop $_;
$sum += $b**$place * (scalar (grep ($_ eq $val, "A".."Y")) ? (ord($val)-55) : $val);
}
print "Base 10: $sum\n";
}
|