day9 done

This commit is contained in:
m
2025-12-12 08:48:22 -05:00
parent 7392e6d7ef
commit 4a44b1c136
6 changed files with 1183 additions and 0 deletions

496
src/plasl/2025/day9/input Normal file
View File

@@ -0,0 +1,496 @@
98139,50134
98139,51344
97752,51344
97752,52552
97690,52552
97690,53768
97716,53768
97716,55028
98110,55028
98110,56140
97156,56140
97156,57477
97912,57477
97912,58631
97393,58631
97393,59810
97068,59810
97068,60999
96805,60999
96805,62191
96547,62191
96547,63241
95790,63241
95790,64439
95574,64439
95574,65656
95388,65656
95388,66774
94904,66774
94904,67836
94290,67836
94290,69244
94501,69244
94501,70268
93788,70268
93788,71148
92809,71148
92809,72346
92489,72346
92489,73328
91753,73328
91753,74320
91051,74320
91051,75306
90348,75306
90348,76613
90136,76613
90136,77644
89480,77644
89480,78337
88364,78337
88364,79295
87628,79295
87628,80165
86784,80165
86784,81228
86171,81228
86171,82441
85705,82441
85705,83098
84624,83098
84624,84064
83873,84064
83873,84825
82918,84825
82918,85335
81744,85335
81744,86744
81365,86744
81365,86949
79956,86949
79956,88350
79514,88350
79514,88946
78431,88946
78431,89218
77134,89218
77134,90171
76314,90171
76314,91035
75418,91035
75418,91538
74296,91538
74296,91669
72975,91669
72975,92779
72193,92779
72193,92918
70903,92918
70903,93286
69742,93286
69742,93717
68615,93717
68615,94951
67809,94951
67809,95446
66686,95446
66686,95710
65481,95710
65481,95839
64241,95839
64241,95966
63013,95966
63013,96113
61801,96113
61801,97201
60813,97201
60813,96716
59464,96716
59464,97458
58368,97458
58368,97772
57181,97772
57181,97368
55897,97368
55897,97883
54733,97883
54733,97638
53493,97638
53493,97722
52286,97722
52286,98001
51081,98001
51081,97675
49866,97675
49866,97707
48657,97707
48657,98136
47423,98136
47423,97634
46238,97634
46238,98098
44972,98098
44972,97622
43799,97622
43799,97855
42531,97855
42531,97299
41385,97299
41385,96972
40209,96972
40209,96335
39110,96335
39110,96563
37804,96563
37804,95651
36799,95651
36799,95762
35501,95762
35501,94989
34481,94989
34481,95417
33034,95417
33034,94438
32104,94438
32104,93632
31130,93632
31130,93574
29830,93574
29830,93411
28554,93411
28554,92731
27526,92731
27526,91888
26595,91888
26595,91570
25371,91570
25371,90514
24589,90514
24589,89701
23674,89701
23674,89384
22423,89384
22423,88761
21369,88761
21369,87707
20642,87707
20642,87225
19472,87225
19472,85980
18936,85980
18936,85790
17482,85790
17482,84618
16907,84618
16907,83563
16247,83563
16247,82768
15333,82768
15333,82271
14078,82271
14078,80864
13842,80864
13842,80408
12492,80408
12492,79557
11593,79557
11593,78479
10986,78479
10986,77474
10289,77474
10289,76312
9830,76312
9830,75465
8887,75465
8887,74377
8322,74377
8322,73361
7631,73361
7631,71962
7666,71962
7666,71126
6622,71126
6622,70096
5936,70096
5936,68996
5389,68996
5389,67683
5367,67683
5367,66513
5025,66513
5025,65515
4188,65515
4188,64224
4215,64224
4215,63167
3489,63167
3489,61910
3462,61910
3462,60708
3257,60708
3257,59625
2484,59625
2484,58265
3125,58265
3125,57194
2142,57194
2142,55886
2721,55886
2721,54690
2552,54690
2552,53529
1870,53529
1870,52300
1984,52300
1984,51075
2287,51075
2287,50126
94997,50126
94997,48641
1738,48641
1738,47438
2142,47438
2142,46228
2242,46228
2242,45035
2503,45035
2503,43802
2400,43802
2400,42582
2469,42582
2469,41477
3203,41477
3203,40123
2614,40123
2614,39130
3748,39130
3748,37771
3311,37771
3311,36688
3965,36688
3965,35618
4607,35618
4607,34321
4547,34321
4547,33197
5019,33197
5019,31962
5208,31962
5208,31031
6138,31031
6138,29690
6123,29690
6123,28824
7136,28824
7136,27785
7761,27785
7761,26487
7917,26487
7917,25366
8421,25366
8421,24655
9592,24655
9592,23544
10102,23544
10102,22385
10560,22385
10560,21358
11223,21358
11223,20681
12341,20681
12341,19804
13179,19804
13179,18387
13383,18387
13383,17846
14610,17846
14610,16742
15209,16742
15209,16240
16429,16240
16429,14832
16758,14832
16758,14652
18243,14652
18243,13592
18921,13592
18921,13025
20023,13025
20023,11804
20605,11804
20605,11323
21765,11323
21765,10506
22675,10506
22675,10187
23921,10187
23921,9541
24939,9541
24939,8539
25750,8539
25750,7925
26800,7925
26800,7268
27831,7268
27831,7118
29114,7118
29114,6182
30015,6182
30015,5471
31038,5471
31038,5830
32500,5830
32500,5118
33520,5118
33520,4516
34595,4516
34595,3842
35659,3842
35659,3852
36935,3852
36935,3660
38140,3660
38140,3437
39332,3437
39332,2972
40472,2972
40472,2852
41686,2852
41686,2524
42863,2524
42863,2771
44119,2771
44119,2721
45326,2721
45326,2485
46515,2485
46515,2257
47712,2257
47712,2068
48919,2068
48919,2423
50133,2423
50133,2070
51349,2070
51349,2501
52542,2501
52542,1823
53804,1823
53804,2662
54947,2662
54947,2141
56231,2141
56231,2160
57466,2160
57466,2742
58606,2742
58606,3176
59759,3176
59759,3160
61007,3160
61007,3713
62122,3713
62122,3596
63418,3596
63418,4576
64391,4576
64391,4917
65550,4917
65550,5332
66685,5332
66685,5802
67798,5802
67798,5698
69158,5698
69158,5988
70371,5988
70371,7040
71222,7040
71222,7085
72570,7085
72570,8251
73325,8251
73325,8772
74424,8772
74424,9591
75344,9591
75344,10037
76498,10037
76498,10972
77326,10972
77326,11171
78680,11171
78680,12095
79510,12095
79510,12791
80513,12791
80513,13793
81258,13793
81258,14467
82284,14467
82284,15132
83330,15132
83330,16459
83729,16459
83729,17146
84756,17146
84756,17950
85674,17950
85674,18854
86486,18854
86486,19790
87261,19790
87261,20559
88254,20559
88254,21754
88691,21754
88691,22539
89690,22539
89690,23885
89867,23885
89867,24583
91032,24583
91032,25801
91371,25801
91371,27020
91675,27020
91675,27977
92449,27977
92449,29020
93074,29020
93074,30116
93597,30116
93597,31248
94036,31248
94036,32343
94564,32343
94564,33526
94865,33526
94865,34739
95057,34739
95057,35811
95668,35811
95668,37049
95744,37049
95744,38096
96509,38096
96509,39350
96482,39350
96482,40433
97222,40433
97222,41595
97659,41595
97659,42878
97375,42878
97375,44100
97379,44100
97379,45229
98259,45229
98259,46460
98267,46460
98267,47709
97813,47709
97813,48914
98189,48914
98189,50134

