Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. n r(n)
  2. -- ------
  3. 1 1/1
  4. 2 1/2
  5. 3 2/1
  6. 4 1/3
  7. 5 3/2
  8. 6 2/3
  9. 7 3/1
  10. 8 1/4
  11. 9 4/3
  12. 10 3/5
  13. 11 5/2
  14. 12 2/5
  15. 13 5/3
  16. 14 3/4
  17. 15 4/1
  18. 16 1/5
  19. 17 5/4
  20. 18 4/7
  21. 19 7/3
  22. 20 3/8
  23. 50 7/12
  24. 100 7/19
  25. 1000 11/39
  26.  
  27. 3ẋḶŒpḄċ
  28. ’Ç”/⁸Ç
  29.  
  30. 3ẋḶŒpḄċ
  31. 3ẋ 3, repeated a number of times equal to {the argument}
  32. Ḷ Map 3 to [0, 1, 2]
  33. Œp Take the cartesian product of that list
  34. Ḅ Convert binary (or in this case hyperbinary) to a number
  35. ċ Count number of occurrences of {the argument} in the resulting list
  36.  
  37. ’Ç”/⁸Ç
  38. ’Ç Helper function (Ç), run on {the input} minus 1 (‘)
  39. ”/ {Output that to stdout}; start again with the constant '/'
  40. ⁸Ç {Output that to stdout}; then run the helper function (Ç) on the input (⁸)
  41.  
  42. 1_{_@_2$%2*-+}ri*'/
  43.  
  44. 1 / (2 * floor(s/t) + 1 - s/t)
  45. = t / (2 * t * floor(s/t) + t - s)
  46. = t / (2 * (s - s%t) + t - s)
  47. = t / (s + t - 2 * (s % t))
  48.  
  49. gcd(t, s + t - 2 * (s % t))
  50. = gcd(t, s - 2 * (s % t))
  51. = gcd(t, -(s % t))
  52. = 1
  53.  
  54. 1_ e# s=1, t=1
  55. { e# Loop...
  56. _@_2$%2*-+ e# s, t = t, s + t - 2 * (s % t)
  57. }
  58. ri* e# ...n times
  59. '/ e# Separate s and t with a /
  60.  
  61. (s#t)0=show s++'/':show t
  62. (s#t)n=t#(s+t-2*mod s t)$n-1
  63. 1#1
  64.  
  65. s=(!!)(1:1:f 0)
  66. f n=s n+s(n+1):s(n+1):(f$n+1)
  67. r n=show(s n)++'/':(show.s$n+1)
  68.  
  69. r n=show>>=[s!!n,'/',s!!(n+1)]
  70.  
  71. L‘Hị⁸Sṭ
  72. 1Ç¡ṫ-j”/
  73.  
  74. 1Ç¡ṫ-j”/ Main link. Argument: n
  75.  
  76. 1 Set the return value to 1.
  77. Ç¡ Apply the helper link n times.
  78. ṫ- Tail -1; extract the last two items.
  79. j”/ Join, separating by a slash.
  80.  
  81.  
  82. L‘Hị⁸Sṭ Helper link. Argument: A (array)
  83.  
  84. L Get the length of A.
  85. ‘ Add 1 to compute the next index.
  86. H Halve.
  87. ị⁸ Retrieve the item(s) of A at those indices.
  88. If the index in non-integer, ị floors and ceils the index, then retrieves
  89. the items at both indices.
  90. S Compute the sum of the retrieved item(s).
  91. ṭ Tack; append the result to A.
  92.  
  93. XX‚¹GÂ2£DO¸s¦ìì¨}R2£'/ý
  94.  
  95. XX‚ # push [1,1]
  96. ¹G } # input-1 times do
  97. Â # bifurcate
  98. 2£ # take first 2 elements of reversed list
  99. DO¸ # duplicate and sum 1st copy, s(n)+s(n+1)
  100. s¦ # cut away the first element of 2nd copy, s(n)
  101. ìì # prepend both to list
  102. ¨ # remove last item in list
  103. R2£ # reverse and take the first 2 elements
  104. '/ý # format output
  105. # implicitly print
  106.  
  107. FT+"@:qtPXnosV47]xhh
  108.  
  109. FT+ % Implicitly take input n. Add [0 1] element-wise. Gives [n n+1]
  110. " % For each k in [n n+1]
  111. @:q % Push range [0 1 ... k-1]
  112. tP % Duplicate and flip: push [k-1 ... 1 0]
  113. Xn % Binomial coefficient, element-wise. Gives an array
  114. os % Number of odd entries in that array
  115. V % Convert from number to string
  116. 47 % Push 47, which is ASCII for ''
  117. ] % End for each
  118. x % Remove second 47
  119. hh % Concatenate horizontally twice. Automatically transforms 47 into ''
  120. % Implicitly display
  121.  
  122. x,s=input(),[1,1]
  123. for i in range(x):s+=s[i]+s[i+1],s[i+1]
  124. print`s[x-1]`+"/"+`s[x]`
  125.  
  126. s=lambda x:int(x<1)or x%2 and s(x/2)or s(-~x/2)+s(~-x/2)
  127. lambda x:`s(x)`+"/"+`s(x+1)`
  128.  
  129. s=lambda x:x<1 or x%2 and s(x/2)or s(-~x/2)+s(~-x/2)
  130. lambda x:`s(x)`+"/"+`s(x+1)`
  131.  
  132. f=(i,n=0,d=1)=>i?f(i-1,d,n+d-n%d*2):n+'/'+d
  133.  
  134. 11,`│;a%τ@-+`nk'/j
  135.  
  136. 11,`│;a%τ@-+`nk'/j
  137. 11 push 1, 1
  138. ,`│;a%τ@-+`n do the following n times (where n is the input):
  139. stack: [t s]
  140. │ duplicate the entire stack ([t s t s])
  141. ; dupe t ([t t s t s])
  142. a invert the stack ([s t s t t])
  143. % s % t ([s%t s t t])
  144. τ multiply by 2 ([2*(s%t) s t t])
  145. @- subtract from s ([s-2*(s%t) s t])
  146. + add to t ([t+s-2*(s%t) t])
  147. in effect, this is s,t = t,s+t-2*(s%t)
  148. k'/j push as a list, join with "/"
  149.  
  150. 1i:"tt@TF-)sw@)v]tGq)V47bG)Vhh
  151.  
  152. f=function(n)ifelse(n<3,1,ifelse(n%%2,f(n/2-1/2)+f(n/2+1/2),f(n/2)))
  153. g=function(n)f(n)/f(n+1)
  154.  
  155. define(s,`ifelse($1,1,1,eval($1%2),0,`s(eval($1/2))',`eval(s(eval(($1-1)/2))+s(eval(($1+1)/2)))')')define(r,`s($1)/s(eval($1+1))')
  156.  
  157. ->n{s=t=1;n.times{s,t=t,s+t-2*(s%t)};"#{s}/#{t}"}
  158.  
  159. &01$n"/"on;
  160. &?!:@}:{:@+@%2*-&1-:
  161.  
  162. function f(i)S=[1 1];for(j=1:i/2)S=[S S(j)+S(j+1) (j+1)];end;printf("%d/%d",S(i),S(i+1));end
  163.  
  164. n=>{Func<int,int>s=_=>_;s=m=>1==m?m:s(m/2)+(0==m%2?0:s(m/2+1));return$"{s(n)}/{s(n+1)}";};
  165.  
  166. n =>
  167. {
  168. Func<int,int> s = _ => _; // s needs to be set to use recursively. _=>_ is the same byte count as null and looks cooler.
  169. s = m =>
  170. 1 == m ? m // s(1) = 1
  171. : s(m/2) + (0 == m%2 ? 0 // s(m) = s(m/2) for even
  172. : s(m/2+1)); // s(m) = s(m/2) + s(m/2+1) for odd
  173. return $"{s(n)}/{s(n+1)}";
  174. };
  175.  
  176. ([,'/',])&":&([:+/2|]!&i.-)>:
  177.  
  178. f =: ([,'/',])&":&([:+/2|]!&i.-)>:
  179. f 1
  180. 1/1
  181. f 10
  182. 3/5
  183. f 50
  184. 7/12
  185. f 100x
  186. 7/19
  187. f 1000x
  188. 11/39
  189.  
  190. (s={1,1};n=1;a=AppendTo;t=ToString;Do[a[s,s[[n]]+s[[++n]]];a[s,s[[n]]],#];t@s[[n-1]]<>"/"<>t@s[[n]])&
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement