Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bestand inlezen:
- #bestand = open('voorbeeld.txt', 'r')
- bestand = open('input.txt', 'r')
- alles = bestand.readlines()
- for x in range(len(alles)):
- alles[x] = alles[x].replace('\n', '')
- hx = 0
- hy = 0
- tx = 0
- ty = 0
- staart = [[0,0]]
- for stap in range(len(alles)):
- #naar boven lopen:
- if alles[stap][0] == 'U':
- for stapje in range(int(alles[stap][2:])):
- hy += 1
- if hy - ty > 1:
- if hx == tx:
- ty += 1
- else:
- ty += 1
- tx = hx
- staartje = [ty,tx]
- if staartje not in staart:
- staart.append(staartje)
- #naar onder lopen:
- if alles[stap][0] == 'D':
- for stapje in range(int(alles[stap][2:])):
- hy -= 1
- if ty - hy > 1:
- if hx == tx:
- ty -= 1
- else:
- ty -= 1
- tx = hx
- staartje = [ty,tx]
- if staartje not in staart:
- staart.append(staartje)
- #naar rechts lopen:
- if alles[stap][0] == 'R':
- for stapje in range(int(alles[stap][2:])):
- hx += 1
- if hx - tx > 1:
- if hy == ty:
- tx += 1
- else:
- tx += 1
- ty = hy
- staartje = [ty,tx]
- if staartje not in staart:
- staart.append(staartje)
- #naar links lopen:
- if alles[stap][0] == 'L':
- for stapje in range(int(alles[stap][2:])):
- hx -= 1
- if tx - hx > 1:
- if hy == ty:
- tx -= 1
- else:
- tx -= 1
- ty = hy
- staartje = [ty,tx]
- if staartje not in staart:
- staart.append(staartje)
- print(len(staart))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement