Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- z sn # num of crab subs
- [ d2*1+2%* ] S| # abs
- [ d sm ] S= # set maximum: leave top on stack
- [
- d ls+ss # top -> (sum += top) top
- d lm<= # top -> (top > max, set new max) top
- d;c 1+ r:c # c(top) = c(top) + 1
- z 0<L
- ] SL
- 0 ss # sum = 0
- 0 sm # max init to 0
- lLx # load sub data
- [
- 1+ # i -> i+1
- d;c lc r- d sc # i -> (count = count-crab(i)) new-count i
- 0<M # (loop if new-count > 0) i
- ] SM
- ln 2/sc _1 lMx
- sv # v = median
- [ lv- l|x ] sW # weight function: top -> abs(top - v)
- [
- d d;c r # i -> i c(i) i
- lWx * # -> weight(i)*c(i) i
- l!+ s! # add result to part 1
- 1- d _1<S # i--, (loop until i = -1)
- ] SS
- 0 s! lm
- lSx s.
- l!p
- [ d 1+* 2/ ] ST # top -> triangle(top)
- [ lv- l|x lTx ] sW # weight function: top -> abs(top - v)
- [ l@ ] SU
- ls ln/d1+ # (mean+1) mean
- sv 0 s! lm lSx s. # run S with v = mean+1
- l! s@ # store result in @
- sv 0 s! lm lSx # run S with v = mean
- l!d l@r >U p # S(m+1) < S(m), U will push S(m+1), else S(m) on top
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement