Advertisement
rolfvanoven

AoC 2023 dag 4

Dec 6th, 2023
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. # bestand lezen en in stukjes hakken:
  2. bestand = open('input.txt', 'r')
  3. alles = bestand.readlines()
  4. for x in range(len(alles)):
  5.   alles[x] = alles[x].replace('\n', '')
  6.   alles[x] = alles[x].split(':')[1]
  7.   alles[x] = alles[x].split('|')
  8.   alles[x][0] = alles[x][0].split(' ')
  9.   alles[x][1] = alles[x][1].split(' ')
  10.   while '' in alles[x][0]:
  11.     alles[x][0].remove('')
  12.   while '' in alles[x][1]:
  13.     alles[x][1].remove('')
  14.   alles[x].append(1)
  15.  
  16.  
  17.  
  18. #vraag A
  19.  
  20. antwoorda = 0
  21. for x in range(len(alles)):
  22.   dezekaart = 0
  23.   for y in range(len(alles[x][1])):
  24.     if alles[x][1][y] in alles[x][0]:
  25.       dezekaart += 1
  26.   antwoorda += int(2**(dezekaart-1))
  27.  
  28. print(antwoorda)
  29.  
  30.  
  31. #vraag B
  32.  
  33. antwoordb = 0
  34. for x in range(len(alles)):
  35.   dezekaart = 0
  36.   for y in range(len(alles[x][1])):
  37.     if alles[x][1][y] in alles[x][0]:
  38.       dezekaart += 1
  39.   if dezekaart > 0:
  40.     for y in range(dezekaart):
  41.       if x+y+1 < len(alles):
  42.         alles[x+y+1][2] += alles[x][2]
  43.   antwoordb += alles[x][2]
  44.  
  45. print(antwoordb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement