Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bestand lezen en in stukjes hakken:
- bestand = open('input.txt', 'r')
- alles = bestand.readlines()
- for x in range(len(alles)):
- alles[x] = alles[x].replace('\n', '')
- fouten = []
- puntenlijst = []
- for x in range(len(alles)):
- corrupted = False
- haakjes = []
- for y in range(len(alles[x])):
- if alles[x][y] == '(' or alles[x][y] == '[' or alles[x][y] == '{' or alles[x][y] == '<':
- haakjes.append(alles[x][y])
- if alles[x][y] == ')':
- if haakjes[-1] == '(':
- haakjes.pop(-1)
- else:
- if corrupted == False:
- corrupted = True
- # print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
- fouten.append(alles[x][y])
- if alles[x][y] == ']':
- if haakjes[-1] == '[':
- haakjes.pop(-1)
- else:
- if corrupted == False:
- corrupted = True
- # print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
- fouten.append(alles[x][y])
- if alles[x][y] == '}':
- if haakjes[-1] == '{':
- haakjes.pop(-1)
- else:
- if corrupted == False:
- corrupted = True
- # print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
- fouten.append(alles[x][y])
- if alles[x][y] == '>':
- if haakjes[-1] == '<':
- haakjes.pop(-1)
- else:
- if corrupted == False:
- corrupted = True
- # print('error in lijn', x, ',', alles[x][y], 'probeert ', haakjes[-1], 'te closen')
- fouten.append(alles[x][y])
- if corrupted == False:
- haakjes.reverse()
- punten = 0
- for y in range(len(haakjes)):
- punten *= 5
- if haakjes[y] == '(':
- punten += 1
- if haakjes[y] == '[':
- punten += 2
- if haakjes[y] == '{':
- punten += 3
- if haakjes[y] == '<':
- punten += 4
- puntenlijst.append(punten)
- antwoorda = 0
- for x in range(len(fouten)):
- if fouten[x] == ')':
- antwoorda += 3
- if fouten[x] == ']':
- antwoorda += 57
- if fouten[x] == '}':
- antwoorda += 1197
- if fouten[x] == '>':
- antwoorda += 25137
- puntenlijst.sort()
- middelste = (int(len(puntenlijst)/2))
- antwoordb = puntenlijst[middelste]
- print(antwoorda)
- print(antwoordb)
Add Comment
Please, Sign In to add comment