Created
July 9, 2014 09:12
-
-
Save egisatoshi/0cd4bd96b9a2bde0fa3f to your computer and use it in GitHub Desktop.
続編 - RubyにHaskellよりも強力なパターンマッチを実装した ref: http://qiita.com/egisatoshi/items/dfa13e45edbc71430048
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
require 'egison' | |
require 'prime' | |
include Egison | |
twin_primes = match_stream(Prime) { | |
with(List.(*_, _x, __("x + 2"), *_)) { | |
[x, x + 2] | |
} | |
} | |
# print the first 10 prime twins | |
p twin_primes.take(10) | |
#=>[[3, 5], [5, 7], [11, 13], [17, 19], [29, 31], [41, 43], [59, 61], [71, 73], [101, 103], [107, 109]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment