From 3e3f1987a27ad1dc8d1cea6582fc827bc7fbe210 Mon Sep 17 00:00:00 2001 From: Eric Douglas Date: Wed, 28 May 2014 10:37:01 -0300 Subject: [PATCH] add merge pattern 01.01.03 --- .../UNIT-01/03-problem-solving/.loops.py.swp | Bin 12288 -> 16384 bytes .../UNIT-01/03-problem-solving/loops.py | 21 ++++++++++++++++++ 2 files changed, 21 insertions(+) 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 5c5b27f4150d8bc11f1f891fb5cddf26c3ec7ba2..27cb1fc5d7402d4ace2fc52e0f6a7b0983abdcf3 100644 GIT binary patch delta 519 zcmZXQ&n^Q|6vj`B#DYw_lGdLb84XP@?XK-~0p3cjEiH3yDnp16QSsw!#h@=* zFA_=H+;#$iv4_PcMG4Xg96{HHxN^dwfpC|9px(}U-HwD_lnd_e?}2jeno;tq9p;5# z;RtRM?15#l0CFG+2)x7o3?9KPaIbqMkalj=p{S+Di4n3=mw9i;Y;t0rHKe0XZM=67 z!Y&)OZ5(PPQ|E%ePnRq`?<8U)5erg9Rwq15Iv#h+SUk@uXCpQ^xi9Uq^mCf%T!n>H zUfq-IWw~ZF8q%&3wU5@|m!JhsfmGU~p`@}?v(0M5 zFZ=gVBELhlR!WN*krQ)5OXjHIInZ!cM^HM KGdjx~9eo41ymbQr delta 114 zcmZo@U~EWGNHPfX^i?p|GiCq+0R{%O#D?HRhJOq#(hLl#MVZNy85vbJy6ofUXJn`c zs$c>s1A@NEf&${3Jp^{}PZnTQn54kMtHsE`P{$0E0vgh{Sx~{AX)`mU1|ypS7;LUn HZsGv|d-)dl 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 3acb769..0b5d78c 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 @@ -140,3 +140,24 @@ def shuffle4(array1, array2): array3.append(array1[i]) array3.append(array2[i]) return array3 + array2[i+1:] + +# The merge pattern + +def merge(array1, array2): + array3 = [] + i = 0 + j = 0 + while (i < len(array1) and j < len(array2)): + if array1[i] < array2[j]: + array3.append(array1[i]) + i += 1 + else: + array3.append(array2[j]) + j += 1 + return array3 + array1[i:] + array2[j:] + +## using the merge pattern +array1 = [1,3,4,6,8] +array2 = [2,5,7,9,10] + +print merge(array1, array2)