aboutsummaryrefslogtreecommitdiff
path: root/python/helper/numbers.py
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-08-12 15:47:31 +0200
committerCharles <sircharlesaze@gmail.com>2019-08-12 15:47:31 +0200
commitbb515e51d67f37ba9c6dfbd2fd0930be873a5ada (patch)
treee86abea100d2c02a5dad7b6d5f0bf29c307bae04 /python/helper/numbers.py
parent1879caa1dd80cb11dd62403663917ad4bf7cc68e (diff)
downloadproject_euler-bb515e51d67f37ba9c6dfbd2fd0930be873a5ada.tar.gz
project_euler-bb515e51d67f37ba9c6dfbd2fd0930be873a5ada.tar.bz2
project_euler-bb515e51d67f37ba9c6dfbd2fd0930be873a5ada.zip
haskell problems 007 -> 010
Diffstat (limited to 'python/helper/numbers.py')
-rw-r--r--python/helper/numbers.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/python/helper/numbers.py b/python/helper/numbers.py
new file mode 100644
index 0000000..f99f205
--- /dev/null
+++ b/python/helper/numbers.py
@@ -0,0 +1,47 @@
+from functools import reduce
+from itertools import count
+
+
+def sum_digits(n):
+ return reduce(lambda x, y: x + int(y), str(n), 0)
+
+
+def triangular(n):
+ return n * (n+1) // 2
+
+
+def pentagonal(n):
+ return n * (3*n - 1) // 2
+
+
+def hexagonal(n):
+ return n * (2*n - 1)
+
+
+def is_triangular(n):
+ for i in count(1):
+ t = triangular(i)
+ if t >= n:
+ return t == n
+
+
+# def is_pentagonal(n):
+# for i in count(1):
+# p = pentagonal(i)
+# if p >= n:
+# return p == n
+
+
+# def is_hexagonal(n):
+# for i in count(1):
+# h = hexagonal(i)
+# if h >= n:
+# return h == n
+
+
+def proper_divisors(num):
+ divisor = []
+ for i in range(1, num):
+ if num % i == 0:
+ divisor.append(i)
+ return divisor