View File

@@ -0,0 +1,13 @@
4,1
6,1
6,3
8,3
8,5
6,5
6,7
4,7
4,5
2,5
2,3
4,3

View File

@@ -0,0 +1,9 @@
7,1
11,1
11,7
9,7
9,5
2,5
2,3
7,3

View File

@@ -0,0 +1,151 @@
i64 write(i32, ptr i8, u64) {
`scsbsa`
syscall3(i64(1), `la` as i64, `lb` as i64, `lc` as i64)
}
i64 read(i32, ptr i8, u64) {
`scsbsa`
syscall3(i64(0), `la` as i64, `lb` as i64, `lc` as i64)
}
i32 open(ptr i8, i32, i32) {
`scsbsa`
syscall3(i64(2), `la` as i64, `lb` as i64, `lc` as i64)
as i32
}
void exit(i32) {
as i64 i64(231) rev
syscall1 trash
}
void putc(i8) {
array i8[1] `dstr` store
write(1, `lt`, u64(1)) trash
}
u64 strlen(ptr i8) {
dup while(dup load i8(0) !=) { 1+ } `r-`
}
void print(ptr i8) {
1 rev dup strlen write trash
}
void println(ptr i8) {
print i8(10) putc
}
void printnum(i32) {
if (dup 0 ==) {
putc('0')
} else if (dup 0 <) {
`0r-` '-' putc
}
array i8[11] 10+ dup i8(0) store -1+ `sb`
while (dup 0 !=) {
10 divmod 48+ as i8
`lb` rev store
`lb` -1+ `sb`
} trash
print(`lb`1+)
}
void printnum64(u64) {
if (dup u64(0) ==) {
putc('0')
}
array i8[22] 22+ dup i8(0) store -1+ `sb`
while (dup u64(0) !=) {
u64(10) divmod u64(48)+ as i8
`lb` rev store
`lb` -1+ `sb`
} trash
print(`lb`1+)
}
i32 atoi(ptr i8) {
set string
0
while (get string load '0' >= get string load '9' <= &) {
10* get string load '0'- as i32 +
get string 1+ set string
}
}
u64 atol(ptr i8) {
set string
u64(0)
while (get string load '0' >= get string load '9' <= &) {
u64(10)* get string load '0'- as u64 +
get string 1+ set string
}
}
i32 abs(i32) {
if (dup 0 <) {`0r-`}
}
void _start() {
open("input", 0, 0) set file
array i8[65535] set buffer
get buffer i8(48) store
read(get file, get buffer, u64(65535)) as i32 set size
#get buffer get size+ i8(10) store
array i32[512] set px
array i32[512] set py
u64(0) `so`
`0sc`
`0si`
while (`li1+` get size < ) {
atoi(buffer[`li`]) px[`lc`] `r` store
while (buffer[`li`] load ',' !=) {inc(i)} inc(i)
atoi(buffer[`li`]) py[`lc`] `r` store
while (buffer[`li`] load i8(10) !=) {inc(i)} inc(i)
inc(c)
}
`0si`
while (`lilc` < ) {
`li1+sj`
while(`ljlc` <){
px[`li`] load set x1 py[`li`] load set y1
px[`lj`] load set x2 py[`lj`] load set y2
if (abs(get x1 get x2 -) `1+` as u64 abs(get y1 get y2 -) `1+` as u64 * `lo` > ) {
abs(get x1 get x2 -) `1+` as u64 abs(get y1 get y2 -) `1+` as u64 * `so`
}
inc(j)
}
inc(i)
}
println("answer:")
printnum64(get o)
exit(0)
}
void main() {
_start
}

