mirror of
https://git.plasmaofthedawn.com/adventofcode.git
synced 2025-12-23 18:17:35 -06:00
day 13, 14 and 15
This commit is contained in:
147
src/pladcl/2024/day13/part1.pdl
Normal file
147
src/pladcl/2024/day13/part1.pdl
Normal file
@@ -0,0 +1,147 @@
|
||||
state read_a
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sA`
|
||||
set_state(read_b)
|
||||
|
||||
end
|
||||
|
||||
state read_b
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sD`
|
||||
set_state(read_c)
|
||||
|
||||
end
|
||||
|
||||
state read_c
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sB`
|
||||
set_state(read_d)
|
||||
|
||||
end
|
||||
|
||||
state read_d
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sE`
|
||||
set_state(read_e)
|
||||
|
||||
|
||||
end
|
||||
|
||||
state read_e
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sC`
|
||||
set_state(read_f)
|
||||
|
||||
|
||||
end
|
||||
|
||||
state read_f
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sF`
|
||||
|
||||
`[a=]nlAn[ b=]nlBn[ c=]nlCn[ d=]nlDn[ e=]nlEn[ f=]nlFn`
|
||||
`10an`
|
||||
|
||||
# (a, d)
|
||||
# (b, e)
|
||||
# (c, f)
|
||||
|
||||
# (af - cd) / (ae - bd)
|
||||
# num
|
||||
`lAlF*`
|
||||
`lClD*`
|
||||
`-`
|
||||
|
||||
# den
|
||||
`lAlE*`
|
||||
`lBlD*`
|
||||
`-`
|
||||
|
||||
`~s.sY`
|
||||
|
||||
# if no residue
|
||||
if `l.` == 0 then
|
||||
`lClBlY*-lA/sX`
|
||||
`[x = ]nlXn[ y = ]nlYn10an`
|
||||
`lX3*lY+`
|
||||
`lo+so`
|
||||
end
|
||||
if `l.` != 0 then
|
||||
`[no solution]n10an`
|
||||
end
|
||||
|
||||
set_state(read_a)
|
||||
|
||||
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
`lop`
|
||||
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
|
||||
164
src/pladcl/2024/day13/part2.pdl
Normal file
164
src/pladcl/2024/day13/part2.pdl
Normal file
@@ -0,0 +1,164 @@
|
||||
state read_a
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sA`
|
||||
set_state(read_b)
|
||||
|
||||
end
|
||||
|
||||
state read_b
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sD`
|
||||
set_state(read_c)
|
||||
|
||||
end
|
||||
|
||||
state read_c
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sB`
|
||||
set_state(read_d)
|
||||
|
||||
end
|
||||
|
||||
state read_d
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sE`
|
||||
set_state(read_e)
|
||||
|
||||
|
||||
end
|
||||
|
||||
state read_e
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sC`
|
||||
set_state(read_f)
|
||||
|
||||
|
||||
end
|
||||
|
||||
state read_f
|
||||
|
||||
return_if(`ln` < '0' or `ln` > '9')
|
||||
read_number()
|
||||
`sF`
|
||||
|
||||
`lC10000000000000+sC`
|
||||
`lF10000000000000+sF`
|
||||
|
||||
`[a=]nlAn[ b=]nlBn[ c=]nlCn[ d=]nlDn[ e=]nlEn[ f=]nlFn`
|
||||
`10an`
|
||||
|
||||
# (a, d)
|
||||
# (b, e)
|
||||
# (c, f)
|
||||
|
||||
# (af - cd) / (ae - bd)
|
||||
# num
|
||||
`lAlF*`
|
||||
`lClD*`
|
||||
`-`
|
||||
|
||||
# den
|
||||
`lAlE*`
|
||||
`lBlD*`
|
||||
`-`
|
||||
|
||||
`~s.sY`
|
||||
|
||||
`[. = ]nl.n[ ]n`
|
||||
|
||||
if `lY` < 0 and `l.` == 0 then
|
||||
`[fuck!!! ]n`
|
||||
end
|
||||
|
||||
# if no residue
|
||||
if `l.` == 0 then
|
||||
`lClBlY*-lA~s.sX`
|
||||
if `l.` == 0 then
|
||||
`[x = ]nlXn[ y = ]nlYn10an`
|
||||
`lX3*lY+`
|
||||
`lo+so`
|
||||
end
|
||||
if `l.` != 0 then
|
||||
`[no sollution x]n10an`
|
||||
end
|
||||
end
|
||||
if `l.` != 0 then
|
||||
`[no solution]n10an`
|
||||
end
|
||||
|
||||
set_state(read_a)
|
||||
|
||||
end
|
||||
|
||||
interrupt program_start
|
||||
`0k`
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
`lop`
|
||||
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
|
||||
96
src/pladcl/2024/day14/part1.pdl
Normal file
96
src/pladcl/2024/day14/part1.pdl
Normal file
@@ -0,0 +1,96 @@
|
||||
interrupt program_start
|
||||
`101sw`
|
||||
`103sh`
|
||||
|
||||
`lw2/sm` # width middle
|
||||
`lh2/sM` # height middle
|
||||
|
||||
`100s.`
|
||||
|
||||
# 7890 are outputs
|
||||
end
|
||||
|
||||
state read
|
||||
adjust_index(2) # go past p=
|
||||
read_number()
|
||||
`sx` # x position
|
||||
adjust_index(1) # go past ,
|
||||
read_number()
|
||||
`sy`
|
||||
|
||||
adjust_index(3) # go past " v="
|
||||
read_number()
|
||||
`s1` #dx
|
||||
adjust_index(1) # go past ","
|
||||
read_number()
|
||||
`s2`
|
||||
|
||||
#adjust_index(1) # go past newline
|
||||
|
||||
`[x=]nlxn[ y=]nlyn[ 1=]nl1n[ 2=]nl2n10an`
|
||||
|
||||
`lxl1l.*+lw%sx`
|
||||
`lyl2l.*+lh%sy`
|
||||
|
||||
if `lx` < 0 then
|
||||
`lxlw+sx`
|
||||
end
|
||||
if `ly` < 0 then
|
||||
`lylh+sy`
|
||||
end
|
||||
|
||||
`[nx=]nlxn[ ny=]nlyn10an`
|
||||
|
||||
if `lx` < `lm` then
|
||||
if `ly` < `lM` then
|
||||
`[quadrant 1]n10an`
|
||||
`l71+s7`
|
||||
end
|
||||
if `ly` > `lM` then
|
||||
`[quadrant 3]n10an`
|
||||
`l91+s9`
|
||||
end
|
||||
end
|
||||
|
||||
if `lx` > `lm` then
|
||||
if `ly` < `lM` then
|
||||
`[quadrant 2]n10an`
|
||||
`l81+s8`
|
||||
end
|
||||
if `ly` > `lM` then
|
||||
`[quadrant 4]n10an`
|
||||
`l01+s0`
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
|
||||
`[w=]nlwn[ h=]nlhn[ m=]nlmn[ M=]nlMn10an`
|
||||
`[7=]nl7n[ 8=]nl8n[ 9=]nl9n[ 0=]nl0n10an`
|
||||
`l7l8l9l0***p`
|
||||
|
||||
end
|
||||
|
||||
function read_number
|
||||
# does no error checking
|
||||
`1` # sign
|
||||
if `ln` == '-' then
|
||||
`2-` # negative
|
||||
adjust_index(1)
|
||||
end
|
||||
|
||||
`0` # c num
|
||||
while `ln` >= '0' and `ln` <= '9' do
|
||||
|
||||
`10*`
|
||||
`ln48-+` # add in number
|
||||
adjust_index(1)
|
||||
|
||||
end
|
||||
|
||||
#adjust_index(-1)
|
||||
|
||||
`*`
|
||||
|
||||
end
|
||||
192
src/pladcl/2024/day14/part2.pdl
Normal file
192
src/pladcl/2024/day14/part2.pdl
Normal file
@@ -0,0 +1,192 @@
|
||||
interrupt program_start
|
||||
`101sw`
|
||||
`103sh`
|
||||
|
||||
`0s.` # num
|
||||
`0sc` # count
|
||||
|
||||
# X: x array
|
||||
# Y: y array
|
||||
`0sm` #x mean
|
||||
`0sM` #y mean
|
||||
|
||||
`0sv` # x variance
|
||||
`0sV` # y variance
|
||||
|
||||
`10 10^s(` # min x variance
|
||||
`10 10^s)` # min y variance
|
||||
|
||||
`0s{` # min x loc
|
||||
`0s}` # min y loc
|
||||
|
||||
`0sF` # finished flag
|
||||
|
||||
# A: posx
|
||||
# B: posy
|
||||
# C: velx
|
||||
# D: vely
|
||||
|
||||
end
|
||||
|
||||
state read
|
||||
|
||||
adjust_index(2) # go past p=
|
||||
read_number()
|
||||
`lc:A` # x position
|
||||
adjust_index(1) # go past ,
|
||||
read_number()
|
||||
`lc:B`
|
||||
|
||||
adjust_index(3) # go past " v="
|
||||
read_number()
|
||||
`lc:C` #dx
|
||||
adjust_index(1) # go past ","
|
||||
read_number()
|
||||
`lc:D`
|
||||
|
||||
inc('c')
|
||||
|
||||
#adjust_index(1) # go past newline
|
||||
end
|
||||
|
||||
|
||||
interrupt program_end
|
||||
|
||||
`[finished reading]n10an`
|
||||
#`[x=]nlxn[ y=]nlyn[ 1=]nl1n[ 2=]nl2n10an`
|
||||
|
||||
# calculate variances
|
||||
for '.' in 0 to 103 do
|
||||
calculate_variance()
|
||||
end
|
||||
|
||||
`[lowest x var at ]nl{n[, lowest y var at ]nl}n10an`
|
||||
|
||||
while `l{` != `l}` do
|
||||
`l{101+s{` # inc x by 101
|
||||
|
||||
if `l}` < `l{` then
|
||||
`l}103+s}` # inc y by 103 if it's smaller
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
`[calculated first tree at ]nl}n[, printing...]n`
|
||||
`l}s.`
|
||||
calculate_positions()
|
||||
|
||||
for '!' in 0 to `lhlw*` do
|
||||
if `l!lw%` == 0 then
|
||||
`10an`
|
||||
end
|
||||
if `l!;Z` == 0 then
|
||||
`[ ]n`
|
||||
end
|
||||
if `l!;Z` != 0 then
|
||||
`[#]n`
|
||||
end
|
||||
end
|
||||
|
||||
`10an[ at ]nl.n10an`
|
||||
|
||||
end
|
||||
|
||||
|
||||
function calculate_variance
|
||||
|
||||
# find positions
|
||||
for '!' in 0 to `lc` do
|
||||
|
||||
`l!;Al!;Cl.*+lw%sx`
|
||||
`l!;Bl!;Dl.*+lh%sy`
|
||||
|
||||
if `lx` < 0 then
|
||||
`lxlw+sx`
|
||||
end
|
||||
if `ly` < 0 then
|
||||
`lylh+sy`
|
||||
end
|
||||
|
||||
# store these
|
||||
`lxl!:X`
|
||||
`lyl!:Y`
|
||||
|
||||
`lmlx+sm`
|
||||
`lMly+sM`
|
||||
|
||||
end
|
||||
|
||||
|
||||
# x and y variance calculation
|
||||
`0sv`
|
||||
`0sV`
|
||||
|
||||
`lmlc/sm`
|
||||
`lMlc/sM`
|
||||
|
||||
for '!' in 0 to `lc` do
|
||||
`lvl!;Xlm-2^+sv`
|
||||
`lVl!;Ylm-2^+sV`
|
||||
end
|
||||
|
||||
if `lv` < `l(` then
|
||||
`lvs(`
|
||||
`l.s{`
|
||||
end
|
||||
if `lV` < `l)` then
|
||||
`lVs)`
|
||||
`l.s}`
|
||||
end
|
||||
|
||||
|
||||
`[.=]nl.n[ v=]nlvn[ V=]nlVn10an`
|
||||
|
||||
end
|
||||
|
||||
function calculate_positions
|
||||
|
||||
# find positions
|
||||
for '!' in 0 to `lc` do
|
||||
|
||||
`l!;Al!;Cl.*+lw%sx`
|
||||
`l!;Bl!;Dl.*+lh%sy`
|
||||
|
||||
if `lx` < 0 then
|
||||
`lxlw+sx`
|
||||
end
|
||||
if `ly` < 0 then
|
||||
`lylh+sy`
|
||||
end
|
||||
|
||||
`1`
|
||||
# index of this
|
||||
`lylw*lx+`
|
||||
`:Z` # store in Z
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function read_number
|
||||
# does no error checking
|
||||
`1` # sign
|
||||
if `ln` == '-' then
|
||||
`2-` # negative
|
||||
adjust_index(1)
|
||||
end
|
||||
|
||||
`0` # c num
|
||||
while `ln` >= '0' and `ln` <= '9' do
|
||||
|
||||
`10*`
|
||||
`ln48-+` # add in number
|
||||
adjust_index(1)
|
||||
|
||||
end
|
||||
|
||||
#adjust_index(-1)
|
||||
|
||||
`*`
|
||||
|
||||
end
|
||||
112
src/pladcl/2024/day14/part2_works.pdl
Normal file
112
src/pladcl/2024/day14/part2_works.pdl
Normal file
@@ -0,0 +1,112 @@
|
||||
interrupt program_start
|
||||
`101sw`
|
||||
`103sh`
|
||||
|
||||
`lw2/sm` # width middle
|
||||
`lh2/sM` # height middle
|
||||
|
||||
# found through excel
|
||||
`8006s.`
|
||||
|
||||
# robots bunch up horizontally every 103s
|
||||
# offset of 27
|
||||
# robots bunch up vertically every 101s
|
||||
# offset of 75
|
||||
|
||||
|
||||
|
||||
# 7890 are outputs
|
||||
end
|
||||
|
||||
state read
|
||||
|
||||
adjust_index(2) # go past p=
|
||||
read_number()
|
||||
`sx` # x position
|
||||
adjust_index(1) # go past ,
|
||||
read_number()
|
||||
`sy`
|
||||
|
||||
adjust_index(3) # go past " v="
|
||||
read_number()
|
||||
`s1` #dx
|
||||
adjust_index(1) # go past ","
|
||||
read_number()
|
||||
`s2`
|
||||
|
||||
#adjust_index(1) # go past newline
|
||||
|
||||
#`[x=]nlxn[ y=]nlyn[ 1=]nl1n[ 2=]nl2n10an`
|
||||
|
||||
`lxl1l.*+lw%sx`
|
||||
`lyl2l.*+lh%sy`
|
||||
|
||||
if `lx` < 0 then
|
||||
`lxlw+sx`
|
||||
end
|
||||
if `ly` < 0 then
|
||||
`lylh+sy`
|
||||
end
|
||||
|
||||
#`[nx=]nlxn[ ny=]nlyn10an`
|
||||
|
||||
`1`
|
||||
# index of this
|
||||
`lylw*lx+`
|
||||
`:X` # store in X
|
||||
|
||||
if `li1+;I` == -1 then
|
||||
`[---------------------------------------------------------------------------------------]n10an`
|
||||
`[. = ]nl.n`
|
||||
|
||||
for '!' in 0 to `lhlw*` do
|
||||
if `l!lw%` == 0 then
|
||||
`10an`
|
||||
end
|
||||
if `l!;X` == 0 then
|
||||
`[ ]n`
|
||||
end
|
||||
if `l!;X` != 0 then
|
||||
`[#]n`
|
||||
end
|
||||
`0l!:X` # clear
|
||||
end
|
||||
|
||||
rewind()
|
||||
`l.103+s.`
|
||||
`10an`
|
||||
`10an` # for less
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
interrupt program_end
|
||||
|
||||
`[w=]nlwn[ h=]nlhn[ m=]nlmn[ M=]nlMn10an`
|
||||
`[7=]nl7n[ 8=]nl8n[ 9=]nl9n[ 0=]nl0n10an`
|
||||
`l7l8l9l0***p`
|
||||
|
||||
end
|
||||
|
||||
function read_number
|
||||
# does no error checking
|
||||
`1` # sign
|
||||
if `ln` == '-' then
|
||||
`2-` # negative
|
||||
adjust_index(1)
|
||||
end
|
||||
|
||||
`0` # c num
|
||||
while `ln` >= '0' and `ln` <= '9' do
|
||||
|
||||
`10*`
|
||||
`ln48-+` # add in number
|
||||
adjust_index(1)
|
||||
|
||||
end
|
||||
|
||||
#adjust_index(-1)
|
||||
|
||||
`*`
|
||||
|
||||
end
|
||||
181
src/pladcl/2024/day14/part2_works2.pdl
Normal file
181
src/pladcl/2024/day14/part2_works2.pdl
Normal file
@@ -0,0 +1,181 @@
|
||||
interrupt program_start
|
||||
`101sw`
|
||||
`103sh`
|
||||
|
||||
`0s.` # num
|
||||
`0sc` # count
|
||||
|
||||
# X: x array
|
||||
# Y: y array
|
||||
`0sm` #x mean
|
||||
`0sM` #y mean
|
||||
|
||||
`0sv` # x variance
|
||||
`0sV` # y variance
|
||||
|
||||
`10 10^s(` # min x variance
|
||||
`10 10^s)` # min y variance
|
||||
|
||||
`0s{` # min x loc
|
||||
`0s}` # min y loc
|
||||
|
||||
`0sF` # finished flag
|
||||
|
||||
# A: posx
|
||||
# B: posy
|
||||
# C: velx
|
||||
# D: vely
|
||||
|
||||
end
|
||||
|
||||
state read
|
||||
|
||||
adjust_index(2) # go past p=
|
||||
read_number()
|
||||
`sx` # x position
|
||||
adjust_index(1) # go past ,
|
||||
read_number()
|
||||
`sy`
|
||||
|
||||
adjust_index(3) # go past " v="
|
||||
read_number()
|
||||
`s1` #dx
|
||||
adjust_index(1) # go past ","
|
||||
read_number()
|
||||
`s2`
|
||||
|
||||
#adjust_index(1) # go past newline
|
||||
|
||||
#`[x=]nlxn[ y=]nlyn[ 1=]nl1n[ 2=]nl2n10an`
|
||||
|
||||
`lxl1l.*+lw%sx`
|
||||
`lyl2l.*+lh%sy`
|
||||
|
||||
if `lx` < 0 then
|
||||
`lxlw+sx`
|
||||
end
|
||||
if `ly` < 0 then
|
||||
`lylh+sy`
|
||||
end
|
||||
|
||||
#`[nx=]nlxn[ ny=]nlyn10an`
|
||||
|
||||
|
||||
# store these
|
||||
`lxlc:X`
|
||||
`lylc:Y`
|
||||
inc('c')
|
||||
|
||||
`lmlx+sm`
|
||||
`lMly+sM`
|
||||
|
||||
# if done put it in an array for printing
|
||||
if `lF` == 1 then
|
||||
`1`
|
||||
# index of this
|
||||
`lylw*lx+`
|
||||
`:Z` # store in Z
|
||||
end
|
||||
|
||||
if `li1+;I` == -1 then
|
||||
|
||||
#`[.]n`
|
||||
|
||||
# print tree when done
|
||||
if `lF` == 1 then
|
||||
for '!' in 0 to `lhlw*` do
|
||||
if `l!lw%` == 0 then
|
||||
`10an`
|
||||
end
|
||||
if `l!;Z` == 0 then
|
||||
`[ ]n`
|
||||
end
|
||||
if `l!;Z` != 0 then
|
||||
`[#]n`
|
||||
end
|
||||
end
|
||||
|
||||
`10an[ at ]nl.n10an`
|
||||
return
|
||||
end
|
||||
|
||||
# if we're done here
|
||||
if `l.` == 103 then
|
||||
|
||||
`[lowest x var at ]nl{n[, lowest y var at ]nl}n10an`
|
||||
|
||||
while `l{` != `l}` do
|
||||
`l{101+s{` # inc x by 101
|
||||
|
||||
if `l}` < `l{` then
|
||||
`l}103+s}` # inc y by 103 if it's smaller
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
`[calculated first tree at ]nl}n[, printing...]n`
|
||||
|
||||
`l}s.`
|
||||
rewind()
|
||||
`1sF`
|
||||
end
|
||||
|
||||
if `lF` != 1 then
|
||||
|
||||
# x and y variance
|
||||
`0sv`
|
||||
`0sV`
|
||||
|
||||
`lmlc/sm`
|
||||
`lMlc/sM`
|
||||
|
||||
for '!' in 0 to `lc` do
|
||||
`lvl!;Xlm-2^+sv`
|
||||
`lVl!;Ylm-2^+sV`
|
||||
end
|
||||
|
||||
if `lv` < `l(` then
|
||||
`lvs(`
|
||||
`l.s{`
|
||||
end
|
||||
if `lV` < `l)` then
|
||||
`lVs)`
|
||||
`l.s}`
|
||||
end
|
||||
|
||||
|
||||
`[.=]nl.n[ v=]nlvn[ V=]nlVn10an`
|
||||
|
||||
`0sm`
|
||||
`0sM`
|
||||
`0sc`
|
||||
rewind()
|
||||
inc('.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function read_number
|
||||
# does no error checking
|
||||
`1` # sign
|
||||
if `ln` == '-' then
|
||||
`2-` # negative
|
||||
adjust_index(1)
|
||||
end
|
||||
|
||||
`0` # c num
|
||||
while `ln` >= '0' and `ln` <= '9' do
|
||||
|
||||
`10*`
|
||||
`ln48-+` # add in number
|
||||
adjust_index(1)
|
||||
|
||||
end
|
||||
|
||||
#adjust_index(-1)
|
||||
|
||||
`*`
|
||||
|
||||
end
|
||||
140
src/pladcl/2024/day15/part1.pdl
Normal file
140
src/pladcl/2024/day15/part1.pdl
Normal file
@@ -0,0 +1,140 @@
|
||||
state read_map
|
||||
if `ln` == '@' then
|
||||
`lisp`
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
state read_instructions
|
||||
`lnan`
|
||||
|
||||
if `ln` == '<' then
|
||||
-1
|
||||
end
|
||||
if `ln` == '^' then
|
||||
`0lw-`
|
||||
end
|
||||
if `ln` == '>' then
|
||||
1
|
||||
end
|
||||
if `ln` == 'v' then
|
||||
`lw`
|
||||
end
|
||||
if `ln` == 10 then
|
||||
return
|
||||
end
|
||||
|
||||
move()
|
||||
|
||||
#print_board()
|
||||
|
||||
end
|
||||
|
||||
interrupt newline
|
||||
|
||||
if `lw` == 0 then
|
||||
`li1+sw`
|
||||
end
|
||||
|
||||
if `li1+;I` == 10 then
|
||||
`li1+lw/sh`
|
||||
|
||||
`[board is ]nlw1-n[x]nlhn10an`
|
||||
`lplw~`
|
||||
`[robot is at (]nn[,]nn[)]n10an`
|
||||
|
||||
adjust_index(2)
|
||||
|
||||
set_state(read_instructions)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
|
||||
`st`
|
||||
|
||||
`[finished]n10an`
|
||||
|
||||
0
|
||||
for '!' in 0 to `lwlh*` do
|
||||
|
||||
if `l!;I` == 'O' then
|
||||
`l!lw~`
|
||||
`[box is at (]nn[,]nn[)]n10an`
|
||||
`l!lw~`
|
||||
`r100*++`
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function print_board
|
||||
|
||||
for '!' in 0 to `lwlh*` do
|
||||
|
||||
`l!;Ian`
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
function move
|
||||
|
||||
`sv`
|
||||
`lpSP`
|
||||
if _move() == 1 then
|
||||
|
||||
'.'
|
||||
`lp:I`
|
||||
|
||||
'@'
|
||||
`lplv+dsp:I`
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function _move
|
||||
# v is vector of movement
|
||||
# P is current position of push
|
||||
|
||||
# returns 1 if can move/push
|
||||
|
||||
# empty space -- can push
|
||||
if `lPlv+;I` == '.' then
|
||||
`LPst`
|
||||
return 1
|
||||
end
|
||||
|
||||
# wall -- can't push
|
||||
if `lPlv+;I` == '#' then
|
||||
`LPst`
|
||||
return 0
|
||||
end
|
||||
|
||||
# box, need to check further
|
||||
if `lPlv+;I` == 'O' then
|
||||
`lPlv+SP` # add new position to stack
|
||||
|
||||
# if we can move
|
||||
if _move() == 1 then
|
||||
# set the next spot to be an O
|
||||
'O'
|
||||
`LPlvd++:I`
|
||||
return 1
|
||||
|
||||
end
|
||||
|
||||
`LPst`
|
||||
return 0
|
||||
|
||||
end
|
||||
|
||||
`[unknown symbol type: ]nlPlv+;Ian10an`
|
||||
end
|
||||
|
||||
382
src/pladcl/2024/day15/part2.pdl
Normal file
382
src/pladcl/2024/day15/part2.pdl
Normal file
@@ -0,0 +1,382 @@
|
||||
interrupt program_start
|
||||
`0sc`
|
||||
end
|
||||
|
||||
state read_map
|
||||
if `ln` == '@' then
|
||||
'@'
|
||||
`lc:X`
|
||||
`lcsp`
|
||||
inc('c')
|
||||
'.'
|
||||
`lc:X`
|
||||
inc('c')
|
||||
end
|
||||
|
||||
if `ln` == '#' then
|
||||
'#'
|
||||
`lc:X`
|
||||
inc('c')
|
||||
'#'
|
||||
`lc:X`
|
||||
inc('c')
|
||||
end
|
||||
|
||||
if `ln` == '.' then
|
||||
'.'
|
||||
`lc:X`
|
||||
inc('c')
|
||||
'.'
|
||||
`lc:X`
|
||||
inc('c')
|
||||
end
|
||||
|
||||
if `ln` == 'O' then
|
||||
'['
|
||||
`lc:X`
|
||||
inc('c')
|
||||
']'
|
||||
`lc:X`
|
||||
inc('c')
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
state read_instructions
|
||||
`lnan`
|
||||
|
||||
if `ln` == '<' then
|
||||
-1
|
||||
end
|
||||
if `ln` == '^' then
|
||||
`0lw-`
|
||||
end
|
||||
if `ln` == '>' then
|
||||
1
|
||||
end
|
||||
if `ln` == 'v' then
|
||||
`lw`
|
||||
end
|
||||
if `ln` == 10 then
|
||||
return
|
||||
end
|
||||
|
||||
move()
|
||||
|
||||
#print_board()
|
||||
|
||||
end
|
||||
|
||||
interrupt newline
|
||||
|
||||
if `lw` == 0 then
|
||||
`lisw`
|
||||
end
|
||||
|
||||
if `li1+;I` == 10 then
|
||||
`lilw/sh`
|
||||
`lw2*sw`
|
||||
|
||||
`[board is ]nlw1-n[x]nlhn10an`
|
||||
`lplw~`
|
||||
`[robot is at (]nn[,]nn[)]n`
|
||||
|
||||
adjust_index(2)
|
||||
|
||||
set_state(read_instructions)
|
||||
|
||||
print_board()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
interrupt program_end
|
||||
|
||||
`st`
|
||||
|
||||
`[finished]n10an`
|
||||
|
||||
0
|
||||
for '!' in 0 to `lc` do
|
||||
|
||||
if `l!;X` == '[' then
|
||||
`l!lw~`
|
||||
`[box is at (]nn[,]nn[)]n10an`
|
||||
`l!lw~`
|
||||
`r100*++`
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
`p`
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function print_board
|
||||
|
||||
for '!' in 0 to `lc` do
|
||||
|
||||
if `l!lw%` == 0 then
|
||||
`10an`
|
||||
end
|
||||
|
||||
`l!;Xan`
|
||||
|
||||
end
|
||||
|
||||
`10an`
|
||||
|
||||
end
|
||||
|
||||
|
||||
function move
|
||||
|
||||
`sv`
|
||||
`lpSP`
|
||||
|
||||
`[`
|
||||
_move()
|
||||
`10an]x` #????
|
||||
|
||||
`[wow]nps.`
|
||||
if `l.` == 1 then
|
||||
|
||||
`[moved]n`
|
||||
|
||||
'.'
|
||||
`lp:X`
|
||||
|
||||
'@'
|
||||
`lplv+dsp:X`
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function _move
|
||||
# v is vector of movement
|
||||
# P is current position of push
|
||||
|
||||
# returns 1 if can move/push
|
||||
|
||||
# empty space -- can push
|
||||
if `lPlv+;X` == '.' then
|
||||
`LPst`
|
||||
return 1
|
||||
end
|
||||
|
||||
# wall -- can't push
|
||||
if `lPlv+;X` == '#' then
|
||||
`LPst`
|
||||
return 0
|
||||
end
|
||||
|
||||
# box left, need to check further
|
||||
if `lPlv+;X` == '[' then
|
||||
|
||||
# rightwards push
|
||||
if `lv` == 1 then
|
||||
|
||||
`lP2+SP` # add point to the right
|
||||
|
||||
# if we can move
|
||||
if _move() == 1 then
|
||||
|
||||
# move this box
|
||||
']'
|
||||
`lP3+:X`
|
||||
'['
|
||||
`LP2+:X`
|
||||
|
||||
return 1
|
||||
|
||||
end
|
||||
|
||||
return 0
|
||||
|
||||
end
|
||||
|
||||
# up/down push
|
||||
if `lv` != 1 then
|
||||
|
||||
`lPlv+SP` # add point to the up/down
|
||||
# check if we can move
|
||||
|
||||
if updown_check() == 1 then
|
||||
|
||||
`LPlv+SP` # move
|
||||
updown_move()
|
||||
|
||||
return 1
|
||||
|
||||
end
|
||||
|
||||
`[done]n`
|
||||
|
||||
`LPst`
|
||||
|
||||
return 0
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# box right, need to check further
|
||||
if `lPlv+;X` == ']' then
|
||||
# leftwards push
|
||||
if `lv` == -1 then
|
||||
|
||||
`lP2-SP` # add point to the two left
|
||||
|
||||
# if we can move
|
||||
if _move() == 1 then
|
||||
|
||||
# move this box
|
||||
'['
|
||||
`lP3-:X`
|
||||
']'
|
||||
`LP2-:X`
|
||||
|
||||
return 1
|
||||
|
||||
end
|
||||
|
||||
return 0
|
||||
|
||||
end
|
||||
|
||||
# up/down push
|
||||
if `lv` != -1 then
|
||||
|
||||
`lPlv+SP` # add point to the up/down
|
||||
# check if we can move
|
||||
if updown_check() == 1 then
|
||||
|
||||
`LPlv+SP` # move
|
||||
updown_move()
|
||||
|
||||
return 1
|
||||
|
||||
end
|
||||
|
||||
`LPst`
|
||||
|
||||
return 0
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
0
|
||||
`[unknown symbol type: ]nlPlv+;Xan10an`
|
||||
end
|
||||
|
||||
# takes position in P
|
||||
# also vector (assmed to be up or down) in v
|
||||
function updown_check
|
||||
|
||||
`[updown_check p=]nlPn[ ]nlP;Xan10an`
|
||||
|
||||
if `lP;X` == '.' then
|
||||
`LPst`
|
||||
return 1
|
||||
end
|
||||
|
||||
if `lP;X` == '#' then
|
||||
`LPst`
|
||||
return 0
|
||||
end
|
||||
|
||||
if `lP;X` == ']' then
|
||||
`LPlv+d`
|
||||
`SP` # store one directly above
|
||||
`1-SP` # and one directly to the left
|
||||
|
||||
if updown_check() == 1 then
|
||||
if updown_check() == 1 then
|
||||
|
||||
`[}1]n`
|
||||
return 1
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
`[}0]n`
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
if `lP;X` == '[' then
|
||||
`LPlv+d`
|
||||
`SP` # store one directly above
|
||||
`1+SP` # and one directly to the right
|
||||
|
||||
if updown_check() == 1 then
|
||||
if updown_check() == 1 then
|
||||
`[{1]n`
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
`[{0]n`
|
||||
return 0
|
||||
end
|
||||
|
||||
0
|
||||
|
||||
end
|
||||
|
||||
|
||||
# takes position above/below [ in P
|
||||
function updown_move
|
||||
|
||||
`[updown_move p=]nlPn[ ]nlP;Xan10an`
|
||||
|
||||
if `lP;X` == '.' then
|
||||
`LPst`
|
||||
return
|
||||
end
|
||||
|
||||
if `lP;X` == '#' then
|
||||
`LPst`
|
||||
`[updown move on invalid thing. fuck.]n10an`
|
||||
return
|
||||
end
|
||||
|
||||
if `lP;X` == '[' then
|
||||
`lPlv+ds11+s2` # 1 = above directly, 2 = abo
|
||||
|
||||
'.'
|
||||
`lP:X`
|
||||
'.' # and remove traces
|
||||
`lP1+:X`
|
||||
|
||||
`l1SP` # store one directly above '['
|
||||
`l2SP` # store two directly above ']'
|
||||
updown_move()
|
||||
updown_move()
|
||||
|
||||
`LPlv+ds11+s2` # 1 = above directly, 2 = abo
|
||||
'['
|
||||
`l1:X` # put this here
|
||||
']'
|
||||
`l2:X` # and this here
|
||||
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
if `lP;X` == ']' then
|
||||
`LP1-SP`
|
||||
updown_move()
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
25
src/python/2024/day13/part2.py
Normal file
25
src/python/2024/day13/part2.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import re
|
||||
a = open("temp").read().split("\n\n")[:-1]
|
||||
#a = open("resources/2024/day13.txt").readlines()
|
||||
|
||||
def solve(a, b, c, d, e, f):
|
||||
y = ((a * f) - (c * d))/(a * e - b * d)
|
||||
x = (c - b * y) / a
|
||||
return (x, y)
|
||||
|
||||
|
||||
|
||||
for i in a:
|
||||
ba, bb, bp = i.split("\n")
|
||||
|
||||
a, d = [int(re.sub(r'\D+', '', x)) for x in ba.split(", ")]
|
||||
b, e = [int(re.sub(r'\D+', '', x)) for x in bb.split(", ")]
|
||||
c, f = [int(re.sub(r'\D+', '', x)) for x in bp.split(", ")]
|
||||
|
||||
x_s, y_s = solve(a, b, c, d, e, f)
|
||||
x_10000, y_10000 = solve(a, b, 10000, d, e, 10000)
|
||||
|
||||
print(a, b, c, d, e, f)
|
||||
print(x_s + x_10000 * 1000000000, y_s + y_10000 * 1000000000)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user