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
|
; 3. go through array, checking the neighbors of
|
||||||
; numbers for symbols, skip *last added index*,
|
; 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:
|
check_neighbors:
|
||||||
xor ecx, ecx ; index
|
xor ecx, ecx ; index
|
||||||
dec ecx ; gets incremented immediately
|
dec ecx ; gets incremented immediately
|
||||||
@ -110,53 +113,60 @@ je .check_next_number ; is last added idx, skip
|
|||||||
.check_symbols:
|
.check_symbols:
|
||||||
lea edx, [ecx+array] ; current char
|
lea edx, [ecx+array] ; current char
|
||||||
; right
|
; right
|
||||||
cmp byte [edx+1], '.'
|
lea ebp, [ecx+1]
|
||||||
je .r_nsym
|
cmp byte [edx+1], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.r_nsym:
|
|
||||||
; left
|
; left
|
||||||
cmp byte [edx-1], '.'
|
lea ebp, [ecx-1]
|
||||||
je .l_nsym
|
cmp byte [edx-1], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.l_nsym:
|
|
||||||
; top
|
; top
|
||||||
cmp byte [edx-(GRID_X+2)], '.'
|
lea ebp, [ecx-(GRID_X+2)]
|
||||||
je .t_nsym
|
cmp byte [edx-(GRID_X+2)], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.t_nsym:
|
|
||||||
; bottom
|
; bottom
|
||||||
cmp byte [edx+(GRID_X+2)], '.'
|
lea ebp, [ecx+(GRID_X+2)]
|
||||||
je .b_nsym
|
cmp byte [edx+(GRID_X+2)], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.b_nsym:
|
|
||||||
; top left
|
; top left
|
||||||
cmp byte [edx-((GRID_X+2)+1)], '.'
|
lea ebp, [ecx-((GRID_X+2)+1)]
|
||||||
je .tl_nsym
|
cmp byte [edx-((GRID_X+2)+1)], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.tl_nsym:
|
|
||||||
; top right
|
; top right
|
||||||
cmp byte [edx-((GRID_X+2)-1)], '.'
|
lea ebp, [ecx-((GRID_X+2)-1)]
|
||||||
je .tr_nsym
|
cmp byte [edx-((GRID_X+2)-1)], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.tr_nsym:
|
|
||||||
; bottom left
|
; bottom left
|
||||||
cmp byte [edx+((GRID_X+2)-1)], '.'
|
lea ebp, [ecx+((GRID_X+2)-1)]
|
||||||
je .bl_nsym
|
cmp byte [edx+((GRID_X+2)-1)], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.bl_nsym:
|
|
||||||
; bottom right
|
; bottom right
|
||||||
cmp byte [edx+((GRID_X+2)+1)], '.'
|
lea ebp, [ecx+((GRID_X+2)+1)]
|
||||||
je .br_nsym
|
cmp byte [edx+((GRID_X+2)+1)], '*'
|
||||||
jmp .has_sym_neighbor
|
je .has_sym_neighbor
|
||||||
.br_nsym:
|
|
||||||
; there's no symbol neighbor
|
; there's no symbol neighbor
|
||||||
; get next number
|
; get next number
|
||||||
jmp .check_next_number
|
jmp .check_next_number
|
||||||
.has_sym_neighbor:
|
.has_sym_neighbor:
|
||||||
; we have a symbol 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
|
; add to final value
|
||||||
mov edx, [numbers+eax*4]
|
add [final_value], eax
|
||||||
add [final_value], edx
|
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
|
; set last added idx
|
||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
; get next number
|
; get next number
|
||||||
|
Loading…
Reference in New Issue
Block a user