View File

@@ -0,0 +1,170 @@
i64 write(i32, ptr i8, u64) {
`scsbsa`
syscall3(i64(1), `la` as i64, `lb` as i64, `lc` as i64)
}
i64 read(i32, ptr i8, u64) {
`scsbsa`
syscall3(i64(0), `la` as i64, `lb` as i64, `lc` as i64)
}
i32 open(ptr i8, i32, i32) {
`scsbsa`
syscall3(i64(2), `la` as i64, `lb` as i64, `lc` as i64)
as i32
}
void exit(i32) {
as i64 i64(231) rev
syscall1 trash
}
void putc(i8) {
array i8[1] `dstr` store
write(1, `lt`, u64(1)) trash
}
u64 strlen(ptr i8) {
dup while(dup load i8(0) !=) { 1+ } `r-`
}
void print(ptr i8) {
1 rev dup strlen write trash
}
void println(ptr i8) {
print i8(10) putc
}
void printnum(i32) {
if (dup 0 ==) {
putc('0')
} else if (dup 0 <) {
`0r-` '-' putc
}
array i8[11] 10+ dup i8(0) store -1+ `sb`
while (dup 0 !=) {
10 divmod 48+ as i8
`lb` rev store
`lb` -1+ `sb`
} trash
print(`lb`1+)
}
void printnum64(u64) {
if (dup u64(0) ==) {
putc('0')
}
array i8[22] 22+ dup i8(0) store -1+ `sb`
while (dup u64(0) !=) {
u64(10) divmod u64(48)+ as i8
`lb` rev store
`lb` -1+ `sb`
} trash
print(`lb`1+)
}
i32 atoi(ptr i8) {
set string
0
while (get string load '0' >= get string load '9' <= &) {
10* get string load '0'- as i32 +
get string 1+ set string
}
}
u64 atol(ptr i8) {
set string
u64(0)
while (get string load '0' >= get string load '9' <= &) {
u64(10)* get string load '0'- as u64 +
get string 1+ set string
}
}
i32 abs(i32) {
if (dup 0 <) {`0r-`}
}
void _start() {
open("input.q", 0, 0) set file
array i8[65535] set buffer
get buffer i8(48) store
read(get file, get buffer, u64(65535)) as i32 set size
#get buffer get size+ i8(10) store
`0so`
`100000` set trx `100000` set try
`100000` set brx `0` set bry
`0` set blx `0` set bly
`0` set tlx `100000` set tly
`0si`
while (`li1+` get size < ) {
atoi(buffer[`li`]) `sx`
while (buffer[`li`] load ',' !=) {inc(i)} inc(i)
atoi(buffer[`li`]) `sy`
while (buffer[`li`] load i8(10) !=) {inc(i)} inc(i)
`lxlyr` printnum ',' putc printnum i8(10) putc
# if less than topright, then
if (`lxly+` get trx get try + <=) {
`lxly` set try set trx
}
# if y - x > br
if (`lylx-` get bry get brx - >=) {
`lxly` set bry set brx
}
# if more than bottom left
if (`lxly+` get blx get bly+ >=) {
`lxly` set bly set blx
}
# if x - y > tl
if (`lxly-` get tlx get tly - >=) {
`lxly` set tly set tlx
}
}
print("tr: ")
printnum(get trx) putc(',') printnum(get try) putc(i8(10))
print("br: ")
printnum(get brx) putc(',') printnum(get bry) putc(i8(10))
print("bl: ")
printnum(get blx) putc(',') printnum(get bly) putc(i8(10))
print("tl: ")
printnum(get tlx) putc(',') printnum(get tly) putc(i8(10))
get blx get trx - `1+` as u64 get bly get try - `1+` as u64 * `s1`
get tlx get brx - `1+` as u64 get bry get tly - `1+` as u64 * `s2`
if (`l1l2`>) {
`l1`
} else {
`l2`
}
println("answer:")
printnum64
exit(0)
}
void main() {
_start
}

