rolfvanoven

troglodiet dag 10AB

Dec 12th, 2021 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1. # bestand lezen en in stukjes hakken:
  2. bestand = open('input.txt', 'r')
  3. alles = bestand.readlines()
  4.  
  5. for x in range(len(alles)):
  6.   alles[x] = alles[x].replace('\n', '')
  7.  
  8. fouten = []
  9. puntenlijst = []
  10.  
  11. for x in range(len(alles)):
  12.   corrupted = False
  13.   haakjes = []
  14.   for y in range(len(alles[x])):
  15.     if alles[x][y] == '(' or alles[x][y] == '[' or alles[x][y] == '{' or alles[x][y] == '<':
  16.       haakjes.append(alles[x][y])
  17.     if alles[x][y] == ')':
  18.       if haakjes[-1] == '(':
  19.         haakjes.pop(-1)
  20.       else:
  21.         if corrupted == False:
  22.           corrupted = True
  23. #          print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
  24.           fouten.append(alles[x][y])
  25.     if alles[x][y] == ']':
  26.       if haakjes[-1] == '[':
  27.         haakjes.pop(-1)
  28.       else:
  29.         if corrupted == False:
  30.           corrupted = True
  31. #          print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
  32.           fouten.append(alles[x][y])
  33.     if alles[x][y] == '}':
  34.       if haakjes[-1] == '{':
  35.         haakjes.pop(-1)
  36.       else:
  37.         if corrupted == False:
  38.           corrupted = True
  39. #          print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
  40.           fouten.append(alles[x][y])
  41.     if alles[x][y] == '>':
  42.       if haakjes[-1] == '<':
  43.         haakjes.pop(-1)
  44.       else:
  45.         if corrupted == False:
  46.           corrupted = True
  47. #          print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
  48.           fouten.append(alles[x][y])
  49.   if corrupted == False:
  50.     haakjes.reverse()
  51.     punten = 0
  52.     for y in range(len(haakjes)):
  53.       punten *= 5
  54.       if haakjes[y] == '(':
  55.         punten += 1
  56.       if haakjes[y] == '[':
  57.         punten += 2
  58.       if haakjes[y] == '{':
  59.         punten += 3
  60.       if haakjes[y] == '<':
  61.         punten += 4
  62.     puntenlijst.append(punten)
  63.  
  64. antwoorda = 0
  65. for x in range(len(fouten)):
  66.   if fouten[x] == ')':
  67.     antwoorda += 3
  68.   if fouten[x] == ']':
  69.     antwoorda += 57
  70.   if fouten[x] == '}':
  71.     antwoorda += 1197
  72.   if fouten[x] == '>':
  73.     antwoorda += 25137
  74.  
  75. puntenlijst.sort()
  76. middelste = (int(len(puntenlijst)/2))
  77. antwoordb = puntenlijst[middelste]
  78.  
  79.  
  80. print(antwoorda)
  81. print(antwoordb)
Add Comment
Please, Sign In to add comment