aboutsummaryrefslogtreecommitdiff
path: root/challenge-055
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-055')
-rw-r--r--challenge-055/yet-ebreo/python/ch-2a.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-055/yet-ebreo/python/ch-2a.py b/challenge-055/yet-ebreo/python/ch-2a.py
new file mode 100644
index 0000000000..15b537d506
--- /dev/null
+++ b/challenge-055/yet-ebreo/python/ch-2a.py
@@ -0,0 +1,35 @@
+import sys
+import time
+
+start_time = time.time()
+
+if len(sys.argv) < 2:
+ narray = [1, 2, 3, 4]
+else:
+ narray = list(map(int, sys.argv[1:]))
+
+narray.sort()
+dict = {}
+
+def wave(a,l,r):
+
+ if (l==r):
+ flag = 1
+ for e in list(range(1,len(a))):
+ flag &= (a[e] >= a[e-1], a[e] <= a[e-1])[e % 2 > 0]
+ if not flag:
+ break
+
+ if flag > 0:
+ hold = str(a)
+ if (not hold in dict):
+ print (hold)
+ dict[hold] = 1
+ else:
+ for i in list(range(l,r+1)):
+ a[l],a[i] = a[i],a[l]
+ wave(a,l+1,r)
+ a[l],a[i] = a[i],a[l]
+
+wave(narray,0,len(narray)-1)
+print("Execution Time: %s seconds" % (time.time() - start_time)) \ No newline at end of file