Skip to content

Instantly share code, notes, and snippets.

@jettero
Created August 4, 2011 01:54
Show Gist options
  • Select an option

  • Save jettero/1124337 to your computer and use it in GitHub Desktop.

Select an option

Save jettero/1124337 to your computer and use it in GitHub Desktop.
a curious little number encoder
#!/usr/bin/perl
use common::sense;
use Math::BigInt;
my $orig = $ARGV[0] ? Math::BigInt->new(shift) : Math::BigInt->new(1 . (0 x 3000)) + 7;
my $res = blog_reduce($orig);
print stringify_series( $res ), "\n";
sub stringify_series {
my ($base, $logf, $delta) = @{$_[0]};
my $ret = "$base";
$ret .= "^" . (ref($logf) eq "ARRAY" ? "(" . stringify_series($logf) . ")" : $logf);
$ret .= " + " . (ref($delta) eq "ARRAY" ? "(" . stringify_series($delta) . ")" : $delta) if $delta;
return $ret;
}
sub blog_reduce {
my $arg = shift;
my $logf = $arg->copy->blog(10);
my $delta = $arg - Math::BigInt->new(10)->bpow($logf);
$logf = blog_reduce( $logf ) if $logf > 99;
$delta = blog_reduce( $delta ) if $delta > 99;
return [10, $logf, $delta];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment