Created
August 1, 2014 06:39
-
-
Save takahiro47/2d040de7559fecf74885 to your computer and use it in GitHub Desktop.
エラトステネスの篩のワンライナー
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
## Solution 1 | |
x = 1000 | |
primes = [] | |
primes.push i for i in [2..x] when not (j for j in primes when i % j == 0).length | |
## Solution 2 | |
# 洗練する前 | |
# (n) -> (p.push i for i in [2..n] when not (j for j in (p or p=[]) when i%j == 0)[0]) and n in p | |
# 完成形 | |
(n) -> (p.push i for i in [2..n] when !(p or p=[]).some((j) -> i%j is 0)) and n in p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment