aboutsummaryrefslogtreecommitdiff
path: root/challenge-148/eric-cheung/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-148/eric-cheung/python/ch-2.py')
-rwxr-xr-xchallenge-148/eric-cheung/python/ch-2.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-148/eric-cheung/python/ch-2.py b/challenge-148/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..1e1311e7d4
--- /dev/null
+++ b/challenge-148/eric-cheung/python/ch-2.py
@@ -0,0 +1,44 @@
+## Credit:
+## https://theweeklychallenge.org/blog/perl-weekly-challenge-148/
+## https://github.com/Anshumanmahan/Cardano-Triplets/blob/master/CardanoTriplets.py
+## https://medium.com/swift-programming/cardano-triplets-in-swift-114692293795
+
+import math
+
+nCount = 0
+nCountMax = 5
+
+nNumMax = 200
+
+for nNum_01 in range(1, nNumMax):
+ for nNum_02 in range(1, nNumMax):
+ for nNum_03 in range(1, nNumMax):
+ x = nNum_01 - nNum_02 * math.sqrt(nNum_03)
+
+ if (x > 0):
+ y = math.pow(x, float(1) / 3)
+ else:
+ y = - math.pow(abs(x), float(1) / 3)
+
+ z = math.pow(nNum_01 + nNum_02 * math.sqrt(nNum_03), float(1) / 3.0) + y
+
+ ## Floating Point Rounding Errors
+ if (z > 0.999999 and z < 1.000001):
+ nCount = nCount + 1
+ print(nNum_01, nNum_02, nNum_03)
+
+ if (nCount == nCountMax):
+ break;
+
+ if (nCount == nCountMax):
+ break;
+
+ if (nCount == nCountMax):
+ break;
+
+## Results
+## 2 1 5
+## 5 1 52
+## 5 2 13
+## 8 1 189
+## 8 3 21