Initial commit
This commit is contained in:
commit
b1394d905a
18 changed files with 6496 additions and 0 deletions
16
day3/1.py
Normal file
16
day3/1.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
with open(r'day3/input.txt', 'r') as input:
|
||||
lines = input.read().split('\n')[:-1]
|
||||
|
||||
|
||||
sum = 0
|
||||
|
||||
for line in lines:
|
||||
# Transforming line to array of digits
|
||||
numbers = list(map(lambda x: int(x), list(line)))
|
||||
# Since the first digis is the most important, we can chose the best (careful to leave a single digit at the end to leave a second choice!)
|
||||
best1 = max(numbers[:-1])
|
||||
besti = numbers.index(best1) # first occurence of best digit
|
||||
best2 = max(numbers[besti+1:])
|
||||
sum += best1*10+best2
|
||||
|
||||
print(sum)
|
||||
Loading…
Add table
Add a link
Reference in a new issue