Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: dc -fdc-p1.dc <input
- # Unpack input onto stack
- ?
- [
- 10~r
- d0<L
- ] dsLx +
- [digits unpacked: ]nzps.
- dsl1 # left = start (size of file #0); stack: file idx next ...
- [
- r3R + # idx += next (gap); idx file nextNext ...
- 3R # i=next idx file ...
- [
- rd 4Rd 3R:d # disk(idx)=file; file idx i
- r1+ # idx++ file i
- 3R 1- d0<I # i--; loop
- ] dsIx + # idx file
- r1+ # file++ idx next rest
- z2<L
- ] dsLx s.
- ll1- # stack: left right
- [
- rdd;d r0r:d # disk(right) right left; disk(right) = 0
- 3R d3R r:d # disk(left) = disk(right); stack: left right
- [
- 1+ d;d 0!=L # inc left until not zero
- ] dsLx
- r
- [
- 1- d;d 0=R # dec right until zero
- ] dsRx
- d3Rd3R >M # loop while (right > left); left right
- ] dsMx
- 0r # i sum=0
- [
- dd;d * 3R+ # sum += disk(i) * i
- r1- d0<L
- ] dsLx +
- [Part 1: ]np
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement