diff options
| author | boblied <boblied@gmail.com> | 2023-01-23 08:29:56 -0600 |
|---|---|---|
| committer | boblied <boblied@gmail.com> | 2023-01-23 08:29:56 -0600 |
| commit | c2de8f565b88096181337a6e2890c7ca4b6a6e9e (patch) | |
| tree | 2a692c38c3d7d3a842ecefd526dab448af534f66 /challenge-200/eric-cheung/python/ch-1.py | |
| parent | 109bfa578eb7dad7db280313e577f9ce3659175f (diff) | |
| parent | 27b88f614b9bb53872ef0da19a56087505836db0 (diff) | |
| download | perlweeklychallenge-club-c2de8f565b88096181337a6e2890c7ca4b6a6e9e.tar.gz perlweeklychallenge-club-c2de8f565b88096181337a6e2890c7ca4b6a6e9e.tar.bz2 perlweeklychallenge-club-c2de8f565b88096181337a6e2890c7ca4b6a6e9e.zip | |
Merge branch 'master' of https://github.com/boblied/perlweeklychallenge-club
Diffstat (limited to 'challenge-200/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-200/eric-cheung/python/ch-1.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-200/eric-cheung/python/ch-1.py b/challenge-200/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..74f509b821 --- /dev/null +++ b/challenge-200/eric-cheung/python/ch-1.py @@ -0,0 +1,25 @@ +
+## arrInput = [1, 2, 3, 4] ## Example 1
+arrInput = [2] ## Example 2
+
+def IsArithmetic(arrSubInput):
+
+ if len(arrSubInput) < 3:
+ return False
+
+ nDiff = arrSubInput[1] - arrSubInput[0]
+
+ for nLoop in range(2, len(arrSubInput)):
+ if arrSubInput[nLoop] - arrSubInput[nLoop - 1] != nDiff:
+ return False
+
+ return True
+
+arrOutput = []
+
+for nLen in range(3, len(arrInput) + 1):
+ for nIndx in range(0, len(arrInput) - nLen + 1):
+ if IsArithmetic(arrInput[nIndx:nIndx + nLen]):
+ arrOutput.append(arrInput[nIndx:nIndx + nLen])
+
+print (arrOutput)
\ No newline at end of file |
