Created
May 6, 2014 02:12
-
-
Save akanehara/441098a65e6edb08d640 to your computer and use it in GitHub Desktop.
Ginqのunfoldで余再帰sieve。非効率きわまりないお遊びなので実用しないでね。
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
<?php | |
require_once("vendor/autoload.php"); | |
$primes = Ginq::from([2])->concat(Ginq::unfold( | |
Ginq::range(3,null,2), | |
function($xs) { | |
$x = $xs->first(); | |
return [ | |
$x, | |
$xs->drop(1)->filter(['y'=>'y % x != 0', 'x'=>$x]) | |
]; | |
} | |
)); | |
foreach($primes as $n) { | |
echo "$n\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment