Guest User

Untitled

a guest
Oct 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. p([1,0,2]) -> [33,0,67] or [34,0,66]
  2. p([1000,1000]) -> [50,50]
  3. p([1,1,2,4]) -> [12,12,25,51] or [13,12,25,50] or [12,13,25,50] or [12,12,26,50]
  4. p([0,0,0,5,0]) -> [0,0,0,100,0]
  5.  
  6. +⍣¯1∘⌊100×+÷+/
  7.  
  8. {+⍣¯1⌊100×+⍵÷+/⍵}
  9.  
  10. ⍝ Sample input: 1 1 2 4
  11. + ⍝ Cumulative sum of input. (1 2 4 8)
  12. +/ ⍝ Sum of input. (8)
  13. ÷ ⍝ Divide the first result by the second. (0.125 0.25 0.5 1)
  14. 100× ⍝ Multiply each quotient by 100. (12.5 25 50 100)
  15. ⌊ ⍝ Round the products down to the nearest integer... (12 25 50 100)
  16. ∘ ⍝ and ...
  17. ⍣¯1 ⍝ apply the inverse of...
  18. +/ ⍝ the cumulative sum. (12 13 25 50)
  19.  
  20. ΔList(augment({0},int(cumSum(ᴇ2Ans/sum(Ans
  21.  
  22. ΔList(augment({0},int(cumSum(Ans/sum(Ans%
  23.  
  24. int(ᴇ2Ans/sum(Ans
  25. Ans+(ᴇ2-sum(Ans)≥cumSum(1 or Ans
  26.  
  27. sum(Ans ; 8
  28. int(ᴇ2Ans/ ; {12,12,25,50}
  29.  
  30. 1 or Ans ; {1,1,1,1}
  31. cumSum( ; {1,2,3,4}
  32. ᴇ2-sum(Ans) ; 1
  33. ≥ ; {1,0,0,0}
  34. Ans+ ; {13,12,25,50}
  35.  
  36. {_:e2:+f/_:+100-Xb.+}
  37.  
  38. _ e# Push a copy of the input.
  39. :e2 e# Apply e2 to each integer, i.e., multiply by 100.
  40. e# Swap the result with the original.
  41. :+ e# Add all integers from input.
  42. f/ e# Divide the product by the sum. (integer division)
  43. _:+ e# Push the sum of copy.
  44. 100- e# Subtract 100. Let's call the result d.
  45. Xb e# Convert to base 1, i.e., push an array of |d| 1's.
  46. .+ e# Vectorized sum; increment the first |d| integers.
  47.  
  48. (s=Floor[100#/Tr@#];s[[;;100-Tr@s]]++;s)&
  49.  
  50. f=.3 :'+/^:_1<.100*(+/%+/)y'
  51.  
  52. f 1 1 2 4
  53. 12 13 25 50
  54.  
  55. f=.3 :0
  56. p=.<.100*y%+/y
  57. r=.100-+/p
  58. p+((r$1),(#p-r)$0)/::p
  59. )
  60.  
  61. f 1 0 2
  62. 33 0 67
  63.  
  64. f 1000 1000
  65. 50 50
  66.  
  67. f 1 1 2 4
  68. 12 12 25 51
  69.  
  70. f 0 0 0 5 0
  71. 0 0 0 100 0
  72.  
  73. f 16 16 16 16 16 16
  74. 17 17 17 17 16 16
  75.  
  76. f 0 100 5 0 7 1
  77. 0 89 4 0 7 0
  78.  
  79. 33 0 66 sums to 99
  80. 100 - 99 = 1
  81. 1x1 , (3-1)x0 = 1, 0 0
  82. sorted mask = 0 0 1
  83.  
  84. 33 0 66
  85. 0 0 1
  86. -------
  87. 33 0 67
  88.  
  89. a=>(e=0,a.map(c=>((e+=(f=c/a.reduce((c,d)=>c+d)*100)%1),f+(e>.999?(e--,1):0)|0)))
  90.  
  91. p a=[div(100*x)$sum a|x<-a]
  92.  
  93. *Main> p([1,0,2])
  94. [33,0,66]
  95. *Main> p([1000,1000])
  96. [50,50]
  97. *Main> p([1,1,2,4])
  98. [12,12,25,50]
  99. *Main> p([0,0,0,5,0])
  100. [0,0,0,100,0]
  101.  
  102. p xs=[div(x*100)tot|x<-xs]where tot=sum xs
  103.  
  104. @(x)diff(ceil([0,cumsum(100*x/sum(x))]))
  105.  
  106. let a=|c:Vec<_>|c.iter().map(|m|m*100/c.iter().fold(0,|a,x|a+x)).collect::<Vec<_>>();
  107.  
  108. perl -p percent.pl <<< "1 0 2"
  109.  
  110. s%d+%-$-+($-=$a+=$&*100/eval y/ /+/r)%eg
  111.  
  112. 0;+÷S×ȷ2ḞI
Add Comment
Please, Sign In to add comment