day 3 part 2
This commit is contained in:
parent
f805701abf
commit
b1921a7656
10
03/input_test2
Normal file
10
03/input_test2
Normal file
@ -0,0 +1,10 @@
|
||||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
80
03/main.s
80
03/main.s
@ -87,7 +87,10 @@ add esp, 4 ; no more cur num idx
|
||||
|
||||
; 3. go through array, checking the neighbors of
|
||||
; numbers for symbols, skip *last added index*,
|
||||
; adding numbers with sym neighbors to final_value
|
||||
; if has * as neighbor, replace the index of the *
|
||||
; with the current number index if it has no index currently,
|
||||
; otherwise multiply by the number its index points to
|
||||
; and add to final_value, setting last added index to current index
|
||||
check_neighbors:
|
||||
xor ecx, ecx ; index
|
||||
dec ecx ; gets incremented immediately
|
||||
@ -110,53 +113,60 @@ je .check_next_number ; is last added idx, skip
|
||||
.check_symbols:
|
||||
lea edx, [ecx+array] ; current char
|
||||
; right
|
||||
cmp byte [edx+1], '.'
|
||||
je .r_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.r_nsym:
|
||||
lea ebp, [ecx+1]
|
||||
cmp byte [edx+1], '*'
|
||||
je .has_sym_neighbor
|
||||
; left
|
||||
cmp byte [edx-1], '.'
|
||||
je .l_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.l_nsym:
|
||||
lea ebp, [ecx-1]
|
||||
cmp byte [edx-1], '*'
|
||||
je .has_sym_neighbor
|
||||
; top
|
||||
cmp byte [edx-(GRID_X+2)], '.'
|
||||
je .t_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.t_nsym:
|
||||
lea ebp, [ecx-(GRID_X+2)]
|
||||
cmp byte [edx-(GRID_X+2)], '*'
|
||||
je .has_sym_neighbor
|
||||
; bottom
|
||||
cmp byte [edx+(GRID_X+2)], '.'
|
||||
je .b_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.b_nsym:
|
||||
lea ebp, [ecx+(GRID_X+2)]
|
||||
cmp byte [edx+(GRID_X+2)], '*'
|
||||
je .has_sym_neighbor
|
||||
; top left
|
||||
cmp byte [edx-((GRID_X+2)+1)], '.'
|
||||
je .tl_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.tl_nsym:
|
||||
lea ebp, [ecx-((GRID_X+2)+1)]
|
||||
cmp byte [edx-((GRID_X+2)+1)], '*'
|
||||
je .has_sym_neighbor
|
||||
; top right
|
||||
cmp byte [edx-((GRID_X+2)-1)], '.'
|
||||
je .tr_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.tr_nsym:
|
||||
lea ebp, [ecx-((GRID_X+2)-1)]
|
||||
cmp byte [edx-((GRID_X+2)-1)], '*'
|
||||
je .has_sym_neighbor
|
||||
; bottom left
|
||||
cmp byte [edx+((GRID_X+2)-1)], '.'
|
||||
je .bl_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.bl_nsym:
|
||||
lea ebp, [ecx+((GRID_X+2)-1)]
|
||||
cmp byte [edx+((GRID_X+2)-1)], '*'
|
||||
je .has_sym_neighbor
|
||||
; bottom right
|
||||
cmp byte [edx+((GRID_X+2)+1)], '.'
|
||||
je .br_nsym
|
||||
jmp .has_sym_neighbor
|
||||
.br_nsym:
|
||||
lea ebp, [ecx+((GRID_X+2)+1)]
|
||||
cmp byte [edx+((GRID_X+2)+1)], '*'
|
||||
je .has_sym_neighbor
|
||||
; there's no symbol neighbor
|
||||
; get next number
|
||||
jmp .check_next_number
|
||||
.has_sym_neighbor:
|
||||
; we have a symbol neighbor!
|
||||
; get its id
|
||||
movzx edx, word [index+ebp*2]
|
||||
test edx, edx
|
||||
jz .no_sym_number ; * doesn't have a number assigned yet
|
||||
; multiply by its number!
|
||||
pushad ; out of registers lol
|
||||
mov eax, [numbers+eax*4] ; our number
|
||||
mul dword [numbers+edx*4] ; * number
|
||||
; add to final value
|
||||
mov edx, [numbers+eax*4]
|
||||
add [final_value], edx
|
||||
add [final_value], eax
|
||||
popad ; get back values :3
|
||||
; set last added idx
|
||||
mov ebx, eax
|
||||
; get next number
|
||||
jmp .check_next_number
|
||||
.no_sym_number:
|
||||
; save our index in the * index
|
||||
mov [index+ebp*2], ax
|
||||
; set last added idx
|
||||
mov ebx, eax
|
||||
; get next number
|
||||
|
Loading…
Reference in New Issue
Block a user