Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command: dc -fdc-p1.dc <input
- [q] sQ
- # Read Input
- ?
- [
- # stack: item2 item1
- d;b 1+ r:b # b(item2)++
- d;a 1+ r:a # a(item1)++
- ? z0<I
- ] dsIx
- # sorting loop, paramertized (lGx: get from reg array, lPx: push to reg stack)
- [
- 99999
- [
- dlGx # j=get(i) i
- [
- d 0=Q # j i, quit if j == 0
- rd lPx r # Push copy of i on register stack
- 1- lJx # j--
- ] dsJx + # end: junk j=0 with addition
- 1- d0<I # i--, loop while i > 0
- ] dsIx
- ] sS
- 0 Sc # add sentinel to bottom of c
- [;a]sG [Sc]sP lSx # convert array a into sorted stack c
- [;b]sG [Sd]sP lSx # convert array b into sorted stack d
- # Process
- 0 # sum
- [
- Lc d0=Q # pop item, quit if == 0
- Ld - d*v + # sum += abs(item1 - item2)
- lLx
- ] dsLx
- [Part 1: ]nrp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement