Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p([1,0,2]) -> [33,0,67] or [34,0,66]
- p([1000,1000]) -> [50,50]
- p([1,1,2,4]) -> [12,12,25,51] or [13,12,25,50] or [12,13,25,50] or [12,12,26,50]
- p([0,0,0,5,0]) -> [0,0,0,100,0]
- +⍣¯1∘⌊100×+÷+/
- {+⍣¯1⌊100×+⍵÷+/⍵}
- ⍝ Sample input: 1 1 2 4
- + ⍝ Cumulative sum of input. (1 2 4 8)
- +/ ⍝ Sum of input. (8)
- ÷ ⍝ Divide the first result by the second. (0.125 0.25 0.5 1)
- 100× ⍝ Multiply each quotient by 100. (12.5 25 50 100)
- ⌊ ⍝ Round the products down to the nearest integer... (12 25 50 100)
- ∘ ⍝ and ...
- ⍣¯1 ⍝ apply the inverse of...
- +/ ⍝ the cumulative sum. (12 13 25 50)
- ΔList(augment({0},int(cumSum(ᴇ2Ans/sum(Ans
- ΔList(augment({0},int(cumSum(Ans/sum(Ans%
- int(ᴇ2Ans/sum(Ans
- Ans+(ᴇ2-sum(Ans)≥cumSum(1 or Ans
- sum(Ans ; 8
- int(ᴇ2Ans/ ; {12,12,25,50}
- 1 or Ans ; {1,1,1,1}
- cumSum( ; {1,2,3,4}
- ᴇ2-sum(Ans) ; 1
- ≥ ; {1,0,0,0}
- Ans+ ; {13,12,25,50}
- {_:e2:+f/_:+100-Xb.+}
- _ e# Push a copy of the input.
- :e2 e# Apply e2 to each integer, i.e., multiply by 100.
- e# Swap the result with the original.
- :+ e# Add all integers from input.
- f/ e# Divide the product by the sum. (integer division)
- _:+ e# Push the sum of copy.
- 100- e# Subtract 100. Let's call the result d.
- Xb e# Convert to base 1, i.e., push an array of |d| 1's.
- .+ e# Vectorized sum; increment the first |d| integers.
- (s=Floor[100#/Tr@#];s[[;;100-Tr@s]]++;s)&
- f=.3 :'+/^:_1<.100*(+/%+/)y'
- f 1 1 2 4
- 12 13 25 50
- f=.3 :0
- p=.<.100*y%+/y
- r=.100-+/p
- p+((r$1),(#p-r)$0)/::p
- )
- f 1 0 2
- 33 0 67
- f 1000 1000
- 50 50
- f 1 1 2 4
- 12 12 25 51
- f 0 0 0 5 0
- 0 0 0 100 0
- f 16 16 16 16 16 16
- 17 17 17 17 16 16
- f 0 100 5 0 7 1
- 0 89 4 0 7 0
- 33 0 66 sums to 99
- 100 - 99 = 1
- 1x1 , (3-1)x0 = 1, 0 0
- sorted mask = 0 0 1
- 33 0 66
- 0 0 1
- -------
- 33 0 67
- a=>(e=0,a.map(c=>((e+=(f=c/a.reduce((c,d)=>c+d)*100)%1),f+(e>.999?(e--,1):0)|0)))
- p a=[div(100*x)$sum a|x<-a]
- *Main> p([1,0,2])
- [33,0,66]
- *Main> p([1000,1000])
- [50,50]
- *Main> p([1,1,2,4])
- [12,12,25,50]
- *Main> p([0,0,0,5,0])
- [0,0,0,100,0]
- p xs=[div(x*100)tot|x<-xs]where tot=sum xs
- @(x)diff(ceil([0,cumsum(100*x/sum(x))]))
- let a=|c:Vec<_>|c.iter().map(|m|m*100/c.iter().fold(0,|a,x|a+x)).collect::<Vec<_>>();
- perl -p percent.pl <<< "1 0 2"
- s%d+%-$-+($-=$a+=$&*100/eval y/ /+/r)%eg
- 0;+÷S×ȷ2ḞI
Add Comment
Please, Sign In to add comment