Solve first challenge and update template
This commit is contained in:
1 parent
bf479f12b5
commit
9cb373798d
4 files changed
+2125
-3
No files matched your search
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
measurements = open(sys.argv[1]).read().strip('\n\n').split('\n')
|
||||
meas = [int(i) for i in measurements]
|
||||
|
||||
# challenge 1
|
||||
incr = 0
|
||||
last = 0
|
||||
for i in meas:
|
||||
if i > last:
|
||||
incr += 1
|
||||
last = i
|
||||
res1 = str(incr - 1)
|
||||
print("challenge 1: " + res1 + "\n")
|
||||
|
||||
# challenge 2
|
||||
incr = 0
|
||||
first = meas[0]
|
||||
second = meas[1]
|
||||
third = meas[2]
|
||||
last = first + second + third
|
||||
for i in meas[3:]:
|
||||
first = second
|
||||
second = third
|
||||
third = i
|
||||
nex = first + second + third
|
||||
if nex > last:
|
||||
incr += 1
|
||||
last = nex
|
||||
res2 = str(incr)
|
||||
print("challenge 2: " + res2 + "\n")
|
||||
|
||||
Reference in new issue
Block a user