first commit
This commit is contained in:
48
08/part2.py
Normal file
48
08/part2.py
Normal file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line.rstrip()
|
||||
|
||||
|
||||
def getMemorySize(line):
|
||||
count = 0
|
||||
pos = 0
|
||||
while pos < len(line):
|
||||
if line[pos] != '\\':
|
||||
pos += 1
|
||||
count += 1
|
||||
elif line[pos+1] == '\\':
|
||||
pos += 2
|
||||
count += 4
|
||||
elif line[pos+1] == '"':
|
||||
pos += 2
|
||||
count += 4
|
||||
elif line[pos+1] == 'x':
|
||||
pos += 4
|
||||
count += 5
|
||||
else:
|
||||
print "chyba"
|
||||
return count
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
numCode = 0
|
||||
numMem = 0
|
||||
for line in read_file('input'):
|
||||
numCode = numCode + len(line)
|
||||
numMem = numMem + getMemorySize(line) + 4
|
||||
print line
|
||||
|
||||
print numCode
|
||||
print numMem
|
||||
print numMem - numCode
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user