Created
July 12, 2014 11:29
-
-
Save def-/2578abe885f99670e35e to your computer and use it in GitHub Desktop.
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
import sequtils, math | |
template any(sequence, operation: expr): expr = | |
var result {.gensym.}: bool = false | |
for i in 0 .. <sequence.len: | |
let it {.inject.} = sequence[i] | |
result = operation | |
if result: | |
break | |
result | |
proc prime(a: int): bool = | |
result = not (a < 2 or any(toSeq 2 .. int sqrt float a, a mod it == 0)) | |
proc prime2(a): bool = | |
not (a < 2 or any(toSeq 2 .. int sqrt float a, a mod it == 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment