Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A(0,n) = n+1
- A(m,0) = A(m-1,1)
- A(m,n) = A(m-1,A(m,n-1))
- A | n=0 1 2 3 4 5 6 7 8 9 10
- -----+-----------------------------------------------------------------
- m=0 | 1 2 3 4 5 6 7 8 9 10 11
- 1 | 2 3 4 5 6 7 8 9 10 11 12
- 2 | 3 5 7 9 11 13 15 17 19 21 23
- 3 | 5 13 29 61 125 253 509 1021 2045 4093 8189
- 4 | 13 65533 big really big...
- DaGHR?atG?aGtHH1GhH
- $ time pyth -c "DaGHR?atG?aGtHH1GhH ;a 3 10"
- 8189
- real 0m0.092s
- user 0m0.088s
- sys 0m0.000s
- DaGH def a(G,H):
- R return
- ? G (if G:
- atG (a(G-1,
- ? H (if H:
- aGtH a(G,H-1)
- 1 else:1)
- hH else:H+1)
- a 0=(1+)
- a m=(iterate(a$m-1)1!!)
- {1$1>{1){1$(A}*;}{+)}if}:A;
- { # Function boilerplate
- 1$ # Get a copy of m: stack holds m n m
- 1>{ # (Optimisation): if m is greater than 1
- 1 # Take this as the value of A(m, -1)
- ){ # Repeat n+1 times:
- # Stack: m A(m, i-1)
- 1$( # Stack: m m-1 A(m, i-1)
- A # Stack: m A(m, i)
- }*
- ; # Lose that unwanted copy of m
- }{ # Else
- +) # A(m in {0, 1}, n) = m + n + 1
- }if
- }:A; # Function boilerplate
- A=lambda m,n:m and A(m-1,n<1or A(m,n-1))or-~n
- A=lambda m,n:n+(m<1or A(m-1,n<1or A(m,n-1))-n)
- A(m,n){return!m?n+1:A(m-1,n?A(m,n-1):1);}
- int main()
- {
- int m,n;
- for(m = 0; m <= 3; m++)
- for(n = 0; n <= 10; n++)
- printf("%d %d %dn", m,n,A(m,n));
- return 0;
- }
- f=(m,n)=>m?f(m-1,!n||f(m,n-1)):n+1
- f(3,2) // returns 29
- ($:^:(<:@[`]`1:)^:(0<[)>:)
- Ack 0 n = n+1
- Ack m n = Iter (Ack (m-1)) n
- Iter f 0 = f 1
- Iter f n = f (Iter f (n-1))
- ( >:) NB. increment n
- ^:(0<[) NB. if m=0, do nothing to n+1; else:
- ^: NB. iterate...
- ($: ) NB. self ($: is recursion)
- (<:@[ ) NB. with left arg m-1
- `] NB. n+1 times
- `1: NB. starting on 1
- 3 ($:^:(<:@[`]`1:)^:(0<[)>:) 3
- 61
- ack =: ($:^:(<:@[`]`1:)^:(0<[)>:)
- (i.4) ack"0 table (i.11)
- +-----+------------------------------------------+
- |ack"0|0 1 2 3 4 5 6 7 8 9 10|
- +-----+------------------------------------------+
- |0 |1 2 3 4 5 6 7 8 9 10 11|
- |1 |2 3 4 5 6 7 8 9 10 11 12|
- |2 |3 5 7 9 11 13 15 17 19 21 23|
- |3 |5 13 29 61 125 253 509 1021 2045 4093 8189|
- +-----+------------------------------------------+
- 6!:2 '3 ($:^:(<:@[`]`1:)^:(0<[)>:) 10' NB. snugly fits in a minute
- 58.5831
- (0&<~(<:@#~$:/@,1:^:)>:)
- nat_rec _ S(fun _ b n=>nat_iter(S n)b 1)
- Welcome to Coq 8.4pl6 (November 2015)
- Coq < Compute nat_rec _ S(fun _ b n=>nat_iter(S n)b 1) 3 10.
- = 8189
- : nat
- 00000000: 1607 2d88 072f 68 ..-../h
- 000101100000011100101101100010000000011100101111011010
- (define(a m n)(if(= m 0)(+ n 1)(a(- m 1)(if(= n 0)1(a m(- n 1))))))
- 0~a~n_:=n+1
- m_~a~n_:=a[m-1,If[n<1,1,a[m,n-1]]]
- $RecursionLimit = Infinity
- A=(m,n)=>m?A(m-1,n?A(m,n-1):1):n+1
- (d A
- (q( (m n)
- (i m
- (i n
- (A (s m 1)
- (A m
- (s n 1)
- )
- )
- (A (s m 1)
- 1
- )
- )
- (s n
- (s 0 1)
- )
- )
- ) )
- )
- func (m,n int)int{r:=0
- switch{case m==0&&n!=0:r=n+1
- case m!=0&&n==0:r=a(m-1,1)
- case m!=0&&n!=0:r=a(m-1,a(m,n-1))}
- return r}
- $ time go run ack
- 16381
- real 0m1.434s
- user 0m1.432s
- sys 0m0.004s
- a::Int->Int->Int
- a 0 n=n+1
- a m 0=a (m-1) 1
- a m n=a (m-1) a m (n-1)
- a=function(m,n){"if"(m,a(m-1,"if"(n,a(m,n-1),1)),n+1)}
- > a(3,8)
- [1] 2045
- 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)))))
- M?GgtG?HgGtH1hH
- iiRuldr%l%lR$d%rd:u%d:%+uRu:ro
- >:@]`(1$:~<:@[)`(<:@[$:[$:_1+])@.(0>.[:<:@#.,&*)M.
- A=:>:@]`(1$:~<:@[)`(<:@[$:[$:_1+])@.(0>.[:<:@#.,&*)M.
- timespacex 'res=:(i.4) A"0 table (i.11)'
- 0.0336829 3.54035e6
- res
- ┌───┬──────────────────────────────────────────┐
- │A"0│0 1 2 3 4 5 6 7 8 9 10│
- ├───┼──────────────────────────────────────────┤
- │0 │1 2 3 4 5 6 7 8 9 10 11│
- │1 │2 3 4 5 6 7 8 9 10 11 12│
- │2 │3 5 7 9 11 13 15 17 19 21 23│
- │3 │5 13 29 61 125 253 509 1021 2045 4093 8189│
- └───┴──────────────────────────────────────────┘
- {⍺=0:⍵+1⋄⍵=0:1∇⍨⍺-1⋄(⍺-1)∇⍺∇⍵-1}
- $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+;;]]]@
- 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)));}}
- proc A m n {expr {$m?[A [expr $m-1] [expr {$n?[A $m [expr $n-1]]:1}]]:$n+1}}
- m=0, n=0, A=1, time=3.5e-5 seconds
- m=0, n=1, A=2, time=2e-6 seconds
- m=0, n=2, A=3, time=8e-6 seconds
- m=0, n=3, A=4, time=1e-6 seconds
- m=0, n=4, A=5, time=2e-6 seconds
- m=0, n=5, A=6, time=1e-6 seconds
- m=0, n=6, A=7, time=1e-6 seconds
- m=0, n=7, A=8, time=1e-6 seconds
- m=0, n=8, A=9, time=1e-6 seconds
- m=0, n=9, A=10, time=0.0 seconds
- m=0, n=10, A=11, time=1e-6 seconds
- m=1, n=0, A=2, time=4e-6 seconds
- m=1, n=1, A=3, time=6e-6 seconds
- m=1, n=2, A=4, time=1e-5 seconds
- m=1, n=3, A=5, time=1.2e-5 seconds
- m=1, n=4, A=6, time=1.5e-5 seconds
- m=1, n=5, A=7, time=2e-5 seconds
- m=1, n=6, A=8, time=2e-5 seconds
- m=1, n=7, A=9, time=2.6e-5 seconds
- m=1, n=8, A=10, time=3e-5 seconds
- m=1, n=9, A=11, time=3e-5 seconds
- m=1, n=10, A=12, time=3.3e-5 seconds
- m=2, n=0, A=3, time=8e-6 seconds
- m=2, n=1, A=5, time=2.2e-5 seconds
- m=2, n=2, A=7, time=3.9e-5 seconds
- m=2, n=3, A=9, time=6.3e-5 seconds
- m=2, n=4, A=11, time=9.1e-5 seconds
- m=2, n=5, A=13, time=0.000124 seconds
- m=2, n=6, A=15, time=0.000163 seconds
- m=2, n=7, A=17, time=0.000213 seconds
- m=2, n=8, A=19, time=0.000262 seconds
- m=2, n=9, A=21, time=0.000316 seconds
- m=2, n=10, A=23, time=0.000377 seconds
- m=3, n=0, A=5, time=2.2e-5 seconds
- m=3, n=1, A=13, time=0.000145 seconds
- m=3, n=2, A=29, time=0.000745 seconds
- m=3, n=3, A=61, time=0.003345 seconds
- m=3, n=4, A=125, time=0.015048 seconds
- m=3, n=5, A=253, time=0.059836 seconds
- m=3, n=6, A=509, time=0.241431 seconds
- m=3, n=7, A=1021, time=0.971836 seconds
- m=3, n=8, A=2045, time=3.908884 seconds
- m=3, n=9, A=4093, time=15.926341 seconds
- m=3, n=10, A=8189, time=63.734713 seconds
Add Comment
Please, Sign In to add comment