Skip to content

Instantly share code, notes, and snippets.

@mebusw
Created August 19, 2016 13:47
Show Gist options
  • Save mebusw/e0af979fbcc8a47db95bbe68d2b32154 to your computer and use it in GitHub Desktop.
Save mebusw/e0af979fbcc8a47db95bbe68d2b32154 to your computer and use it in GitHub Desktop.
functional programming for Prime Factor
# https://codingstyle.cn/topics/202
def f(n, p=2):
if n < 2: return []
if n % p == 0: return [p] + f(n/p, p)
return f(n, p+1)
assert [2,2,3,3,3,5,5,19] == f(2*2*3*3*3*5*5*19)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment