Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Command:
- #
- # highbit = 2048
- # dc -e`dc -e"$highbit sb" -e'2i' -finput -e"[1r-] sN" -fdc-p2.dc` \
- # -e`dc -e"$highbit sb" -e'2i' -finput -e"[] sN" -fdc-p2.dc` \
- # -e'*p'
- #
- # Script takes two pieces of input code:
- # 1) setting b to the high bit (2048 for the input or 16 for test)
- # 2) an N macro to negate the logic for the Oxygen calculation
- #
- Ai # back to decimal
- #2048sb # for input (pass in this or 16sb for test case)
- # Quit reducing: size setIndex
- [
- * # clear size=1
- 1 r;Gx # get first/only value in array[setIndex]
- lb lo *+ p # apply remainder if needed and print exit
- q # quit
- ] sq
- # Macros so we can get and set to different arrays with
- # value index array ;Sx -> this does array[array][index] = value
- # index array ;Gx -> this returns array[array][index]
- [:0] 0:S [:1] 1:S
- [;0] 0:G [;1] 1:G
- # Filter: i=size num1 num2 num3 ...
- [
- 0Sn # clear counts
- # num1 num2 num3 ...
- [
- lb # b num
- ~r # bit rest
- dd;n 1+ d_3Rr:n # num[bit]++; num[bit] bit rest
- r;Sx # array[bit][num] = rest; num2 ...
- z 0<L
- ] dsLx
- # 0s - 1s | +'ve 0 -'ve
- # --------+---------=--------
- # Oxygen | 0 1 1
- # CO2 | 1 0 0
- #
- # So we want d.-1/ (1 if +'ve, 0 if 0 or -'ve), and to negate (1r-) for the Oxygen
- 0;n 1;n- d.1-/ lNx # do check to get index of target array
- dlo 2*+ so # append that bit to the output
- d;n # i=size setIndex
- d1=q # stop if only one left
- # load passing values from successful array back onto stack
- [
- r d3R d3R # set i i set
- ;Gx # get( set[i] ) i set
- _3R 1- d0<I # i-- set get(set[i])
- ] dsIx *+ # clear i=0 and set
- lb2/dsb 0<F # shift highbit right, loop until we quit or run off end
- ] dsFx
Advertisement
Add Comment
Please, Sign In to add comment