Guest User

Untitled

a guest
Mar 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. 12 = 2 * 2 * 3 -> 3 * 3 * 3 = 27
  2.  
  3. 1 -> 1
  4. 2 -> 3
  5. 3 -> 3
  6. 4 -> 9
  7. 5 -> 5
  8. 6 -> 9
  9. 7 -> 7
  10. 8 -> 27
  11. 9 -> 9
  12. 10 -> 15
  13. 11 -> 11
  14. 12 -> 27
  15. 13 -> 13
  16. 14 -> 21
  17. 15 -> 15
  18. 16 -> 81
  19. 17 -> 17
  20. 18 -> 27
  21. 19 -> 19
  22. 20 -> 45
  23. 21 -> 21
  24. 22 -> 33
  25. 23 -> 23
  26. 24 -> 81
  27. 25 -> 25
  28. 26 -> 39
  29. 27 -> 27
  30. 28 -> 63
  31. 29 -> 29
  32.  
  33. 3/2
  34.  
  35. 3/2
  36. / Replace a factor of
  37. 2 2
  38. 3 with 3
  39. {implicit: repeat until no more replacements are possible}
  40.  
  41. Ò1~P
  42.  
  43. Ò Compute the prime factorization of the input.
  44. 1~ Perform bitwise OR with 1, making the only even prime (2) odd (3).
  45. P Take the product of the result.
  46.  
  47. until odd$(*3).(`div`2)
  48.  
  49. odd`until`x->div(x*3)2
  50.  
  51. f=x=>x%2?x:f(x*1.5)
  52.  
  53. #//.x_?EvenQ:>3x/2&
  54.  
  55. {{({}[()]<([({})]()<({}{})>)>)}{}([{}]()){{}((({})){}{})<>}<>}<>({}({}){}())
  56.  
  57. Yf1Z|p
  58.  
  59. Yf % Prime factors
  60.  
  61. [2 2 2 3]
  62.  
  63. 1Z| % Bitwise OR with 1
  64.  
  65. [3 3 3 3]
  66.  
  67. p % Product
  68.  
  69. 81
  70.  
  71. Yfto~+p
  72.  
  73. ÒDÈ+P
  74.  
  75. Ò # push list of prime factors of input
  76. D # duplicate
  77. È # check each factor for evenness (1 if true, else 0)
  78. + # add list of factors and list of comparison results
  79. P # product
  80.  
  81. 2/S 3
  82. o@i
  83.  
  84. 2 Push 2 (irrelevant).
  85. / Reflect to SE. Switch to Ordinal.
  86. i Read all input as a string.
  87. The IP bounces up and down, hits the bottom right corner and turns around,
  88. bounces down again.
  89. i Try to read more input, but we're at EOF so this pushes an empty string.
  90. / Reflect to W. Switch to Cardinal.
  91. 2 Push 2.
  92. The IP wraps around to the last column.
  93. 3 Push 3.
  94. S Implicitly discard the empty string and convert the input string to the integer
  95. value it contains. Then replace the divisor 2 with the divisor 3 in the input.
  96. This works by multiplying the value by 3/2 as long as it's divisible by 2.
  97. / Reflect to NW. Switch to Ordinal.
  98. Immediately bounce off the top boundary. Move SW.
  99. o Implicitly convert the result to a string and print it.
  100. Bounce off the bottom left corner. Move NE.
  101. / Reflect to S. Switch to Cardinal.
  102. @ Terminate the program.
  103.  
  104. Æf3»P
  105.  
  106. Æf3»P Main Link, argument is z
  107. Æf Prime factors
  108. 3» Takes maximum of 3 and the value for each value in the array
  109. P Takes the product of the whole thing
  110.  
  111. *^1.5/PQ2
  112.  
  113. .+
  114. $*
  115. +`^(1+)1$
  116. $&$1
  117. 1
  118.  
  119. ~×₂×₃↰|
  120.  
  121. ~×₂×₃↰| original program
  122. ?~×₂×₃↰.|?. with implicit input (?) and output (.) added
  123.  
  124. ?~×₂ input "un-multiplied" by 2
  125. ×₃ multiplied by 3
  126. ↰ recursion
  127. . is the output
  128. | or (in case the above fails, meaning that the input
  129. cannot be "un-multiplied" by 2)
  130. ?. the input is the output
  131.  
  132. [:*/q:+2=q:
  133.  
  134. (+2&=)&.q:
  135.  
  136. (2&={,&3)"+&.q:
  137.  
  138. (2&={,&3)"+&.q:
  139. &. "under"; applies the verb on the right, then the left,
  140. then the inverse of the right
  141. q: prime factors
  142. ( )"+ apply inside on each factor
  143. ,&3 pair with three: [factor, 3]
  144. 2&= equality with two: factor == 2
  145. { list selection: [factor, 3][factor == 2]
  146. gives us 3 for 2 and factor for anything else
  147. &.q: under prime factor
  148.  
  149. *F+1.|R1P
  150.  
  151. *F+1.|R1P
  152. P prime factorization
  153. .|R1 bitwise OR each element with 1
  154. *F+1 product
  155.  
  156. k ®w3Ã×
  157.  
  158. k ® w3Ã ×
  159. Uk mZ{Zw3} r*1
  160. U # (input)
  161. k m # for every prime factor
  162. Z{Zw3} # replace it by the maximum of itself and 3
  163. r*1 # output the product
  164.  
  165. k mw3 ×
  166.  
  167. k mw3 ×
  168.  
  169. k // Factorize the input.
  170. mw3 // Map each item X by taking max(X, 3).
  171. × // Take the product of the resulting array.
  172. // Implicit: output result of last expression
  173.  
  174. rimf2Zer:*
  175.  
  176. ri e# Read integer: | 28
  177. mf e# Prime factors: | [2 2 7]
  178. 2 e# Push 2: | [2 2 7] 2
  179. Z e# Push 3: | [2 2 7] 2 3
  180. er e# Replace: | [3 3 7]
  181. :* e# Product: | 63
  182.  
  183. x=gmp::factorize(scan());x[x==2]=3;prod(x)
  184.  
  185. P1.|B
  186.  
  187. &>:2%!#v_.@
  188. ^*3/2 <
  189.  
  190. & - take in input and add it to the stack
  191. > - move right
  192. : - duplicate the top of the stack
  193. 2 - add two to the stack
  194. % - pop 2 and the input off the stack and put input%2 on the stack
  195. ! - logical not the top of the stack
  196. # - jump over the next command
  197. _ - horizontal if, if the top of the stack is 0 (i.e. input%2 was non zero) go
  198. right, else go left
  199.  
  200. If Zero:
  201. . - output the top of the stack
  202. @ - end code
  203.  
  204. If Not Zero:
  205. v - move down
  206. < - move left
  207. 2 - add 2 the top of the stack
  208. / - pop top two, add var/2 to the stack
  209. 3 - add 3 to stack
  210. * - pop top two, add var*3 to the stack
  211. ^ - move up
  212. > - move right (and start to loop)
  213.  
  214. w⌠i1|ⁿ⌡Mπ
  215.  
  216. w⌠i1|ⁿ⌡Mπ
  217. w factor into [prime, exponent] pairs
  218. ⌠i1|ⁿ⌡M for each pair:
  219. i flatten
  220. 1| prime | 1 (bitwise OR)
  221. ⁿ raise to exponent
  222. π product
  223.  
  224. f(n)=if(n%2,n,f(3*n/2))
  225.  
  226. n->n*1.5^valuation(n,2)
Add Comment
Please, Sign In to add comment