From 36d2865b720d39259343c2452678b46a3c0ed61c Mon Sep 17 00:00:00 2001 From: Eric Douglas Date: Sat, 24 May 2014 06:07:38 -0300 Subject: [PATCH] add the shuffle pattern - 1.1.3 --- .../UNIT-01/03-problem-solving/.loops.py.swp | Bin 12288 -> 12288 bytes .../UNIT-01/03-problem-solving/loops.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/03-problem-solving/.loops.py.swp b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/03-problem-solving/.loops.py.swp index 930693d7c37e721ed6145e59de936fc6f203732a..5c5b27f4150d8bc11f1f891fb5cddf26c3ec7ba2 100644 GIT binary patch delta 401 zcmY+wEXrD^YvTH?){TYc;$- zps}TbaIN+rXmD-{=6R(ChIcx|ObIB_CP_O~T{)AUG;|Z3s`F}@a*0G3e wI?WAf9&@+-TU1PP!|$@RET?tAt}=bsbJ{KJdz)PhhMCc1gA0)#>}faiKj~{^e*gdg delta 168 zcmZojXh={K28Q+V4Z%?i{}@`N85mNFGLt7WGOBEJIm6G`yjf7- zGe7S{CI*I`ED*IoA%)9~c2;Z*3`RiA4a9F)85qt2@hTu*3B=t%oD0P9KpYOl8bHhq t#P5JcJO<*OESnh_r!!67pei-_y2@u}1#N}Nr&W8w^latO&Fj>HI01CJCT;)# diff --git a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/03-problem-solving/loops.py b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/03-problem-solving/loops.py index e091dc6..3acb769 100644 --- a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/03-problem-solving/loops.py +++ b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/03-problem-solving/loops.py @@ -113,12 +113,12 @@ def shuffle2(array1, array2): for i in range(len(array1), 1): array3.append(array1[i]) array3.append(array2[i]) - return array3 + array2[i + 1:] + return array3 + array2[i+1:] else: for i in range(0, len(array2), 1): array3.append(array1[i]) array3.append(array2[i]) - return array3 + array1[i + 1:] + return array3 + array1[i+1:] ## using a while loop instead def shuffle3(array1, array2): @@ -129,3 +129,14 @@ def shuffle3(array1, array2): array3.append(array2[i]) i += 1 return array3 + array1[i:] + array2[i:] + +## back to shuffle2 but adding recursion +def shuffle4(array1, array2): + if len(array2) < len(array1): + return shuffle4(array2, array1) # arrays are flipped + else: + array3 = [] + for i in range(0, len(array1), 1): + array3.append(array1[i]) + array3.append(array2[i]) + return array3 + array2[i+1:]