Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/dc -finput
- z sn # lines of input
- 0 sw # width of lines
- [1+] S1 # inc
- [ d2*1+2%* ] s| # abs
- [ d l|x d 0=1 / ] sS # sign
- # load array, find maximum width line of input
- [ dZ sw ] sW
- [
- dZ lw<W # num -> (max width < len(num), set new width) num
- z :g # store line in grid
- z 0<L # loop until stack empty
- ] sL
- lLx
- # add top and bottom borders
- lw2+ 10r^1- d 0:g ln1+:g
- # add borders to left and right
- [
- dd # i -> i i i
- ;g lw 10r^ 9*+ 10*9+ # g(i) i i -> ((g(i) + 10^x * 9) * 10 + 9) i i
- r:g # (g(i) = number with 9 borders) i
- 1- d 0<L # i--, loop while > 0
- ] sL
- ln lLx
- 0 ss
- [s. _1] sZ # replace top of stack with -1 (so it adds zero)
- [ ;gr 10r^/ 10% ] s= # y x -> digit x of g(y)
- [
- lx ly l=x dddd 0r # g(y,x) five times, insert sum of signs pos 2
- lx1+ ly l=x - lSx+ r # take sign of diff for dir, add to sum of signs
- lx1- ly l=x - lSx+ r # ditto
- lx ly1+ l=x - lSx+ r # ditto
- lx ly1- l=x - lSx+ # ditto
- _4!=Z 1+ ls+ ss # if sum of signs isn't -4, make it add zero to score
- lx1- dsx 0<X
- ] sX
- [
- lw sx lXx
- ly1- dsy 0<Y
- ] sY
- ln sy lYx
- [Part 1: ]n lsp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement