diff options
Diffstat (limited to 'challenge-344/eric-cheung/python')
| -rwxr-xr-x | challenge-344/eric-cheung/python/ch-1.py | 25 | ||||
| -rwxr-xr-x | challenge-344/eric-cheung/python/ch-2.py | 34 |
2 files changed, 59 insertions, 0 deletions
diff --git a/challenge-344/eric-cheung/python/ch-1.py b/challenge-344/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..23cff3d29a --- /dev/null +++ b/challenge-344/eric-cheung/python/ch-1.py @@ -0,0 +1,25 @@ +
+## Example 1
+## arrInt = [1, 2, 3, 4]
+## nX = 12
+
+## Example 2
+## arrInt = [2, 7, 4]
+## nX = 181
+
+## Example 3
+## arrInt = [9, 9, 9]
+## nX = 1
+
+## Example 4
+## arrInt = [1, 0, 0, 0, 0]
+## nX = 9999
+
+## Example 5
+arrInt = [0]
+nX = 1000
+
+nOutput = int("".join([str(nLoop) for nLoop in arrInt])) + nX
+arrOutput = [int(strLoop) for strLoop in str(nOutput)]
+
+print (arrOutput)
diff --git a/challenge-344/eric-cheung/python/ch-2.py b/challenge-344/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..6aaef3792d --- /dev/null +++ b/challenge-344/eric-cheung/python/ch-2.py @@ -0,0 +1,34 @@ +
+from itertools import permutations
+
+## Example 1
+## arrSource = [[2, 3], [1], [4]]
+## arrTarget = [1, 2, 3, 4]
+
+## Example 2
+## arrSource = [[1, 3], [2, 4]]
+## arrTarget = [1, 2, 3, 4]
+
+## Example 3
+## arrSource = [[9, 1], [5, 8], [2]]
+## arrTarget = [5, 8, 2, 9, 1]
+
+## Example 4
+## arrSource = [[1], [3]]
+## arrTarget = [1, 2, 3]
+
+## Example 5
+arrSource = [[7, 4, 6]]
+arrTarget = [7, 4, 6]
+
+strTarget = "".join(map(str, arrTarget))
+arrPerm = permutations(arrSource)
+
+bIsFound = False
+for arrLoop in arrPerm:
+ strTemp = "".join(["".join(map(str, arrSubLoop)) for arrSubLoop in arrLoop])
+ if strTarget == strTemp:
+ bIsFound = True
+ break
+
+print (bIsFound)
|
