-
-
Save grondilu/72daaea1a235a138597e745d29ce6fee to your computer and use it in GitHub Desktop.
hex root decimals in raku
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
sub integer_root ( Int $p where * >= 2, Int $n --> Int ) { | |
my Int $d = $p - 1; | |
my $guess = 10**($n.chars div $p); | |
my $iterator = { ( $d * $^x + $n div ($^x ** $d) ) div $p }; | |
my $endpoint = { $^x ** $p <= $n | |
and ($^x + 1) ** $p > $n }; | |
min (+$guess, $iterator ... $endpoint)[*-1, *-2]; | |
} | |
say (($_ - .Int)*2**64).fmt("%0x") given integer_root( 2, 2 * 2**128 ).FatRat / 2**64; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment