From 61a451058aec82d30c6598bef8aa53b9de9e35ae Mon Sep 17 00:00:00 2001 From: David Vereb Date: Thu, 2 Dec 2021 11:32:43 -0500 Subject: [PATCH] Added updated version for puzzle #2. --- 2021/1/main2.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 2021/1/main2.py diff --git a/2021/1/main2.py b/2021/1/main2.py new file mode 100644 index 0000000..2cefe36 --- /dev/null +++ b/2021/1/main2.py @@ -0,0 +1,41 @@ +increment = 0 +decrement = 0 +same = 0 + +increment_3 = 0 +decrement_3 = 0 +same_3 = 0 + +with open('input', 'r') as fp: + last=[] + + for i,line in enumerate(fp): + amt = int(line) + + if(i > 0): + if(amt > last[-1]): + increment = increment + 1 + elif(amt < last[-1]): + decrement = decrement + 1 + else: + same = same + 1 + + if(i > 2): + if(amt > last[-3]): + increment_3 = increment_3 + 1 + elif(amt < last[-3]): + decrement_3 = decrement_3 + 1 + else: + same_3 = same_3 + 1 + + last.append(amt) + if(i > 2): + last.pop(0) # oldest is gone! + +print "Increased:", increment +print "Decreased:", decrement +print " Remained:", same + +print "Increased_3:", increment_3 +print "Decreased_3:", decrement_3 +print " Remained_3:", same_3