add niceties to day 2
This commit is contained in:
		@@ -11,16 +11,15 @@ def get_G(x,y):
 | 
			
		||||
def is_sym(a:str) -> bool:
 | 
			
		||||
    return a != '.' and not a.isdigit()
 | 
			
		||||
 | 
			
		||||
S = 0
 | 
			
		||||
c = 0  # current
 | 
			
		||||
valid = False
 | 
			
		||||
Ns = []  # all part numbers
 | 
			
		||||
for y in range(H):
 | 
			
		||||
    for x in range(W):
 | 
			
		||||
        i = get_G(x,y)
 | 
			
		||||
        if not i.isdigit():
 | 
			
		||||
            # appent current if valid and reset
 | 
			
		||||
            if valid:
 | 
			
		||||
                Ns.append(c)
 | 
			
		||||
                S += c
 | 
			
		||||
            valid = False
 | 
			
		||||
            c = 0
 | 
			
		||||
        else:
 | 
			
		||||
@@ -29,4 +28,4 @@ for y in range(H):
 | 
			
		||||
                for dy in [-1,0,1]:
 | 
			
		||||
                    valid |= is_sym(get_G(x+dx,y+dy))
 | 
			
		||||
 | 
			
		||||
print(sum(Ns))
 | 
			
		||||
print(S)
 | 
			
		||||
 
 | 
			
		||||
@@ -28,8 +28,6 @@ for y in range(H):
 | 
			
		||||
                    if '*' == get_G(x+dx,y+dy):
 | 
			
		||||
                        valid = (x+dx,y+dy)
 | 
			
		||||
 | 
			
		||||
S = 0
 | 
			
		||||
for _,v in Rs.items():
 | 
			
		||||
    if len(v)==2:
 | 
			
		||||
        S += v[0] * v[1]
 | 
			
		||||
print(S)
 | 
			
		||||
print(
 | 
			
		||||
    sum( v[0] * v[1] for _,v in Rs.items() if len(v)==2)
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user