View File

@@ -0,0 +1,344 @@
i64 write(i32, ptr i8, u64) {
`scsbsa`
syscall3(i64(1), `la` as i64, `lb` as i64, `lc` as i64)
}
i64 read(i32, ptr i8, u64) {
`scsbsa`
syscall3(i64(0), `la` as i64, `lb` as i64, `lc` as i64)
}
i32 open(ptr i8, i32, i32) {
`scsbsa`
syscall3(i64(2), `la` as i64, `lb` as i64, `lc` as i64)
as i32
}
ptr i8 mmap(ptr i8, u64, i32, i32, i32, i64) {
`sfsesdscsbsa`
syscall6(i64(9), `la` as i64, `lb` as i64, `lc` as i64, `ld` as i64, `le` as i64, `lf`)
as ptr i8
}
void exit(i32) {
as i64 i64(231) rev
syscall1 trash
}
void putc(i8) {
array i8[1] `dstr` store
write(1, `lt`, u64(1)) trash
}
u64 strlen(ptr i8) {
dup while(dup load i8(0) !=) { 1+ } `r-`
}
void print(ptr i8) {
1 rev dup strlen write trash
}
void println(ptr i8) {
print i8(10) putc
}
void printnum(i32) {
if (dup 0 ==) {
putc('0')
} else if (dup 0 <) {
`0r-` '-' putc
}
array i8[11] 10+ dup i8(0) store -1+ `sb`
while (dup 0 !=) {
10 divmod 48+ as i8
`lb` rev store
`lb` -1+ `sb`
} trash
print(`lb`1+)
}
void printnum64(u64) {
if (dup u64(0) ==) {
putc('0')
}
array i8[22] 21+ dup i8(0) store -1+ `sb`
while (dup u64(0) !=) {
u64(10) divmod u64(48)+ as i8
`lb` rev store
`lb` -1+ `sb`
} trash
print(`lb`1+)
}
i32 atoi(ptr i8) {
set string
0
while (get string load '0' >= get string load '9' <= &) {
10* get string load '0'- as i32 +
get string 1+ set string
}
}
u64 atol(ptr i8) {
set string
u64(0)
while (get string load '0' >= get string load '9' <= &) {
u64(10)* get string load '0'- as u64 +
get string 1+ set string
}
}
i32 abs(i32) {
if (dup 0 <) {`0r-`}
}
ptr i8 memset(ptr i8, i32, u64) {
`sn` as i8 `sc`
u64(0) `si`
while (`liln` < ) {
`1+dlc` store
inc(i)
}
}
u1 check_line(i32, i32, i32, ptr i32, ptr i32, ptr i32, i32) {
set linecount set linep set lineh set linel
set pos set top set bottom
# swap if needed
if (get top get bottom <) {get top get bottom set top set bottom}
printnum(get pos) ']' putc
printnum(get top) ',' putc
printnum(get bottom) i8(10) putc
`0si`
while (`li` get linecount <) {
#printnum(linep[`li`] load) ':' putc
#printnum(lineh[`li`] load) ',' putc
#printnum(linel[`li`] load)
#if (get top linep[`li`] load >= get bottom linep[`li`] load <= &) { '!' putc }
#if (lineh[`li`] load get pos >= linel[`li`] load get bottom <= &) { '@' putc }
#i8(10) putc
if (get top linep[`li`] load >= get bottom linep[`li`] load <= & # this line is positioned between
lineh[`li`] load get pos >= linel[`li`] load get pos <= & # it intersects
&) {
println("intersect")
return u1(0)
}
inc(i)
}
u1(1)
}
void floodfill(ptr i8, i32) {
set w set map
`0sy`
while (`lylw` <) {
u1(0) set flag
#'.' putc
`0sx`
while (`lxlw` <) {
#printnum(`lx`) ',' putc printnum(`ly`) if (get flag) {'T'} else {'F'} putc
#i8(10) putc
if (map[`lylw*lx+`] `dsp` load '#' == ) {
get flag u1(1) ^ set flag
}
if (get flag) {
`lp` '#' store
}
inc(x)
}
inc(y)
}
}
void _start() {
open("input", 0, 0) set file
array i8[65535] set buffer
get buffer i8(48) store
read(get file, get buffer, u64(65535)) as i32 set size
#get buffer get size+ i8(10) store
array i32[512] set px
array i32[512] set py
u64(0) `so`
100000 `sw`
# println("mmap")
# yeah whatever go my constants
# mmap(u64(0) as ptr i8, u64(419304) u64(4096) *, 1 2 |, 32 2 |, 0, i64(0)) set map
# if (get map as i64 i64(-1) == ){
# println("mmap failed")
# exit(1)
#}
# memset(get map, 0, u64(10000000000)) trash
# println("wmpwmef")
# stride
# load points
`0sc`
`0si`
while (`li1+` get size < ) {
atoi(buffer[`li`]) px[`lc`] `r` store
while (buffer[`li`] load ',' !=) {inc(i)} inc(i)
atoi(buffer[`li`]) py[`lc`] `r` store
while (buffer[`li`] load i8(10) !=) {inc(i)} inc(i)
inc(c)
}
println("mapping")
array i32[512] set hlineh
array i32[512] set hlinel
array i32[512] set hlinep
0 set hlinec
array i32[512] set vlineh
array i32[512] set vlinel
array i32[512] set vlinep
0 set vlinec
# map out lines
# i'm just assuming clockwise. i think that's valid
`1si`
# TODO: set lastturn properly
'Q' set lastturn
while (`lilc` <=) {
px[`li1-`] load set x1 py[`li1-`] load set y1
if (`lilc` != ) {
px[`li`] load set x2 py[`li`] load set y2
} else {
# last iter
px[0] load set x2 py[0] load set y2
}
if (get x1 get x2 == ) {
# store vline
if (get y1 get y2 < ) {
# down
# corner
if (get lastturn 'l' ==) {inc(y1) hlinel[get hlinec 1-] dup load `1+` store}
'd' set lastturn
get x1 1+ get y1 get y2
} else {
# up
if (get lastturn 'r' ==) {dec(y1) hlineh[get hlinec 1-] dup load `1-` store}
'u' set lastturn
get x1 1- get y2 get y1
}
vlineh[get vlinec] rev store vlinel[get vlinec] rev store
vlinep[get vlinec] rev store
inc(vlinec)
} else if (get y1 get y2 == ) {
# store hline
if (get x1 get x2 < ) {
# right
if (get lastturn 'd' ==) {inc(x1) vlineh[get vlinec 1-] dup load `1-` store}
'r' set lastturn
get y1 1- get x1 get x2
} else {
# left
if (get lastturn 'u' ==) {dec(x1) vlinel[get vlinec 1-] dup load `1+` store}
'l' set lastturn
get y1 1+ get x2 get x1
}
hlineh[get hlinec] rev store hlinel[get hlinec] rev store
hlinep[get hlinec] rev store
inc(hlinec)
}
inc(i)
}
println("checking")
`0si`
while (`lilc` < ) {
`li1+sj`
while(`ljlc` <){
px[`li`] load set x1 py[`li`] load set y1
px[`lj`] load set x2 py[`lj`] load set y2
i8(10) putc
printnum(get x1) ',' putc printnum(get y1) i8(10) putc
printnum(get x2) ',' putc printnum(get y2) i8(10) putc
if (check_line(get x1, get x2, get y1, get vlinel, get vlineh, get vlinep, get vlinec)
check_line(get x1, get x2, get y2, get vlinel, get vlineh, get vlinep, get vlinec) &
check_line(get y1, get y2, get x1, get hlinel, get hlineh, get hlinep, get hlinec) &
check_line(get y1, get y2, get x2, get hlinel, get hlineh, get hlinep, get hlinec) & ) {
println("okay")
if (abs(get x1 get x2 -) `1+` as u64 abs(get y1 get y2 -) `1+` as u64 * `lo` > ) {
println("max")
abs(get x1 get x2 -) `1+` as u64 abs(get y1 get y2 -) `1+` as u64 * `so`
#if (`lo` u64(25) == ) {exit(2)}
}
}
inc(j)
}
inc(i)
}
println("answer:")
printnum64(get o)
exit(0)
}
void main() {
_start
}