mirror of
https://git.plasmaofthedawn.com/adventofcode.git
synced 2025-12-24 02:27:34 -06:00
day 8
This commit is contained in:
1001
src/plasl/2025/day8/input
Normal file
1001
src/plasl/2025/day8/input
Normal file
File diff suppressed because it is too large
Load Diff
1001
src/plasl/2025/day8/input.s
Normal file
1001
src/plasl/2025/day8/input.s
Normal file
File diff suppressed because it is too large
Load Diff
21
src/plasl/2025/day8/input.t
Normal file
21
src/plasl/2025/day8/input.t
Normal file
@@ -0,0 +1,21 @@
|
||||
162,817,812
|
||||
57,618,57
|
||||
906,360,560
|
||||
592,479,940
|
||||
352,342,300
|
||||
466,668,158
|
||||
542,29,236
|
||||
431,825,988
|
||||
739,650,466
|
||||
52,470,668
|
||||
216,146,977
|
||||
819,987,18
|
||||
117,168,530
|
||||
805,96,715
|
||||
346,949,466
|
||||
970,615,88
|
||||
941,993,340
|
||||
862,61,35
|
||||
984,92,344
|
||||
425,690,689
|
||||
|
||||
337
src/plasl/2025/day8/part1.psl
Normal file
337
src/plasl/2025/day8/part1.psl
Normal file
@@ -0,0 +1,337 @@
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
void heap_add(u64, i32, i32, ptr u64, ptr i32, ptr i32) {
|
||||
`sysx` set heap set vy set vx set value
|
||||
heap[0] load set size
|
||||
|
||||
heap[get size] get value store
|
||||
y[get size] get vy store
|
||||
x[get size] get vx store
|
||||
|
||||
get size as i32 set index
|
||||
# swap while not heaped
|
||||
while(get index 0 > heap[get index] load heap[get index 2/] load < &) {
|
||||
|
||||
heap[get index] set t1 heap[get index 2/] set t2
|
||||
get t1 load get t2 load get t1 rev store get t2 rev store
|
||||
|
||||
x[get index] `ds.` load x[get index 2/] `ds,` load `l.r` store `l,r` store
|
||||
y[get index] `ds.` load y[get index 2/] `ds,` load `l.r` store `l,r` store
|
||||
|
||||
get index 2/ set index
|
||||
}
|
||||
|
||||
heap[0] dup load u64(1)+ store
|
||||
|
||||
}
|
||||
|
||||
void heap_pop(ptr u64, ptr i32, ptr i32) {
|
||||
`sysx` set heap
|
||||
|
||||
heap[0] dup load u64(1) - dup as i32 set size store
|
||||
|
||||
heap[1] heap[get size 1-] load store # set the heap[0] as last heap element
|
||||
y[1] y[get size 1-] load store
|
||||
x[1] x[get size 1-] load store
|
||||
|
||||
u1(1) set cont
|
||||
`1si`
|
||||
|
||||
# down heap
|
||||
while (get cont) {
|
||||
|
||||
`li` set nexti
|
||||
|
||||
if (`li2*` get size < heap[get nexti] load heap[`li2*`] load > &) {
|
||||
`li2*` set nexti
|
||||
}
|
||||
if (`li2*1+` get size < heap[get nexti] load heap[`li2*1+`] load > &) {
|
||||
`li2*1+` set nexti
|
||||
}
|
||||
|
||||
if (`li` get nexti !=) {
|
||||
|
||||
heap[get i] `ds.` load heap[get nexti] `ds,` load `l.r` store `l,r` store
|
||||
x[get i] `ds.` load x[get nexti] `ds,` load `l.r` store `l,r` store
|
||||
y[get i] `ds.` load y[get nexti] `ds,` load `l.r` store `l,r` store
|
||||
|
||||
get nexti set i
|
||||
} else {
|
||||
u1(0) set cont
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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[1024] set px
|
||||
array i32[1024] set py
|
||||
array i32[1024] set pz
|
||||
|
||||
u64(0) `so`
|
||||
|
||||
`0si0sc`
|
||||
while (`li` get size 1- < ) {
|
||||
|
||||
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 ',' !=) {inc(i)} inc(i)
|
||||
|
||||
atoi(buffer[`li`]) pz[`lc`] `r` store
|
||||
while (buffer[`li`] load i8(10) !=) {inc(i)} inc(i)
|
||||
|
||||
inc(c)
|
||||
}
|
||||
|
||||
|
||||
pz[0] load py[0] load px[0] load
|
||||
printnum ',' putc printnum ',' putc printnum i8(10) putc
|
||||
println("distance calculation...")
|
||||
|
||||
mmap(u64(0) as ptr i8, u64(2048) u64(4096) *, 2 1|, 32 2|, 0, i64(0)) as ptr u64 set dist
|
||||
|
||||
dist[524800] as ptr i32 set dist_p1
|
||||
dist_p1[524800] set dist_p2
|
||||
|
||||
dist[0] u64(1) store
|
||||
|
||||
`0si`
|
||||
while (`lilc` < ) {
|
||||
`li1+sj`
|
||||
while (`ljlc` <) {
|
||||
#`liljr` printnum ',' putc printnum i8(10) putc
|
||||
|
||||
heap_add(
|
||||
abs(px[`li`] load px[`lj`] load -) as u64 `d*`
|
||||
abs(py[`li`] load py[`lj`] load -) as u64 `d*` +
|
||||
abs(pz[`li`] load pz[`lj`] load -) as u64 `d*` +,
|
||||
get i, get j
|
||||
get dist, get dist_p1, get dist_p2
|
||||
)
|
||||
|
||||
inc(j)
|
||||
}
|
||||
inc(i)
|
||||
}
|
||||
|
||||
|
||||
println("chain joining...")
|
||||
|
||||
array i32[1024] set links
|
||||
memset(get links as ptr i8, 0, 4 1024* as u64) trash
|
||||
array i32[1024] set linkcount
|
||||
memset(get linkcount as ptr i8, 0, 4 1024* as u64) trash
|
||||
0 set numlinks
|
||||
|
||||
`0si`
|
||||
while (`li` 1000 <) {
|
||||
#dist[0] load printnum64 ' ' putc
|
||||
#dist[1] load printnum64 ',' putc
|
||||
#dist_p1[1] load printnum ',' putc
|
||||
#dist_p2[1] load printnum i8(10) putc
|
||||
|
||||
dist_p1[1] load set p1 dist_p2[1] load set p2
|
||||
|
||||
if (links[get p1] load 0 == links[get p2] load 0 == &) {
|
||||
# create a new link between these unlinked posts
|
||||
inc(numlinks)
|
||||
links[get p1] get numlinks store
|
||||
links[get p2] get numlinks store
|
||||
|
||||
linkcount[get numlinks] dup load 2+ store
|
||||
|
||||
} else if (links[get p1] load 0 != links[get p2] load 0 == &) {
|
||||
# link p2 to p1's link
|
||||
links[get p2] links[get p1] load store
|
||||
linkcount[links[get p1] load] dup load 1+ store
|
||||
} else if (links[get p1] load 0 == links[get p2] load 0 != &) {
|
||||
# link p1 to p2's link
|
||||
links[get p1] links[get p2] load store
|
||||
linkcount[links[get p2] load] dup load 1+ store
|
||||
} else if (links[get p1] load links[get p2] load !=){
|
||||
# big annoying link
|
||||
|
||||
links[get p1] load set into
|
||||
links[get p2] load set from
|
||||
|
||||
|
||||
linkcount[get into] dup load linkcount[get from] load + store
|
||||
linkcount[get from] 0 store
|
||||
|
||||
`0sj`
|
||||
while (`ljlc`<) {
|
||||
if(links[`lj`] load get from ==) {
|
||||
links[`lj`] get into store
|
||||
}
|
||||
inc(j)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
heap_pop(get dist, get dist_p1, get dist_p2)
|
||||
inc(i)
|
||||
}
|
||||
|
||||
println("finding largest...")
|
||||
|
||||
array i32[3] set biggest
|
||||
memset(get biggest as ptr i8, 0, 4 3* as u64) trash
|
||||
|
||||
`0si`
|
||||
while (`li` get numlinks 1+<) {
|
||||
|
||||
`0sj`
|
||||
|
||||
linkcount[`li`] load set ccount
|
||||
|
||||
while (`lj` 3 < ) {
|
||||
if (biggest[`lj`] load get ccount <) {
|
||||
get ccount biggest[`lj`] dup load set ccount rev store
|
||||
}
|
||||
inc(j)
|
||||
}
|
||||
inc(i)
|
||||
}
|
||||
|
||||
|
||||
`0si`
|
||||
1
|
||||
while (`li` 3 <) {
|
||||
printnum(biggest[`li`] load) i8(10) putc
|
||||
biggest[`li`] load *
|
||||
inc(i)
|
||||
}
|
||||
|
||||
println("answer:")
|
||||
printnum64(as u64)
|
||||
|
||||
exit(0)
|
||||
}
|
||||
|
||||
void main() {
|
||||
_start
|
||||
}
|
||||
375
src/plasl/2025/day8/part2.psl
Normal file
375
src/plasl/2025/day8/part2.psl
Normal file
@@ -0,0 +1,375 @@
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
void heap_add(u64, i32, i32, ptr u64, ptr i32, ptr i32) {
|
||||
`sysx` set heap set vy set vx set value
|
||||
heap[0] load set size
|
||||
|
||||
heap[get size] get value store
|
||||
y[get size] get vy store
|
||||
x[get size] get vx store
|
||||
|
||||
get size as i32 set index
|
||||
#printnum(get index) '.' putc printnum(get index 2/) i8(10) putc
|
||||
# swap while not heaped
|
||||
while(
|
||||
get index 2/ set parent
|
||||
get index 1 > heap[get index] load heap[get parent] load < &
|
||||
) {
|
||||
|
||||
#printnum(get index) ',' putc printnum(get parent) i8(10) putc
|
||||
|
||||
|
||||
heap[get index] `ds.` load heap[get parent] `ds,` load `l.r` store `l,r` store
|
||||
x[get index] `ds.` load x[get parent] `ds,` load `l.r` store `l,r` store
|
||||
y[get index] `ds.` load y[get parent] `ds,` load `l.r` store `l,r` store
|
||||
|
||||
get parent set index
|
||||
}
|
||||
|
||||
heap[0] dup load u64(1)+ store
|
||||
|
||||
}
|
||||
|
||||
void heap_pop(ptr u64, ptr i32, ptr i32) {
|
||||
`sysx` set heap
|
||||
|
||||
heap[0] dup load u64(1) - dup as i32 set size store
|
||||
|
||||
heap[1] heap[get size 1-] load store # set the heap[0] as last heap element
|
||||
y[1] y[get size 1-] load store
|
||||
x[1] x[get size 1-] load store
|
||||
|
||||
u1(1) set cont
|
||||
`1si`
|
||||
|
||||
# down heap
|
||||
while (get cont) {
|
||||
|
||||
`li` set nexti
|
||||
|
||||
if (`li2*` get size < heap[get nexti] load heap[`li2*`] load > &) {
|
||||
`li2*` set nexti
|
||||
}
|
||||
if (`li2*1+` get size < heap[get nexti] load heap[`li2*1+`] load > &) {
|
||||
`li2*1+` set nexti
|
||||
}
|
||||
|
||||
if (`li` get nexti !=) {
|
||||
|
||||
heap[get i] `ds.` load heap[get nexti] `ds,` load `l.r` store `l,r` store
|
||||
x[get i] `ds.` load x[get nexti] `ds,` load `l.r` store `l,r` store
|
||||
y[get i] `ds.` load y[get nexti] `ds,` load `l.r` store `l,r` store
|
||||
|
||||
get nexti set i
|
||||
} else {
|
||||
u1(0) set cont
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void check_heap(ptr u64) {
|
||||
set heap
|
||||
|
||||
heap[0] load as i32 set size
|
||||
|
||||
`1si`
|
||||
while (`li` get size <) {
|
||||
|
||||
#printnum(`li`) ':'putc
|
||||
#printnum64(heap[`li`]load) ' ' putc
|
||||
|
||||
if (`li2*` get size < heap[`li2*`] load heap[`li`] load <&) {
|
||||
#printnum64(heap[`li2*`]load) ' ' putc
|
||||
exit(3)
|
||||
}
|
||||
|
||||
if (`li2*1+` get size < heap[`li2*1+`] load heap[`li`] load <&) {
|
||||
#printnum64(heap[`li2*1+`]load) ' ' putc
|
||||
exit(3)
|
||||
}
|
||||
|
||||
inc(i)
|
||||
}
|
||||
i8(10) putc
|
||||
|
||||
}
|
||||
|
||||
|
||||
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[1024] set px
|
||||
array i32[1024] set py
|
||||
array i32[1024] set pz
|
||||
|
||||
u64(0) `so`
|
||||
|
||||
`0si0sc`
|
||||
while (`li` get size 1- < ) {
|
||||
|
||||
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 ',' !=) {inc(i)} inc(i)
|
||||
|
||||
atoi(buffer[`li`]) pz[`lc`] `r` store
|
||||
while (buffer[`li`] load i8(10) !=) {inc(i)} inc(i)
|
||||
|
||||
inc(c)
|
||||
}
|
||||
|
||||
|
||||
#pz[0] load py[0] load px[0] load
|
||||
#printnum ',' putc printnum ',' putc printnum i8(10) putc
|
||||
println("distance calculation...")
|
||||
|
||||
mmap(u64(0) as ptr i8, u64(2048) u64(4096) *, 2 1|, 32 2|, 0, i64(0)) as ptr u64 set dist
|
||||
|
||||
dist[524800] as ptr i32 set dist_p1
|
||||
dist_p1[524800] set dist_p2
|
||||
|
||||
dist[0] u64(1) store
|
||||
|
||||
`0si`
|
||||
while (`lilc` < ) {
|
||||
`li1+sj`
|
||||
while (`ljlc` <) {
|
||||
#`liljr` printnum ',' putc printnum i8(10) putc
|
||||
|
||||
heap_add(
|
||||
abs(px[`li`] load px[`lj`] load -) as u64 `d*`
|
||||
abs(py[`li`] load py[`lj`] load -) as u64 `d*` +
|
||||
abs(pz[`li`] load pz[`lj`] load -) as u64 `d*` +,
|
||||
get i, get j
|
||||
get dist, get dist_p1, get dist_p2
|
||||
)
|
||||
|
||||
#check_heap(get dist)
|
||||
#check_heap(get dist)
|
||||
|
||||
inc(j)
|
||||
}
|
||||
inc(i)
|
||||
}
|
||||
|
||||
|
||||
println("chain joining...")
|
||||
|
||||
array i32[1024] set links
|
||||
memset(get links as ptr i8, 0, 4 1024* as u64) trash
|
||||
array i32[1024] set linkcount
|
||||
memset(get linkcount as ptr i8, 0, 4 1024* as u64) trash
|
||||
0 set numlinks
|
||||
|
||||
0 set maxl
|
||||
|
||||
0 set clink
|
||||
|
||||
`0s10s2`
|
||||
`0si`
|
||||
while (get maxl `lc` !=) {
|
||||
dist_p1[1] load `s1`
|
||||
dist_p2[1] load `s2`
|
||||
|
||||
#dist[0] load printnum64 ' ' putc
|
||||
#dist[1] load printnum64 ',' putc
|
||||
#dist_p1[1] load printnum ',' putc
|
||||
#dist_p2[1] load printnum ',' putc
|
||||
#printnum64(px[`l1`] load as u64 px[`l2`] load as u64 *) ')' putc
|
||||
#printnum(get maxl)
|
||||
#i8(10) putc
|
||||
|
||||
dist_p1[1] load set p1 dist_p2[1] load set p2
|
||||
|
||||
if (links[get p1] load 0 == links[get p2] load 0 == &) {
|
||||
# create a new link between these unlinked posts
|
||||
inc(numlinks)
|
||||
links[get p1] get numlinks store
|
||||
links[get p2] get numlinks store
|
||||
|
||||
linkcount[get numlinks] dup load 2+ store
|
||||
|
||||
get numlinks set clink
|
||||
|
||||
} else if (links[get p1] load 0 != links[get p2] load 0 == &) {
|
||||
# link p2 to p1's link
|
||||
links[get p2] links[get p1] load store
|
||||
linkcount[links[get p1] load] dup load 1+ store
|
||||
|
||||
links[get p1] load set clink
|
||||
|
||||
} else if (links[get p1] load 0 == links[get p2] load 0 != &) {
|
||||
# link p1 to p2's link
|
||||
links[get p1] links[get p2] load store
|
||||
linkcount[links[get p2] load] dup load 1+ store
|
||||
|
||||
links[get p2] load set clink
|
||||
|
||||
} else if (links[get p1] load links[get p2] load !=){
|
||||
# big annoying link
|
||||
|
||||
links[get p1] load set into
|
||||
links[get p2] load set from
|
||||
|
||||
linkcount[get into] dup load linkcount[get from] load + store
|
||||
linkcount[get from] 0 store
|
||||
|
||||
`0sj`
|
||||
while (`ljlc`<) {
|
||||
if(links[`lj`] load get from ==) {
|
||||
links[`lj`] get into store
|
||||
}
|
||||
inc(j)
|
||||
}
|
||||
|
||||
|
||||
get into set clink
|
||||
|
||||
}
|
||||
|
||||
if (get maxl linkcount[get clink] load <) {
|
||||
linkcount[get clink] load set maxl
|
||||
}
|
||||
|
||||
heap_pop(get dist, get dist_p1, get dist_p2)
|
||||
inc(i)
|
||||
}
|
||||
|
||||
`0si`
|
||||
while (`li` get numlinks 1+ <) {
|
||||
#printnum(linkcount[`li`] load) i8(10) putc
|
||||
inc(i)
|
||||
}
|
||||
|
||||
|
||||
|
||||
println("answer:")
|
||||
printnum64(px[`l1`] load as u64 px[`l2`] load as u64 *)
|
||||
|
||||
exit(0)
|
||||
}
|
||||
|
||||
void main() {
|
||||
_start
|
||||
}
|
||||
Reference in New Issue
Block a user