From 3794ab0b3da12cd1fa53f0bf0c01321c32e02aa0 Mon Sep 17 00:00:00 2001 From: plasmaofthedawn Date: Wed, 11 Dec 2024 15:29:06 +0800 Subject: [PATCH] day 10 pladcl --- resources/2024/day11.txt | 1 + src/pladcl/2024/day10/part1.pdl | 162 ++++++++++++++++++++++++++++++++ src/pladcl/2024/day10/part2.pdl | 162 ++++++++++++++++++++++++++++++++ src/pladcl/2024/day11/part1.pdl | 0 4 files changed, 325 insertions(+) create mode 100644 resources/2024/day11.txt create mode 100644 src/pladcl/2024/day10/part1.pdl create mode 100644 src/pladcl/2024/day10/part2.pdl create mode 100644 src/pladcl/2024/day11/part1.pdl diff --git a/resources/2024/day11.txt b/resources/2024/day11.txt new file mode 100644 index 0000000..00ae344 --- /dev/null +++ b/resources/2024/day11.txt @@ -0,0 +1 @@ +3935565 31753 437818 7697 5 38 0 123 diff --git a/src/pladcl/2024/day10/part1.pdl b/src/pladcl/2024/day10/part1.pdl new file mode 100644 index 0000000..aaf11ee --- /dev/null +++ b/src/pladcl/2024/day10/part1.pdl @@ -0,0 +1,162 @@ +state find_width + return_if(`ln` != 10) + `li1+sw` + rewind() + set_state(start) +end + + +state start + return_if(`ln` != '0') + + `ln48-SN` # number + `liSC` # coords + + find_path() + `dlo+so` + `[path count:]nn10an` + +end + +interrupt program_start + + # X: dynamic programming array + # Y: have entry in above + # Z: current visited + + `0so` + +end + + +interrupt program_end + + `[out:]n10an` + `lop` + +end + + +function find_path + + `[path n=]nlNn[ c=]nlCn10an` + + # out of bounds + if `lC` < 0 then + `LCstLNst` + return 0 + end + + + # circular + if array_get('Z', `lC`) == `li1+` then + `[circle]n10an` + `LCstLNst` # clear params + return 0 + end + + # mark with this index + array_set('Z', `lC`, `li1+`) + + # already found the solution to this problem + # if array_get('Y', `lC`) == 1 then + # `[cached]n10an` + # `LNst` + # return array_get('X', `LC`) + #end + + + # if this is an endpoint + if `lN` == 9 then + # set this entry as 1 + array_set('X', `lC`, 1) + array_set('Y', `LC`, 1) + + `LNst` # pop params + + return 1 + end + + # start sum + 0 + + # store wanted + `lN49+S2` + + # top + + `lClw-S1` # calculate index + # if this is the number we are looking for + if `l1` >= 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + # right + + `lC1+S1` # calculate index + # if this is the number we are looking for + if `l1` > 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + # down + + `lClw+S1` # calculate index + # if this is the number we are looking for + if `l1` >= 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + + # left + + `lC1-S1` # calculate index + # if this is the number we are looking for + if `l1` >= 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + + # remove N and 2 + `LNstL2st` + # mark as cached + array_set('Y', `lC`, 1) + # store sum in X (and return it) + `dLC:X` +end diff --git a/src/pladcl/2024/day10/part2.pdl b/src/pladcl/2024/day10/part2.pdl new file mode 100644 index 0000000..4628951 --- /dev/null +++ b/src/pladcl/2024/day10/part2.pdl @@ -0,0 +1,162 @@ +state find_width + return_if(`ln` != 10) + `li1+sw` + rewind() + set_state(start) +end + + +state start + return_if(`ln` != '0') + + `ln48-SN` # number + `liSC` # coords + + find_path() + `dlo+so` + `[path count:]nn10an` + +end + +interrupt program_start + + # X: dynamic programming array + # Y: have entry in above + # Z: current visited + + `0so` + +end + + +interrupt program_end + + `[out:]n10an` + `lop` + +end + + +function find_path + + `[path n=]nlNn[ c=]nlCn10an` + + # out of bounds + if `lC` < 0 then + `LCstLNst` + return 0 + end + + + # circular + #if array_get('Z', `lC`) == `li1+` then + # `[circle]n10an` + # `LCstLNst` # clear params + # return 0 + #end + + # mark with this index + array_set('Z', `lC`, `li1+`) + + # already found the solution to this problem + if array_get('Y', `lC`) == 1 then + `[cached]n10an` + `LNst` + return array_get('X', `LC`) + end + + + # if this is an endpoint + if `lN` == 9 then + # set this entry as 1 + array_set('X', `lC`, 1) + array_set('Y', `LC`, 1) + + `LNst` # pop params + + return 1 + end + + # start sum + 0 + + # store wanted + `lN49+S2` + + # top + + `lClw-S1` # calculate index + # if this is the number we are looking for + if `l1` >= 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + # right + + `lC1+S1` # calculate index + # if this is the number we are looking for + if `l1` > 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + # down + + `lClw+S1` # calculate index + # if this is the number we are looking for + if `l1` >= 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + + # left + + `lC1-S1` # calculate index + # if this is the number we are looking for + if `l1` >= 0 then + if array_get('I', `l1`) == `l2` then + + `L1SC` # push new coord + `l248-SN` # push new num + + # recurse + find_path() + + `+` + end + end + + + # remove N and 2 + `LNstL2st` + # mark as cached + array_set('Y', `lC`, 1) + # store sum in X (and return it) + `dLC:X` +end diff --git a/src/pladcl/2024/day11/part1.pdl b/src/pladcl/2024/day11/part1.pdl new file mode 100644 index 0000000..e69de29