Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: perl -pe's/(.)/$1 /g;y/.#/01/' | dc -e2 -fpart1.dc
- # Change the -e1 to -e1000000 for part 2
- ss # scale (extra lines to add)
- # Load grid:
- ? 1 # line y
- [
- 0 # top y ysum
- [
- 3Rd 3R+ r # y (ysum+=top) top
- z2- # y ysum top x=z-2
- d_3R # y ysum x top x
- ;c + r:c # col(x)+=top; y ysum
- z 2<X
- ] dsXx
- # stack: y ysum
- d lg+sg # galaxy number += ysum
- rd_3R :r # row(y) = ysum
- 1+ # y++
- ? zRz 1<Y
- ] dsYx
- # Expand: 1 -> scale
- [ ls* ] sE
- # absolute differences with expanded 0s (stack: i=last-index)
- [
- 0 sc # column
- 0 sa # accumulated seen
- 0r # dist=0 i
- [
- dlAx # dist i arr(i)
- d 1 r0=E lc+sc # inc col (expand by scale if 0); dist i arr(i)
- d dla2*+lg- *lc* # dist i arr(i) factor=col*arr(i)*(2*seen+arr(i)-#gals)
- r la+sa # seen += arr(i); dist i factor
- 3R+ # i dist+=factor
- r1- d 0<L
- ] dsLx
- + # clear i (+0)
- ] sD
- # Stack: size (10 or 140)
- 1-
- [;r]sA dlDx # size -> size-1 row_dist
- [;c]sA rlDx +p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement