Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. Inputs Output
  2.  
  3. 1 1 1 1
  4. 3 4 5 1.25
  5. 42 42 3.14 ≈ 6.9476
  6. 14 6 12 1.575
  7. 6 12 14 1.575
  8. 0.5 0.6 0.7 ≈ 1.09375
  9.  
  10. S_Ḥ⁸÷P
  11.  
  12. Implicit argument [a, b, c].
  13. S Take the sum, a+b+c or 2*s
  14. Ḥ Take the double, [2*a, 2*b, 2*c].
  15. _ Vectorized subtract, giving us [2*(s-a), 2*(s-b), 2*(s-c)].
  16. ⁸÷ Vectorized divide the initial left argument, the input [a, b, c],
  17. by [2*(s-a), 2*(s-b), 2*(s-c)].
  18. P Take the product giving us the aspect ratio, abc/8(s-a)(s-b)(s-c).
  19.  
  20. SH_÷@HP
  21.  
  22. S÷_2Pİ
  23.  
  24. S÷_2Pİ Main link. Argument: [a, b, c]
  25.  
  26. S Sum; compute 2s := a + b + c.
  27. ÷ Divide; yield [2s ÷ a, 2s ÷ b, 2s ÷ c].
  28. _2 Subtract 2; yield [2s ÷ a - 2, 2s ÷ b - 2, 2s ÷ c - 2].
  29. P Product; yield (2s ÷ a - 2)(2s ÷ b - 2)(2s ÷ c - 2).
  30. İ Invert; yield 1 ÷ (2s ÷ a - 2)(2s ÷ b - 2)(2s ÷ c - 2).
  31.  
  32. a=>b=>c=>a*b*c/(b+c-a)/(a+c-b)/(a+b-c)
  33.  
  34. tsGE-/p
  35.  
  36. t % Take input implicitly. Duplicate
  37. % STACK: [3 4 5], [3 4 5]
  38. s % Sum of array
  39. % STACK: [3 4 5], 12
  40. G % Push input again
  41. % STACK: [3 4 5], 12, [3 4 5]
  42. E % Multiply by 2, element-wise
  43. % STACK: [3 4 5], 12, [6 8 10]
  44. - % Subtract, element-wise
  45. % STACK: [3 4 5], [6 4 2]
  46. / % Divide, element-wise
  47. % STACK: [0.5 1 2.5]
  48. p % Product of array. Implicitly display
  49. % STACK: 1.25
  50.  
  51. O¹·-¹/P
  52.  
  53. O # sum input
  54. ¹ # push input again
  55. · # multiply by 2
  56. - # subtract from sum
  57. ¹/ # divide by input
  58. P # product
  59.  
  60. x=scan();prod(x/(sum(x)-2*x))
  61.  
  62. (a#b)c=a*b*c/(b+c-a)/(a+c-b)/(a+b-c)
  63.  
  64. p=product
  65. f v=p v/p((sum v-).(2*)<$>v)
  66.  
  67. @(v)prod(v./(sum(v)-2*v))
  68.  
  69. sum(v) = 3+4+5 = 12
  70. sum(v)-2*v = 12 - 2*[3,4,5] = 12 - [6,8,10] = [6,4,2]
  71. v./(sum(v)-2*v)) = [3,4,5] ./ [6,4,2] = [0.5,1,2.5]
  72. prod(v./(sum(v)-2*v)) = 0.5 * 1 * 2.5 = 1.25
  73.  
  74. 1##&@@(#/(Tr@#-2#))&
  75.  
  76. fun a b c->a*.b*.c/.(b+.c-.a)/.(a+.c-.b)/.(a+.b-.c)
  77.  
  78. @@@prod[#0#1#2/1- +#1#0#2/1- +#2#0#1/1- +#2#1#0]
  79.  
  80. (((@@@prod[#0#1#2/1* * - +#1#0#2- +#2#0#1- +#2#1#0])3)4)5
  81.  
  82. (a,b,c)=>product([a,b,c,1/(b+c-a),1/(a+c-b),1/(a+b-c)])
  83.  
  84. ;Σ♀/♂¬πì
  85.  
  86. Implicit input [a, b, c].
  87. ; Duplicate [a, b, c].
  88. Σ sum() to get twice the semiperimeter, 2*s.
  89. ♀/ Vectorized divide 2*s by [a, b, c] to get [2*s/a, 2*s/b, 2*s/c].
  90. ♂¬ Vectorized subtract 2 to get [2*s/a-2, 2*s/b-2, 2*s/c-2].
  91. π Get the product of the above to get 8*(s/a-1)*(s/b-1)*(s/c-1).
  92. This is the same as 8(s-a)(s-b)(s-c)/abc.
  93. ì Invert to get the aspect ratio, abc/8(s-a)(s-b)(s-c).
  94. Implicit return.
  95.  
  96. (a,b,c)->a*b*c/(b+c-a)/(a-b+c)/(a+b-c)
  97.  
  98. public class Pcg101234 {
  99. interface F {
  100. double f(double a, double b, double c);
  101. }
  102. public static void main(String[] args) {
  103. F f = (a,b,c)->a*b*c/(b+c-a)/(a-b+c)/(a+b-c);
  104.  
  105. System.out.println(f.f(1,1,1));
  106. System.out.println(f.f(3,4,5));
  107. System.out.println(f.f(42,42,3.14));
  108. System.out.println(f.f(14,6,12));
  109. System.out.println(f.f(6,12,14));
  110. System.out.println(f.f(0.5,0.6,0.7));
  111. }
  112. }
  113.  
  114. 1.0
  115. 1.25
  116. 6.947606226693615
  117. 1.575
  118. 1.575
  119. 1.09375
  120.  
  121. p%/*-)/+i
  122. 2%
  123.  
  124. print(
  125. 1 / fold(
  126. multiply,
  127. fold(add, i) / i - 2
  128. )
  129. )
  130.  
  131. print(1 / product(sum(i) / i - 2))
  132.  
  133. Os/ÍPz
  134.  
  135. 5k?dsa?dsb?dsc++2/sslalblc**lsla-lslb-lslc-8***/p
  136.  
  137. 5k # Set the output precision to 5 digits after the decimal
  138. ?dsa # Prompt for first input value on first line, duplicate it, and then store it in register `a`
  139. ?dsb # Prompt for second input, duplicate it, and store it in register `b`
  140. ?dsc # Prompt for third input, duplicate it, and store it in register `c`
  141. ++2/ss # Sum up the 3 values on the main stack, then divide sum by 2 and store the result in register `s`
  142. lalblc** # Copy all three values from registers `a`,`b`,`c` onto the main stack, find their product, and push result to top of main stack
  143. lsla- # Copy value from register `s` onto main stack, subtract register `a`'s value from it, and push result to main stack
  144. lslb- # Copy value from register `s` onto main stack, subtract register `b`'s value from it, and push result to main stack
  145. lslc- # Copy value from register `s` onto main stack, subtract register `c`'s value from it, and push result to main stack
  146. 8*** # Find the product of the top three values and 8 and then push the result to main stack
  147. /p # Divide the second to top value (a*b*c) by the top of stack value (8*(s-a)*(s-b)*(s-c)), push the result to the main stack, and then output the result to STDOUT
  148.  
  149. prod(Ans)/prod(sum(Ans)-2Ans
  150.  
  151. ->a,b,c{a*b*c/(b+c -a)/(a+c -b)/(a+b -c)}
  152.  
  153. def f(x,y,z):s=x+y+z;return 1/((s/x-2)*(s/y-2)*(s/z-2))
  154.  
  155. : p 3 fpick ;
  156. : T p p p ;
  157. : f 0 s>f T f- f+ f- T f+ f- f* T f- f- f* 1/f f* f* f* ;
  158.  
  159. 3 fpick takes the 3rd element (0-indexed) and pushes a copy
  160. Used to copy parameters on the stack over another number 'x' ( a b c x -> a b c x a b c )
  161. : f3p 3 fpick 3 fpick 3 fpick ;
  162.  
  163. : f define a function f
  164. 0 s>f f3p f- f+ f- push a zero, copy params, compute 0-(a+b-c)
  165. the zero allows me to copy (I need an 'x' to jump over)
  166. f3p f+ f- f* copy params and compute -(b+c-a), multiply by previous result
  167. the negatives miraculously cancel
  168. f3p f- f- f* copy and compute (a+c-b), multiply by previous result
  169. 1/f f* f* f* ; take the reciprocal and multiply by a*b*c
  170. the result is left on the floating point stack
  171.  
  172. @*$1/@*{@+$1-2.*$1}
  173.  
  174. Π$1/Π{Σ$1-2.*$1}
  175.  
  176. Function r(a,b,c)
  177. s=(a+b+c)/2:r=(a*b*c)/(8*(s-a)*(s-b)*(s-c))
  178. End Function
  179.  
  180. void ar(double a,double b,double c)=>Console.Write(a*b*c/(b+c-a)/(a+c-b)/(a+b-c));
  181.  
  182. ar(42, 42, 3.14);
  183.  
  184. 1QFQsR/tt)B/
  185.  
  186. {(*/x)%8*/-x-+/x%2}
  187.  
  188. a,b,c=...print(a*b*c/(b+c-a)/(a+c-b)/(a+b-c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement