Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created January 3, 2014 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/8239521 to your computer and use it in GitHub Desktop.
Save grondilu/8239521 to your computer and use it in GitHub Desktop.
hickerson series, see rosettacode.org
constant ln2 = FatRat.new(11497654316995854314538600826176386914675840284781772934832310629025531009647835922483180950073671, 16587608864985500678430621519107217028770145595488224555912965535307732927005633645841205742796800);
# [\+] map { 1.FatRat / 2**$_ / $_ }, 1 .. *;
# FatRat.new(33636436125281008291653702688829128057940764118386796024399, 48527119591121290137917232399964930206766900113689699942400);
subset AlmostInt of FatRat where -> $x { abs($x - $x.round) < .1 }
sub h($n) returns FatRat { ([*] 2 .. $n) / (2*ln2**($n+1)) }
for 1 .. 17 -> $n {
my $h = h($n);
printf "h(%2d) ≈ %26.6f is {$h ~~ AlmostInt ?? "" !! "NOT "} almost integer\n", $n, $h;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment