Compare commits
2 Commits
04c65d31ec
...
a22eae433f
Author | SHA1 | Date | |
---|---|---|---|
a22eae433f | |||
eb2c632a03 |
75
03/03p1.py
75
03/03p1.py
@@ -3,13 +3,13 @@
|
||||
sol = 0
|
||||
inputfile = open("input.txt", "r")
|
||||
lines = inputfile.readlines()
|
||||
nums = dict()
|
||||
syms = dict()
|
||||
nums = {}
|
||||
syms = {}
|
||||
for line in range(len(lines)):
|
||||
tempnum = ""
|
||||
tempindex = -1
|
||||
linenumdict = dict()
|
||||
linesymdict = dict()
|
||||
linenumdict = {}
|
||||
linesymdict = {}
|
||||
for index in range(len(lines[line])):
|
||||
tempchar = lines[line][index]
|
||||
if tempchar.isdigit():
|
||||
@@ -17,28 +17,75 @@ for line in range(len(lines)):
|
||||
if tempindex < 0:
|
||||
tempindex = index
|
||||
else:
|
||||
if tempnum != "" and tempindex > 0 :
|
||||
if tempnum != "" and tempindex >= 0 :
|
||||
linenumdict[tempindex] = tempnum
|
||||
tempnum = ""
|
||||
tempindex = -1
|
||||
if tempchar != "." and tempchar != "\n":
|
||||
if tempchar not in ('.', '\n'):
|
||||
linesymdict[index] = tempchar
|
||||
if tempnum != "" and tempindex > 0:
|
||||
if tempnum != "" and tempindex >= 0:
|
||||
linenumdict[tempindex] = tempnum
|
||||
nums[line] = linenumdict
|
||||
syms[line] = linesymdict
|
||||
for ykey in nums:
|
||||
for xkey in nums[ykey]:
|
||||
hassym = False
|
||||
startx = xkey
|
||||
hasNeigh= False
|
||||
startx = xkey - 1
|
||||
endx = xkey + len(nums[ykey][xkey])
|
||||
starty = ykey - 1
|
||||
endy = ykey + 1
|
||||
for y in range(starty, endy):
|
||||
if y in syms.keys():
|
||||
for x in range(startx, endx):
|
||||
for y in range(starty, endy + 1):
|
||||
if y in syms:
|
||||
for x in range(startx, endx + 1):
|
||||
if x in syms[y].keys():
|
||||
hassym = True
|
||||
if hassym:
|
||||
print(nums[ykey][xkey] + 'has Neigh: ' + syms[y][x])
|
||||
hasNeigh = True
|
||||
if hasNeigh:
|
||||
sol += int(nums[ykey][xkey])
|
||||
print(sol)
|
||||
#sometest:
|
||||
lineno = 0
|
||||
for line in lines:
|
||||
line = line.replace('*', '.')
|
||||
line = line.replace('=', '.')
|
||||
line = line.replace('+', '.')
|
||||
line = line.replace('%', '.')
|
||||
line = line.replace('$', '.')
|
||||
line = line.replace('#', '.')
|
||||
line = line.replace('-', '.')
|
||||
line = line.replace('&', '.')
|
||||
line = line.replace('@', '.')
|
||||
line = line.replace('/', '.')
|
||||
while not line.find('..') < 0:
|
||||
line = line.replace('..', '.')
|
||||
line = line.replace('.', ' ')
|
||||
line = line.replace('\n', '')
|
||||
line = line.lstrip()
|
||||
listnum = line.split()
|
||||
diff = len(listnum)-len(nums[lineno])
|
||||
if diff != 0:
|
||||
print(diff)
|
||||
lineno += 1
|
||||
|
||||
lineno = 0
|
||||
for line in lines:
|
||||
line = line.replace('1', '.')
|
||||
line = line.replace('2', '.')
|
||||
line = line.replace('3', '.')
|
||||
line = line.replace('4', '.')
|
||||
line = line.replace('5', '.')
|
||||
line = line.replace('6', '.')
|
||||
line = line.replace('7', '.')
|
||||
line = line.replace('8', '.')
|
||||
line = line.replace('9', '.')
|
||||
line = line.replace('0', '.')
|
||||
while not line.find('..') < 0:
|
||||
line = line.replace('..', '.')
|
||||
line = line.replace('.', ' ')
|
||||
line = line.replace('\n', '')
|
||||
line = line.lstrip()
|
||||
listnum = line.split()
|
||||
diff = len(listnum)-len(syms[lineno])
|
||||
if diff != 0:
|
||||
print(diff)
|
||||
lineno += 1
|
||||
|
Reference in New Issue
Block a user