Advertisement
icarussiano

Python 3 Day 3

Dec 3rd, 2022 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. Day3 Python3
  2. Part 1
  3. alfa=list(map(chr,[*range(97,123),*range(65,91)]))
  4. prior=0
  5. for s in open('input.txt'):
  6.     for x in alfa:
  7.         if x in s[:int(len(s) / 2)] and x in s[int(len(s) / 2):]:
  8.             prior += alfa.index(x)+1
  9. print(prior)
  10. Part 1 one line
  11. 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):])]))
  12.  
  13. Part 2
  14. prior=0
  15. x=[line.strip() for line in open('input.txt')]
  16. lista = [x[i:i+3] for i in range(0,len(x),3)]
  17. print(lista)
  18. for sub in lista:
  19.     for x in alfa:
  20.         if all(x in sub[i] for i in range(3)):
  21.             prior += alfa.index(x) + 1
  22. print(prior)
  23. Part 2 one line
  24. 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))]))
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement