Created
December 19, 2012 11:42
-
-
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)
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 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