Created
August 4, 2011 01:54
-
-
Save jettero/1124337 to your computer and use it in GitHub Desktop.
a curious little number encoder
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
| #!/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