-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday08p1.py
More file actions
executable file
·38 lines (30 loc) · 812 Bytes
/
day08p1.py
File metadata and controls
executable file
·38 lines (30 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
with open('input/day08.txt') as fh:
data = fh.read().rstrip('\n').split('\n')
code_length = 0
memory_length = 0
for line in data:
code_length += len(line)
memsize = 0
escaped = False
hex_escape = 0
for char in line[1:-1]: # Strip enclosing double quotes
if hex_escape > 0:
if hex_escape == 1:
memsize +=1
hex_escape -= 1
continue
if escaped:
escaped = False
if char == 'x':
hex_escape = 2
else:
memsize += 1
continue
if char == '\\' and not escaped:
escaped = True
continue
else:
memsize += 1
memory_length += memsize
print code_length - memory_length