Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created December 19, 2012 11:42
Show Gist options
  • Save grondilu/4336126 to your computer and use it in GitHub Desktop.
Save grondilu/4336126 to your computer and use it in GitHub Desktop.
Continued fractions in Perl6 (candidate for http://rosettacode.org/wiki/Continued_fraction#Perl6)
sub infix:<o>(&f, &g) { -> $x { &f(&g($x)) } }
sub continued-fraction(@a, @b)
{
gather for [\o] (@a.shift + @b.shift / *) xx * {
take .(Inf)
}
}
say continued-fraction((1, 2 xx *).list, (1 xx *).list)[3];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment