Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Day3 Python3
- Part 1
- alfa=list(map(chr,[*range(97,123),*range(65,91)]))
- prior=0
- for s in open('input.txt'):
- for x in alfa:
- if x in s[:int(len(s) / 2)] and x in s[int(len(s) / 2):]:
- prior += alfa.index(x)+1
- print(prior)
- Part 1 one line
- print(sum([int(list(map(chr,[*range(97,123),*range(65,91)])).index(x)+1) for s in open('input.txt') for x in list(map(chr,[*range(97,123),*range(65,91)])) if (x in s[:int(len(s) / 2)] and x in s[int(len(s) / 2):])]))
- Part 2
- prior=0
- x=[line.strip() for line in open('input.txt')]
- lista = [x[i:i+3] for i in range(0,len(x),3)]
- print(lista)
- for sub in lista:
- for x in alfa:
- if all(x in sub[i] for i in range(3)):
- prior += alfa.index(x) + 1
- print(prior)
- Part 2 one line
- print(sum([(list(map(chr,[*range(97,123),*range(65,91)])).index(y)+1) for x in list(list(line.strip() for line in open('input.txt'))[i:i+3] for i in range(0,len(list(line for line in open('input.txt'))),3)) for y in (list(map(chr,[*range(97,123),*range(65,91)]))) if all(y in x[i] for i in range(3))]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement