Minor improvements to 01

This commit is contained in:
Crista Lopes
2013-11-02 09:36:43 -07:00
parent 48b461fce0
commit 3af7744d5d

View File

@@ -11,7 +11,7 @@ def touchopen(filename, *args, **kwargs):
open(filename, "a").close() # "touch" file open(filename, "a").close() # "touch" file
return open(filename, *args, **kwargs) return open(filename, *args, **kwargs)
# The constrained memory, which consists of only 1024 bytes by constraint # The constrained memory, which consists of only 1024 cells by constraint
data = [] data = []
# Overall strategy: # Overall strategy:
@@ -101,7 +101,6 @@ del data[:]
data = data + [[]]*(25 - len(data)) data = data + [[]]*(25 - len(data))
data.append('') # data[25] is word,freq read from word_freqs file, and then word data.append('') # data[25] is word,freq read from word_freqs file, and then word
data.append(0) # data[26] is freq data.append(0) # data[26] is freq
#print data
while True: while True:
data[25] = word_freqs.readline().strip() data[25] = word_freqs.readline().strip()
@@ -112,9 +111,8 @@ while True:
for i in range(25): # elimination of symbol i left as exercise for i in range(25): # elimination of symbol i left as exercise
if data[i] == [] or data[i][1] < data[26]: if data[i] == [] or data[i][1] < data[26]:
#print str(i) + " " + str(data[25]) + " " + str(data[26])
data.insert(i, [data[25], data[26]]) data.insert(i, [data[25], data[26]])
del data[26] # pop the last element del data[26] # delete the last element
break break