Added updated version for puzzle #2.
This commit is contained in:
parent
5fdc7e3444
commit
61a451058a
41
2021/1/main2.py
Normal file
41
2021/1/main2.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user