Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: tr ',' ' ' </tmp/input | dc -fdc-p2.dc
- # 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
- 1- dsn # num pts
- # update nearest: j dist i
- [
- d3R d3R # j dist dist j i
- :n # nearest(j) = dist; dist j i
- r 3R d3R d3R # i j j i dist
- r:e # end(j) = i; j i dist
- 3Rr # restore stack
- ] sN
- # i = num
- [
- dsi
- d1- # j=i-1 i
- [
- dsj
- li;x lj;x- 2^
- li;y lj;y- 2^ +
- li;z lj;z- 2^ + # dist j i
- d3R d3R # dist j j dist i
- r;n # nearest(j) dist j dist i
- >N # update nearest(j); j dist i
- _3R d3R d3R # dist i i dist j
- r;n
- >N # update nearest(i); i dist j
- rs.r # j i
- 1- d0<J
- ] dsJx +
- 1- d0<I
- ] dsIx 0* # XXX: Why does this exit with -1?
- # stack: 0
- # change max idx: max i -> max=i i
- [ s.d ] sM
- ln # i=n max=0
- [
- d;n # nearest(i) i max
- 3R d;n 3R # nearest(i) nearest(max) max i
- >M # update max; max i
- r 1- d0<L
- ] dsLx +
- # stack: max
- d;e # end max
- ;x r;x # max->x end->x
- *
- [Part 2: ]np
Advertisement
Add Comment
Please, Sign In to add comment