mirror of
https://git.plasmaofthedawn.com/adventofcode.git
synced 2025-12-23 18:17:35 -06:00
pladcl day11 and day12
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
state start
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
|
||||
read_number()
|
||||
`dnSN`
|
||||
`[ ]n`
|
||||
`0SD`
|
||||
blink()
|
||||
`lo+so`
|
||||
end
|
||||
|
||||
interrupt program_start
|
||||
# C: cache
|
||||
`0sc`
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
`10an`
|
||||
`lop`
|
||||
end
|
||||
|
||||
function print_array
|
||||
|
||||
for '?' in `l0` to `lc` do
|
||||
array_get('X', `l?`)
|
||||
`n[ ]n`
|
||||
end
|
||||
`10an`
|
||||
|
||||
end
|
||||
|
||||
|
||||
function blink
|
||||
# N: number
|
||||
# D: depth
|
||||
|
||||
# if we hit max depth
|
||||
if `lD` == 25 then
|
||||
`LNstLDst`
|
||||
return 1
|
||||
end
|
||||
|
||||
# check cache
|
||||
if `lN` < 1000000 then
|
||||
if array_get('C', `lNlD1000000*+`) > 0 then
|
||||
return array_get('C', `LNLD1000000*+`)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# 0 case -- check 1 rock
|
||||
if `lN` == 0 then
|
||||
|
||||
`1SN`
|
||||
`lD1+SD`
|
||||
blink()
|
||||
|
||||
end
|
||||
# even digit case -- check split rock
|
||||
if `lNZ2%` == 0 then
|
||||
|
||||
`lN`
|
||||
`10lNZ2/^`
|
||||
`~` # get top and bottom
|
||||
|
||||
`SNSN`
|
||||
`lD1+dSDSD`
|
||||
|
||||
blink()
|
||||
blink()
|
||||
`+`
|
||||
|
||||
end
|
||||
# default case
|
||||
if `lNZ2%` != 0 and `lN` != 0 then
|
||||
|
||||
`lN2024*SN`
|
||||
`lD1+SD`
|
||||
blink()
|
||||
|
||||
end
|
||||
|
||||
`s.`
|
||||
# cacheable
|
||||
if `lN` < 1000000 then
|
||||
array_set('C', `lNlD1000000*+`, `l.`)
|
||||
end
|
||||
|
||||
`LNstLDst` # clear params
|
||||
|
||||
return `l.`
|
||||
|
||||
end
|
||||
|
||||
function read_number
|
||||
read_number_start()
|
||||
read_number_end()
|
||||
end
|
||||
|
||||
function read_number_start
|
||||
|
||||
-1
|
||||
# ret _1 if not a digit
|
||||
return_if(`ln` < 48)
|
||||
return_if(`ln` > 57)
|
||||
`st`
|
||||
|
||||
# throw the true digit onto the stack
|
||||
`ln48-`
|
||||
|
||||
# inc i
|
||||
adjust_index(1)
|
||||
# recurse
|
||||
read_number_start()
|
||||
|
||||
end
|
||||
|
||||
function read_number_end
|
||||
|
||||
# if we only have 1 item on stack (-1) we found no number, so return
|
||||
return_if(1 == `z`)
|
||||
|
||||
# push entire number thing onto temporary stack
|
||||
`[STz0<.]ds.x`
|
||||
# multiply ten then pop and add repeatedly until done
|
||||
`0`
|
||||
`[LTd_1=qr10*+l.x]ds.x`
|
||||
# get rid of the extra -1
|
||||
`st`
|
||||
# decrement i so we reread the skipped char
|
||||
adjust_index(-1)
|
||||
|
||||
end
|
||||
|
||||
123
src/pladcl/2024/day11/part1_works.pdl
Normal file
123
src/pladcl/2024/day11/part1_works.pdl
Normal file
@@ -0,0 +1,123 @@
|
||||
state start
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
|
||||
array_set('X', `lc`, read_number())
|
||||
inc('c')
|
||||
|
||||
end
|
||||
|
||||
interrupt program_start
|
||||
`0sc`
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
|
||||
`0l0`
|
||||
|
||||
for '!' in 0 to 25 do
|
||||
`1000000l0+s1` # update 1 to yknow.
|
||||
#print_array()
|
||||
`l!n[: ]n`
|
||||
blink()
|
||||
`l1s0` # move to current array
|
||||
`ldsc` # update size
|
||||
`lcl0-n10an`
|
||||
end
|
||||
#print_array()
|
||||
`[out: ]n`
|
||||
`lcl0-n`
|
||||
end
|
||||
|
||||
function print_array
|
||||
|
||||
for '?' in `l0` to `lc` do
|
||||
array_get('X', `l?`)
|
||||
`n[ ]n`
|
||||
end
|
||||
`10an`
|
||||
|
||||
end
|
||||
|
||||
|
||||
function blink
|
||||
# c: length of array + offset
|
||||
# 0: offset into this array
|
||||
# 1: offset into next array
|
||||
|
||||
`l1sd` # curr pointer into next array
|
||||
|
||||
for '?' in `l0` to `lc` do
|
||||
|
||||
array_get('X', `l?`)
|
||||
`sn`
|
||||
|
||||
# 0 case -- return 1 rock
|
||||
if `ln` == 0 then
|
||||
|
||||
array_set('X', `ld`, 1)
|
||||
inc('d')
|
||||
|
||||
end
|
||||
# even digit case -- return split rock
|
||||
if `lnZ2%` == 0 then
|
||||
|
||||
`ln`
|
||||
`10lnZ2/^` # calculate middle divide
|
||||
`~` # get top and bottom
|
||||
|
||||
`ld1+:X` # store bottom at next offset of d
|
||||
`ld:X` # store top at d
|
||||
|
||||
`ld2+sd` # double d
|
||||
|
||||
end
|
||||
# default case -- return 2024 * rock
|
||||
if `ln` != 0 and `lnZ2%` != 0 then
|
||||
|
||||
array_set('X', `ld`, `ln2024*`)
|
||||
inc('d')
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function read_number
|
||||
read_number_start()
|
||||
read_number_end()
|
||||
end
|
||||
|
||||
function read_number_start
|
||||
|
||||
-1
|
||||
# ret _1 if not a digit
|
||||
return_if(`ln` < 48)
|
||||
return_if(`ln` > 57)
|
||||
`st`
|
||||
|
||||
# throw the true digit onto the stack
|
||||
`ln48-`
|
||||
|
||||
# inc i
|
||||
adjust_index(1)
|
||||
# recurse
|
||||
read_number_start()
|
||||
|
||||
end
|
||||
|
||||
function read_number_end
|
||||
|
||||
# if we only have 1 item on stack (-1) we found no number, so return
|
||||
return_if(1 == `z`)
|
||||
|
||||
# push entire number thing onto temporary stack
|
||||
`[STz0<.]ds.x`
|
||||
# multiply ten then pop and add repeatedly until done
|
||||
`0`
|
||||
`[LTd_1=qr10*+l.x]ds.x`
|
||||
# get rid of the extra -1
|
||||
`st`
|
||||
# decrement i so we reread the skipped char
|
||||
adjust_index(-1)
|
||||
|
||||
end
|
||||
134
src/pladcl/2024/day11/part2.pdl
Normal file
134
src/pladcl/2024/day11/part2.pdl
Normal file
@@ -0,0 +1,134 @@
|
||||
state start
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
|
||||
read_number()
|
||||
`dnSN`
|
||||
`[ ]n`
|
||||
`0SD`
|
||||
blink()
|
||||
`lo+so`
|
||||
end
|
||||
|
||||
interrupt program_start
|
||||
# C: cache
|
||||
`0sc`
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
`10an`
|
||||
`lop`
|
||||
end
|
||||
|
||||
function print_array
|
||||
|
||||
for '?' in `l0` to `lc` do
|
||||
array_get('X', `l?`)
|
||||
`n[ ]n`
|
||||
end
|
||||
`10an`
|
||||
|
||||
end
|
||||
|
||||
|
||||
function blink
|
||||
# N: number
|
||||
# D: depth
|
||||
|
||||
# if we hit max depth
|
||||
if `lD` == 75 then
|
||||
`LNstLDst`
|
||||
return 1
|
||||
end
|
||||
|
||||
# check cache
|
||||
if `lN` < 1000000 then
|
||||
if array_get('C', `lNlD1000000*+`) > 0 then
|
||||
return array_get('C', `LNLD1000000*+`)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# 0 case -- check 1 rock
|
||||
if `lN` == 0 then
|
||||
|
||||
`1SN`
|
||||
`lD1+SD`
|
||||
blink()
|
||||
|
||||
end
|
||||
# even digit case -- check split rock
|
||||
if `lNZ2%` == 0 then
|
||||
|
||||
`lN`
|
||||
`10lNZ2/^`
|
||||
`~` # get top and bottom
|
||||
|
||||
`SNSN`
|
||||
`lD1+dSDSD`
|
||||
|
||||
blink()
|
||||
blink()
|
||||
`+`
|
||||
|
||||
end
|
||||
# default case
|
||||
if `lNZ2%` != 0 and `lN` != 0 then
|
||||
|
||||
`lN2024*SN`
|
||||
`lD1+SD`
|
||||
blink()
|
||||
|
||||
end
|
||||
|
||||
`s.`
|
||||
# cacheable
|
||||
if `lN` < 1000000 then
|
||||
array_set('C', `lNlD1000000*+`, `l.`)
|
||||
end
|
||||
|
||||
`LNstLDst` # clear params
|
||||
|
||||
return `l.`
|
||||
|
||||
end
|
||||
|
||||
function read_number
|
||||
read_number_start()
|
||||
read_number_end()
|
||||
end
|
||||
|
||||
function read_number_start
|
||||
|
||||
-1
|
||||
# ret _1 if not a digit
|
||||
return_if(`ln` < 48)
|
||||
return_if(`ln` > 57)
|
||||
`st`
|
||||
|
||||
# throw the true digit onto the stack
|
||||
`ln48-`
|
||||
|
||||
# inc i
|
||||
adjust_index(1)
|
||||
# recurse
|
||||
read_number_start()
|
||||
|
||||
end
|
||||
|
||||
function read_number_end
|
||||
|
||||
# if we only have 1 item on stack (-1) we found no number, so return
|
||||
return_if(1 == `z`)
|
||||
|
||||
# push entire number thing onto temporary stack
|
||||
`[STz0<.]ds.x`
|
||||
# multiply ten then pop and add repeatedly until done
|
||||
`0`
|
||||
`[LTd_1=qr10*+l.x]ds.x`
|
||||
# get rid of the extra -1
|
||||
`st`
|
||||
# decrement i so we reread the skipped char
|
||||
adjust_index(-1)
|
||||
|
||||
end
|
||||
84
src/pladcl/2024/day12/part1.pdl
Normal file
84
src/pladcl/2024/day12/part1.pdl
Normal file
@@ -0,0 +1,84 @@
|
||||
state find_width
|
||||
return_if(`ln` != 10)
|
||||
`li1+sw`
|
||||
rewind()
|
||||
set_state(start)
|
||||
`[width got]n10an`
|
||||
end
|
||||
|
||||
state start
|
||||
|
||||
# have got this
|
||||
return_if(array_get('X', `li`) == 1 or `ln` == 10)
|
||||
|
||||
`liSL` # push locatoin
|
||||
`lnsc` # push character
|
||||
flood_fill()
|
||||
#`[region=]nlcan[ perimeter=]nlpn[ area=]nlan10an`
|
||||
|
||||
`lpla*`
|
||||
`lo+so` # add cost into out
|
||||
|
||||
`0sp0sa`
|
||||
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
`lop`
|
||||
end
|
||||
|
||||
|
||||
function flood_fill
|
||||
# c: character
|
||||
# p: perimeter
|
||||
# L: location
|
||||
# a: area
|
||||
|
||||
# X: "checked" thing
|
||||
|
||||
# if this is OOB
|
||||
if `lL` < 0 then
|
||||
`LLst` # kill L
|
||||
inc('p') # add to perimeter
|
||||
return
|
||||
|
||||
end
|
||||
# if this is not the same area
|
||||
if array_get('I', `lL`) != `lc` then
|
||||
|
||||
`LLst` # kill L
|
||||
inc('p') # add to perimeter
|
||||
return
|
||||
|
||||
end
|
||||
# this was already checked
|
||||
if array_get('X', `lL`) == 1then
|
||||
`LLst`
|
||||
return
|
||||
end
|
||||
|
||||
# `[floodfill c=]nlcan[ l=]nlLn10an`
|
||||
|
||||
# this is inbounds and part of the area
|
||||
array_set('X', `lL`, 1)
|
||||
|
||||
# right
|
||||
`lL1+SL`
|
||||
flood_fill()
|
||||
# left
|
||||
`lL1-SL`
|
||||
flood_fill()
|
||||
# down
|
||||
`lLlw+SL`
|
||||
flood_fill()
|
||||
# up
|
||||
`lLlw-SL`
|
||||
flood_fill()
|
||||
|
||||
# add to area
|
||||
inc('a')
|
||||
|
||||
# kill L
|
||||
`LLst`
|
||||
|
||||
end
|
||||
127
src/pladcl/2024/day12/part2.pdl
Normal file
127
src/pladcl/2024/day12/part2.pdl
Normal file
@@ -0,0 +1,127 @@
|
||||
state find_width
|
||||
return_if(`ln` != 10)
|
||||
`li1+sw`
|
||||
rewind()
|
||||
set_state(start)
|
||||
`[width got]n10an`
|
||||
end
|
||||
|
||||
state start
|
||||
|
||||
# have got this
|
||||
return_if(array_get('X', `li`) == 1 or `ln` == 10)
|
||||
|
||||
`liSL` # push locatoin
|
||||
`lnsc` # push character
|
||||
flood_fill()
|
||||
`[region=]nlcan[ perimeter=]nlpn[ area=]nlan10an`
|
||||
|
||||
`lpla*`
|
||||
`lo+so` # add cost into out
|
||||
|
||||
`0sp0sa`
|
||||
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
`lop`
|
||||
end
|
||||
|
||||
|
||||
function flood_fill
|
||||
# c: character
|
||||
# p: perimeter
|
||||
# L: location
|
||||
# a: area
|
||||
|
||||
# X: "checked" thing
|
||||
|
||||
# 1: right
|
||||
# 2: left
|
||||
# 3: down
|
||||
# 4: up
|
||||
|
||||
# if this is OOB
|
||||
if `lL` < 0 then
|
||||
`LLst` # kill L
|
||||
#inc('p') # add to perimeter
|
||||
return 1
|
||||
|
||||
end
|
||||
# if this is not the same area
|
||||
if array_get('I', `lL`) != `lc` then
|
||||
|
||||
`LLst` # kill L
|
||||
#inc('p') # add to perimeter
|
||||
return 1
|
||||
|
||||
end
|
||||
# this was already checked
|
||||
if array_get('X', `lL`) == 1 then
|
||||
`LLst`
|
||||
return 0
|
||||
end
|
||||
|
||||
# `[floodfill c=]nlcan[ l=]nlLn10an`
|
||||
|
||||
# this is inbounds and part of the area
|
||||
array_set('X', `lL`, 1)
|
||||
|
||||
# right
|
||||
`lL1+SL`
|
||||
if flood_fill() == 1 then
|
||||
# check down/downright for same char
|
||||
if array_get('I', `lLlw+`) != `lc` then
|
||||
inc('p')
|
||||
end
|
||||
if array_get('I', `lLlw+`) == `lc` and array_get('I', `lLlw+1+`) == `lc` then
|
||||
inc('p')
|
||||
end
|
||||
end
|
||||
# left
|
||||
`lL1-SL`
|
||||
if flood_fill() == 1 then
|
||||
# check down/downleft for same char
|
||||
if array_get('I', `lLlw+`) != `lc` then
|
||||
inc('p')
|
||||
end
|
||||
if array_get('I', `lLlw+`) == `lc` and array_get('I', `lLlw+1-`) == `lc` then
|
||||
inc('p')
|
||||
end
|
||||
end
|
||||
# down
|
||||
`lLlw+SL`
|
||||
if flood_fill() == 1 then
|
||||
# check right/rightdown for same char
|
||||
if array_get('I', `lL1+`) != `lc` then
|
||||
inc('p')
|
||||
end
|
||||
if array_get('I', `lL1+`) == `lc` and array_get('I', `lLlw+1+`) == `lc` then
|
||||
inc('p')
|
||||
end
|
||||
end
|
||||
# up
|
||||
`lLlw-SL`
|
||||
if flood_fill() == 1 then
|
||||
# check right/rightup for same char
|
||||
if array_get('I', `lL1+`) != `lc` then
|
||||
inc('p')
|
||||
end
|
||||
if `lLlw-1+` > 0 then
|
||||
if array_get('I', `lL1+`) == `lc` and array_get('I', `lLlw-1+`) == `lc` then
|
||||
inc('p')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# add to area
|
||||
inc('a')
|
||||
|
||||
# kill L
|
||||
`LLst`
|
||||
|
||||
0
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user