aboutsummaryrefslogtreecommitdiff
path: root/challenge-085/lubos-kolouch/python/ch-2.py
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2020-11-08 19:40:05 +0100
committerAbigail <abigail@abigail.be>2020-11-08 19:40:05 +0100
commit4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1 (patch)
tree52495c7853bf31c427ec26f500c66c5bed6753b4 /challenge-085/lubos-kolouch/python/ch-2.py
parent520db2cfca438cdc9a78932e5f479e28abee150b (diff)
parentff7475c4559b1087f402725a7c526d3f780e3434 (diff)
downloadperlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.gz
perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.bz2
perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-085/lubos-kolouch/python/ch-2.py')
-rw-r--r--challenge-085/lubos-kolouch/python/ch-2.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-085/lubos-kolouch/python/ch-2.py b/challenge-085/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..1f93585797
--- /dev/null
+++ b/challenge-085/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,25 @@
+#!/bin/env python
+" Task 2 Challenge 085 "
+
+from math import log, sqrt
+
+
+def is_power_two_integers(what):
+ " Find out if the number can be represented as x^y "
+
+ if what == 1:
+ return 1
+
+ for i in range(2, int(sqrt(what)) + 1):
+ diff = log(what) / log(i)
+
+ if diff - int(diff) < 0.00000001:
+ return 1
+
+ return 0
+
+
+assert is_power_two_integers(8) == 1
+assert is_power_two_integers(15) == 0
+assert is_power_two_integers(125) == 1
+assert is_power_two_integers(625) == 1