aboutsummaryrefslogtreecommitdiff
path: root/challenge-234/packy-anderson/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-234/packy-anderson/python/ch-2.py')
-rwxr-xr-xchallenge-234/packy-anderson/python/ch-2.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-234/packy-anderson/python/ch-2.py b/challenge-234/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..9024561157
--- /dev/null
+++ b/challenge-234/packy-anderson/python/ch-2.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+def findTriplets(ints):
+ solutions = []
+ for i in range(0, len(ints) - 3 ):
+ for j in range(i + 1, len(ints) - 2):
+ for k in range(j + 1, len(ints) - 1):
+ if (ints[i] != ints[j] and
+ ints[j] != ints[k] and
+ ints[i] != ints[k]):
+ solutions.append([i, j, k])
+ return solutions
+
+def solution(ints):
+ intlist = ", ".join([ str(i) for i in ints ])
+ print(f'Input: @ints = ({intlist})')
+ solutions = findTriplets(ints)
+ print(f'Output: {len(solutions)}')
+ if solutions:
+ print("")
+ for triplet in solutions:
+ i, j, k = triplet
+ print(
+ f"({i}, {j}, {k}) because " +
+ f"{ints[i]} != {ints[j]} != {ints[k]}"
+ )
+
+print("Example 1:")
+solution([4, 4, 2, 4, 3])
+
+print("\nExample 2:")
+solution([1, 1, 1, 1, 1])
+
+print("\nExample 3:")
+solution([4, 7, 1, 10, 7, 4, 1, 1]) \ No newline at end of file