Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/dc
- [q] SX
- ###################################################################################
- # Initial loading of data into stack and queue
- 100 sz # z = number of boards (hardcoded)
- # Push card data onto - register stack
- [
- r # i top -> top i next
- S- # (push top on - stack) i next
- 1- d 0=X # ((i-1) == 0 exit) (i-1) next
- lIx
- ] sI
- lz 25* lIx s. # push counter of items, call loop, pop the counter
- # Load remaining items into the caller list (q)
- [
- z 0 =X # exit when stack empty
- li:q # top -> (q(i) = top)
- li 1- si # i++
- lIx
- ] sI
- z1- si lIx
- ###################################################################################
- # Initialize the number hash to -1 for all values 0-top
- [
- 1- # i--
- d _1 r:n # 0 i i -> (n(i) = _1) i
- d 0=X # (exit if i = 0)
- lNx
- ] sN
- # load card into number hash
- [
- li 1- d si # (i = i-1) (i-1)
- _1=X # ((i-1) == -1 exit)
- L- # top = pop item from card input
- d ls+ ss # top -> (s = s + top) top
- li r:n # (n(top) = i)
- lBx
- ] sB
- # clear line count array
- [
- 1- dd # j-- -> j j j
- 0 r:l # (l(j) = 0) j j
- 0=X # (j = 0 exit) j
- lJx
- ] sJ
- # Macro to call to initialize card
- [
- 10 lJx s. # initialize line counts
- 100 lNx s. # initialize number hash
- 0 ss # init s (sum of numbers on card)
- 25si lBx # load card into hash
- ] sC
- ###################################################################################
- # Output result from winning card
- [
- [Calls: ]n li1+n
- [ Result: ]n lc ls*p
- c
- 3Q
- ] sP
- # Macro to mark card
- [
- lc ls r- ss # pos -> (s = s - call) pos
- 5~5+ # pos -> yline xline
- d;l 1+ # l(yline)+1 yline xline
- d 5=P # (l(yline)+1 == 5 print) l(yline)+1 yline xline
- r:l # (l(yline) = l(yline)+1) xline
- d;l 1+ #
- d 5=P # ditto above (only now working on xline)
- r:l #
- 0 # place number on top of stack for return
- ] sM
- #
- # Main loop
- #
- [
- li;q # next number from q(i)
- d sc # (c = num) num
- ;n d _1!=M # num -> (n(num) != _1 mark card) n(num)
- s. # clear 0 or -1 depending if M ran
- li 1+ si # i++
- lIx # loop
- ] sI
- [
- lz 1- d sz _1=X # z--, exit if z == -1
- lCx # initialize card data
- 0si lIx # start calling loop
- lZx
- ] SZ
- lZx
Add Comment
Please, Sign In to add comment