Skip to content

Instantly share code, notes, and snippets.

@mnzk
Created October 26, 2012 17:51
Show Gist options
  • Save mnzk/3960250 to your computer and use it in GitHub Desktop.
Save mnzk/3960250 to your computer and use it in GitHub Desktop.
is_prime2.py
from functools import partial as p
from itertools import ifilter
fth = lambda init, *fs: reduce(lambda a,f: f(a), fs, init)
is_prime = lambda n: n+1 == fth(
xrange(1, n+1),
p(ifilter, lambda potential: n%potential==0),
p(reduce, lambda x,y: x+y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment