Guest User

Untitled

a guest
Oct 20th, 2017
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. A(0,n) = n+1
  2. A(m,0) = A(m-1,1)
  3. A(m,n) = A(m-1,A(m,n-1))
  4.  
  5. A | n=0 1 2 3 4 5 6 7 8 9 10
  6. -----+-----------------------------------------------------------------
  7. m=0 | 1 2 3 4 5 6 7 8 9 10 11
  8. 1 | 2 3 4 5 6 7 8 9 10 11 12
  9. 2 | 3 5 7 9 11 13 15 17 19 21 23
  10. 3 | 5 13 29 61 125 253 509 1021 2045 4093 8189
  11. 4 | 13 65533 big really big...
  12.  
  13. DaGHR?atG?aGtHH1GhH
  14.  
  15. $ time pyth -c "DaGHR?atG?aGtHH1GhH ;a 3 10"
  16. 8189
  17.  
  18. real 0m0.092s
  19. user 0m0.088s
  20. sys 0m0.000s
  21.  
  22. DaGH def a(G,H):
  23. R return
  24. ? G (if G:
  25. atG (a(G-1,
  26. ? H (if H:
  27. aGtH a(G,H-1)
  28. 1 else:1)
  29. hH else:H+1)
  30.  
  31. a 0=(1+)
  32. a m=(iterate(a$m-1)1!!)
  33.  
  34. {1$1>{1){1$(A}*;}{+)}if}:A;
  35.  
  36. { # Function boilerplate
  37. 1$ # Get a copy of m: stack holds m n m
  38. 1>{ # (Optimisation): if m is greater than 1
  39. 1 # Take this as the value of A(m, -1)
  40. ){ # Repeat n+1 times:
  41. # Stack: m A(m, i-1)
  42. 1$( # Stack: m m-1 A(m, i-1)
  43. A # Stack: m A(m, i)
  44. }*
  45. ; # Lose that unwanted copy of m
  46. }{ # Else
  47. +) # A(m in {0, 1}, n) = m + n + 1
  48. }if
  49. }:A; # Function boilerplate
  50.  
  51. A=lambda m,n:m and A(m-1,n<1or A(m,n-1))or-~n
  52.  
  53. A=lambda m,n:n+(m<1or A(m-1,n<1or A(m,n-1))-n)
  54.  
  55. A(m,n){return!m?n+1:A(m-1,n?A(m,n-1):1);}
  56.  
  57.  
  58. int main()
  59. {
  60. int m,n;
  61. for(m = 0; m <= 3; m++)
  62. for(n = 0; n <= 10; n++)
  63. printf("%d %d %dn", m,n,A(m,n));
  64. return 0;
  65. }
  66.  
  67. f=(m,n)=>m?f(m-1,!n||f(m,n-1)):n+1
  68.  
  69. f(3,2) // returns 29
  70.  
  71. ($:^:(<:@[`]`1:)^:(0<[)>:)
  72.  
  73. Ack 0 n = n+1
  74. Ack m n = Iter (Ack (m-1)) n
  75. Iter f 0 = f 1
  76. Iter f n = f (Iter f (n-1))
  77.  
  78. ( >:) NB. increment n
  79. ^:(0<[) NB. if m=0, do nothing to n+1; else:
  80. ^: NB. iterate...
  81. ($: ) NB. self ($: is recursion)
  82. (<:@[ ) NB. with left arg m-1
  83. `] NB. n+1 times
  84. `1: NB. starting on 1
  85.  
  86. 3 ($:^:(<:@[`]`1:)^:(0<[)>:) 3
  87. 61
  88. ack =: ($:^:(<:@[`]`1:)^:(0<[)>:)
  89. (i.4) ack"0 table (i.11)
  90. +-----+------------------------------------------+
  91. |ack"0|0 1 2 3 4 5 6 7 8 9 10|
  92. +-----+------------------------------------------+
  93. |0 |1 2 3 4 5 6 7 8 9 10 11|
  94. |1 |2 3 4 5 6 7 8 9 10 11 12|
  95. |2 |3 5 7 9 11 13 15 17 19 21 23|
  96. |3 |5 13 29 61 125 253 509 1021 2045 4093 8189|
  97. +-----+------------------------------------------+
  98. 6!:2 '3 ($:^:(<:@[`]`1:)^:(0<[)>:) 10' NB. snugly fits in a minute
  99. 58.5831
  100.  
  101. (0&<~(<:@#~$:/@,1:^:)>:)
  102.  
  103. nat_rec _ S(fun _ b n=>nat_iter(S n)b 1)
  104.  
  105. Welcome to Coq 8.4pl6 (November 2015)
  106.  
  107. Coq < Compute nat_rec _ S(fun _ b n=>nat_iter(S n)b 1) 3 10.
  108. = 8189
  109. : nat
  110.  
  111. 00000000: 1607 2d88 072f 68 ..-../h
  112.  
  113. 000101100000011100101101100010000000011100101111011010
  114.  
  115. (define(a m n)(if(= m 0)(+ n 1)(a(- m 1)(if(= n 0)1(a m(- n 1))))))
  116.  
  117. 0~a~n_:=n+1
  118. m_~a~n_:=a[m-1,If[n<1,1,a[m,n-1]]]
  119.  
  120. $RecursionLimit = Infinity
  121.  
  122. A=(m,n)=>m?A(m-1,n?A(m,n-1):1):n+1
  123.  
  124. (d A
  125. (q( (m n)
  126. (i m
  127. (i n
  128. (A (s m 1)
  129. (A m
  130. (s n 1)
  131. )
  132. )
  133. (A (s m 1)
  134. 1
  135. )
  136. )
  137. (s n
  138. (s 0 1)
  139. )
  140. )
  141. ) )
  142. )
  143.  
  144. func (m,n int)int{r:=0
  145. switch{case m==0&&n!=0:r=n+1
  146. case m!=0&&n==0:r=a(m-1,1)
  147. case m!=0&&n!=0:r=a(m-1,a(m,n-1))}
  148. return r}
  149.  
  150. $ time go run ack
  151. 16381
  152. real 0m1.434s
  153. user 0m1.432s
  154. sys 0m0.004s
  155.  
  156. a::Int->Int->Int
  157. a 0 n=n+1
  158. a m 0=a (m-1) 1
  159. a m n=a (m-1) a m (n-1)
  160.  
  161. a=function(m,n){"if"(m,a(m-1,"if"(n,a(m,n-1),1)),n+1)}
  162.  
  163. > a(3,8)
  164. [1] 2045
  165.  
  166. DECLARE @m INT=4,@n INT=1;WITH R AS(SELECT 2 C, 1 X UNION ALL SELECT POWER(2,C),X+1FROM R)SELECT IIF(@m=0,@n+1,IIF(@m=1,@n+2,IIF(@m=2,2*@n+3,IIF(@m=3,POWER(2,@n+3)-3,IIF(@m=4,(SELECT TOP(1)C FROM R WHERE x= @n+3)-3,-1)))))
  167.  
  168. M?GgtG?HgGtH1hH
  169.  
  170. iiRuldr%l%lR$d%rd:u%d:%+uRu:ro
  171.  
  172. >:@]`(1$:~<:@[)`(<:@[$:[$:_1+])@.(0>.[:<:@#.,&*)M.
  173.  
  174. A=:>:@]`(1$:~<:@[)`(<:@[$:[$:_1+])@.(0>.[:<:@#.,&*)M.
  175. timespacex 'res=:(i.4) A"0 table (i.11)'
  176. 0.0336829 3.54035e6
  177. res
  178. ┌───┬──────────────────────────────────────────┐
  179. │A"0│0 1 2 3 4 5 6 7 8 9 10│
  180. ├───┼──────────────────────────────────────────┤
  181. │0 │1 2 3 4 5 6 7 8 9 10 11│
  182. │1 │2 3 4 5 6 7 8 9 10 11 12│
  183. │2 │3 5 7 9 11 13 15 17 19 21 23│
  184. │3 │5 13 29 61 125 253 509 1021 2045 4093 8189│
  185. └───┴──────────────────────────────────────────┘
  186.  
  187. {⍺=0:⍵+1⋄⍵=0:1∇⍨⍺-1⋄(⍺-1)∇⍺∇⍵-1}
  188.  
  189. $Y1%j:j.0=m:2%k:k.0=n:m.n.>[k.1+!|m.n.<[#Y,j.1-,1;|m.n.*0=[#Y,j.1-,#Y,j.,k.1+;;]]]@
  190.  
  191. import java.math.*;class a{BigInteger A(BigInteger b,BigInteger B){if(b.equals(BigInteger.ZERO))return B.add(BigInteger.ONE);if(B.equals(BigInteger.ZERO))return A(b.subtract(BigInteger.ONE),BigInteger.ONE);return A(b.subtract(BigInteger.ONE),A(b,B.subtract(BigInteger.ONE)));}}
  192.  
  193. proc A m n {expr {$m?[A [expr $m-1] [expr {$n?[A $m [expr $n-1]]:1}]]:$n+1}}
  194.  
  195. m=0, n=0, A=1, time=3.5e-5 seconds
  196. m=0, n=1, A=2, time=2e-6 seconds
  197. m=0, n=2, A=3, time=8e-6 seconds
  198. m=0, n=3, A=4, time=1e-6 seconds
  199. m=0, n=4, A=5, time=2e-6 seconds
  200. m=0, n=5, A=6, time=1e-6 seconds
  201. m=0, n=6, A=7, time=1e-6 seconds
  202. m=0, n=7, A=8, time=1e-6 seconds
  203. m=0, n=8, A=9, time=1e-6 seconds
  204. m=0, n=9, A=10, time=0.0 seconds
  205. m=0, n=10, A=11, time=1e-6 seconds
  206. m=1, n=0, A=2, time=4e-6 seconds
  207. m=1, n=1, A=3, time=6e-6 seconds
  208. m=1, n=2, A=4, time=1e-5 seconds
  209. m=1, n=3, A=5, time=1.2e-5 seconds
  210. m=1, n=4, A=6, time=1.5e-5 seconds
  211. m=1, n=5, A=7, time=2e-5 seconds
  212. m=1, n=6, A=8, time=2e-5 seconds
  213. m=1, n=7, A=9, time=2.6e-5 seconds
  214. m=1, n=8, A=10, time=3e-5 seconds
  215. m=1, n=9, A=11, time=3e-5 seconds
  216. m=1, n=10, A=12, time=3.3e-5 seconds
  217. m=2, n=0, A=3, time=8e-6 seconds
  218. m=2, n=1, A=5, time=2.2e-5 seconds
  219. m=2, n=2, A=7, time=3.9e-5 seconds
  220. m=2, n=3, A=9, time=6.3e-5 seconds
  221. m=2, n=4, A=11, time=9.1e-5 seconds
  222. m=2, n=5, A=13, time=0.000124 seconds
  223. m=2, n=6, A=15, time=0.000163 seconds
  224. m=2, n=7, A=17, time=0.000213 seconds
  225. m=2, n=8, A=19, time=0.000262 seconds
  226. m=2, n=9, A=21, time=0.000316 seconds
  227. m=2, n=10, A=23, time=0.000377 seconds
  228. m=3, n=0, A=5, time=2.2e-5 seconds
  229. m=3, n=1, A=13, time=0.000145 seconds
  230. m=3, n=2, A=29, time=0.000745 seconds
  231. m=3, n=3, A=61, time=0.003345 seconds
  232. m=3, n=4, A=125, time=0.015048 seconds
  233. m=3, n=5, A=253, time=0.059836 seconds
  234. m=3, n=6, A=509, time=0.241431 seconds
  235. m=3, n=7, A=1021, time=0.971836 seconds
  236. m=3, n=8, A=2045, time=3.908884 seconds
  237. m=3, n=9, A=4093, time=15.926341 seconds
  238. m=3, n=10, A=8189, time=63.734713 seconds
Add Comment
Please, Sign In to add comment