fixed some mistakes
This commit is contained in:
32
03/03p1.py
32
03/03p1.py
@@ -1,15 +1,15 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
sol = 0
|
sol = 0
|
||||||
inputfile = open("input.txt", "r")
|
inputfile = open("inputtest.txt", "r")
|
||||||
lines = inputfile.readlines()
|
lines = inputfile.readlines()
|
||||||
nums = dict()
|
nums = {}
|
||||||
syms = dict()
|
syms = {}
|
||||||
for line in range(len(lines)):
|
for line in range(len(lines)):
|
||||||
tempnum = ""
|
tempnum = ""
|
||||||
tempindex = -1
|
tempindex = -1
|
||||||
linenumdict = dict()
|
linenumdict = {}
|
||||||
linesymdict = dict()
|
linesymdict = {}
|
||||||
for index in range(len(lines[line])):
|
for index in range(len(lines[line])):
|
||||||
tempchar = lines[line][index]
|
tempchar = lines[line][index]
|
||||||
if tempchar.isdigit():
|
if tempchar.isdigit():
|
||||||
@@ -17,28 +17,28 @@ for line in range(len(lines)):
|
|||||||
if tempindex < 0:
|
if tempindex < 0:
|
||||||
tempindex = index
|
tempindex = index
|
||||||
else:
|
else:
|
||||||
if tempnum != "" and tempindex > 0 :
|
if tempnum != "" and tempindex >= 0 :
|
||||||
linenumdict[tempindex] = tempnum
|
linenumdict[tempindex] = tempnum
|
||||||
tempnum = ""
|
tempnum = ""
|
||||||
tempindex = -1
|
tempindex = -1
|
||||||
if tempchar != "." and tempchar != "\n":
|
if tempchar not in ('.', '\n'):
|
||||||
linesymdict[index] = tempchar
|
linesymdict[index] = tempchar
|
||||||
if tempnum != "" and tempindex > 0:
|
if tempnum != "" and tempindex >= 0:
|
||||||
linenumdict[tempindex] = tempnum
|
linenumdict[tempindex] = tempnum
|
||||||
nums[line] = linenumdict
|
nums[line] = linenumdict
|
||||||
syms[line] = linesymdict
|
syms[line] = linesymdict
|
||||||
for ykey in nums:
|
for ykey in nums:
|
||||||
for xkey in nums[ykey]:
|
for xkey in nums[ykey].keys():
|
||||||
hassym = False
|
hasNeigh= False
|
||||||
startx = xkey
|
startx = xkey - 1
|
||||||
endx = xkey + len(nums[ykey][xkey])
|
endx = xkey + len(nums[ykey][xkey]) + 1
|
||||||
starty = ykey - 1
|
starty = ykey - 1
|
||||||
endy = ykey + 1
|
endy = ykey + 1
|
||||||
for y in range(starty, endy):
|
for y in range(starty, endy):
|
||||||
if y in syms.keys():
|
if y in syms:
|
||||||
for x in range(startx, endx):
|
for x in range(startx, endx):
|
||||||
if x in syms[y].keys():
|
if x in syms[y].keys():
|
||||||
hassym = True
|
hasNeigh = True
|
||||||
if hassym:
|
if hasNeigh:
|
||||||
sol += int(nums[ykey][xkey])
|
sol += int(nums[ykey][xkey])
|
||||||
print(sol)
|
print(sol)
|
||||||
|
Reference in New Issue
Block a user