Skip to content

Instantly share code, notes, and snippets.

@def-
Created July 12, 2014 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save def-/2578abe885f99670e35e to your computer and use it in GitHub Desktop.
Save def-/2578abe885f99670e35e to your computer and use it in GitHub Desktop.
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