Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: tr ',' ' ' <input | dc -fheap.dc -fdc-p1.dc
- A000 sA
- # Load input into x,y,z arrays
- 1 ? # z y x i
- [
- 4R d3R r:z
- d3R r:y
- d3R r:x
- d Fd^ r:n
- 1+ ? z1<L
- ] dsLx # i left on stack
- [A0*] sE
- 1- # num pts = i-1
- d A r A00=E se # e = number of edges to merge
- d sn # n = num pts
- # Calculate distance pairs and push on heap
- # i = num
- [
- dsi
- d1- # j=i-1 i
- [
- dsj
- li;x lj;x- l2^
- li;y lj;y- l2^ +
- li;z lj;z- l2^ + # dist j i
- lA* + # append j to dist
- lA* + # append i to (dist|j)
- l<x # push on heap
- lilj l1- dl0<J
- ] dsJx +
- l1-p dl0<I
- ] dsIx l0*
- # Initialize circuit array
- ln # i=numPoints
- [
- d d:c
- 1- d0<L
- ] dsLx +
- # Set circ[j] = a; b j a i
- [
- r3R # a j b i
- d3R d3R # a j j a b i
- r:c # circ[j] = a; j a b i
- 3R # restore stack: b j a i
- ] sS
- # Merge shortest edges into circuits
- le # i=edges
- [
- l>x # get next edge from heap
- 10 8^% # strip distance
- A000 ~ # aIdx bIdx i
- ;c r;c # b=circ[bIdx] a=circ[aIdx] i
- ln # j=numPoints b a i
- [
- d;c # circ[j] j b a i
- 3R d3R # cir[j] b b j a i
- =S # set if circ[j] == b; b j a i
- r 1- d0<J
- ] dsJx ++s. # junk(j=0 b a); i
- 1- d0<I
- ] dsIx +
- # Calculate sizes of subgraphs
- ln # i = numPoints+0
- [
- d;c
- d;s 1+ r:s # sizes[circ[i]]++
- 1- d0<I
- ] dsIx +
- # [r] sr # available from heap.dc
- # Get size of three largest subgraphs
- dd ln # i = num points max1 max2 max3 (copying zero from start)
- [
- d;s # size[i] i max1 max2 max3
- r _5R
- [
- d3R d3R >r _4R
- ] dsLx lLx lLx
- s. # junk min of four; max1 max2 max3 i
- 4R1- d0<I
- ] dsIx +
- [Part 1: ]n**p
Advertisement
Add Comment
Please, Sign In to add comment