Hyperoperation Golfing
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Introduction
In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the unary operation of successor (n = 0), then continues with the binary operations of addition (n = 1), multiplication (n = 2), and exponentiation (n = 3), after which the sequence proceeds with further binary operations extending beyond exponentiation, using right-associativity.
(Source)
Challenge
Your challenge is code this sequence, given 3 inputs, n, a, and b, code a function such that $$displaystyle H_n(a,b)=begincasesb+1&textif n=0\a&textif n=1text and b=0\0&textif n=2text and b=0\1&textif ngeq 3text and b=0\H_n-1(a,H_n(a,b-1))&textotherwiseendcases$$
(Also from Wikipedia.)
Input
3 positive decimal integers, n, a, and b, taken from STDIN, function or command line arguments, in any order. Make sure to specify this in your answer
Output
The result of applying $H_n(a,b)$ with the inputs
Example inputs and outputs
Input: 0, 6, 3
Output: 4
Input: 4 5 2
Output: 3125
Restrictions
- Your program/function should take input in base 10
- Don't use any built in function that already provides H(n, a, b)
- Standard loopholes apply
This is code-golf, so shortest code in bytes wins!
code-golf math sequence
add a comment |Â
up vote
4
down vote
favorite
Introduction
In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the unary operation of successor (n = 0), then continues with the binary operations of addition (n = 1), multiplication (n = 2), and exponentiation (n = 3), after which the sequence proceeds with further binary operations extending beyond exponentiation, using right-associativity.
(Source)
Challenge
Your challenge is code this sequence, given 3 inputs, n, a, and b, code a function such that $$displaystyle H_n(a,b)=begincasesb+1&textif n=0\a&textif n=1text and b=0\0&textif n=2text and b=0\1&textif ngeq 3text and b=0\H_n-1(a,H_n(a,b-1))&textotherwiseendcases$$
(Also from Wikipedia.)
Input
3 positive decimal integers, n, a, and b, taken from STDIN, function or command line arguments, in any order. Make sure to specify this in your answer
Output
The result of applying $H_n(a,b)$ with the inputs
Example inputs and outputs
Input: 0, 6, 3
Output: 4
Input: 4 5 2
Output: 3125
Restrictions
- Your program/function should take input in base 10
- Don't use any built in function that already provides H(n, a, b)
- Standard loopholes apply
This is code-golf, so shortest code in bytes wins!
code-golf math sequence
@JoKing Does it? I'll have a read
â FireCubez
54 mins ago
@Arnauld will do.
â FireCubez
45 mins ago
3
<s>Possible duplicate of Evaluate the nth hyperoperation</s>
â user202729
43 mins ago
(not really. That one "bans builtins" because it's from '13; plus, cumbersome input/output format)
â user202729
42 mins ago
@dzaima fixed it.
â FireCubez
31 mins ago
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Introduction
In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the unary operation of successor (n = 0), then continues with the binary operations of addition (n = 1), multiplication (n = 2), and exponentiation (n = 3), after which the sequence proceeds with further binary operations extending beyond exponentiation, using right-associativity.
(Source)
Challenge
Your challenge is code this sequence, given 3 inputs, n, a, and b, code a function such that $$displaystyle H_n(a,b)=begincasesb+1&textif n=0\a&textif n=1text and b=0\0&textif n=2text and b=0\1&textif ngeq 3text and b=0\H_n-1(a,H_n(a,b-1))&textotherwiseendcases$$
(Also from Wikipedia.)
Input
3 positive decimal integers, n, a, and b, taken from STDIN, function or command line arguments, in any order. Make sure to specify this in your answer
Output
The result of applying $H_n(a,b)$ with the inputs
Example inputs and outputs
Input: 0, 6, 3
Output: 4
Input: 4 5 2
Output: 3125
Restrictions
- Your program/function should take input in base 10
- Don't use any built in function that already provides H(n, a, b)
- Standard loopholes apply
This is code-golf, so shortest code in bytes wins!
code-golf math sequence
Introduction
In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the unary operation of successor (n = 0), then continues with the binary operations of addition (n = 1), multiplication (n = 2), and exponentiation (n = 3), after which the sequence proceeds with further binary operations extending beyond exponentiation, using right-associativity.
(Source)
Challenge
Your challenge is code this sequence, given 3 inputs, n, a, and b, code a function such that $$displaystyle H_n(a,b)=begincasesb+1&textif n=0\a&textif n=1text and b=0\0&textif n=2text and b=0\1&textif ngeq 3text and b=0\H_n-1(a,H_n(a,b-1))&textotherwiseendcases$$
(Also from Wikipedia.)
Input
3 positive decimal integers, n, a, and b, taken from STDIN, function or command line arguments, in any order. Make sure to specify this in your answer
Output
The result of applying $H_n(a,b)$ with the inputs
Example inputs and outputs
Input: 0, 6, 3
Output: 4
Input: 4 5 2
Output: 3125
Restrictions
- Your program/function should take input in base 10
- Don't use any built in function that already provides H(n, a, b)
- Standard loopholes apply
This is code-golf, so shortest code in bytes wins!
code-golf math sequence
code-golf math sequence
edited 33 mins ago
asked 59 mins ago
FireCubez
615
615
@JoKing Does it? I'll have a read
â FireCubez
54 mins ago
@Arnauld will do.
â FireCubez
45 mins ago
3
<s>Possible duplicate of Evaluate the nth hyperoperation</s>
â user202729
43 mins ago
(not really. That one "bans builtins" because it's from '13; plus, cumbersome input/output format)
â user202729
42 mins ago
@dzaima fixed it.
â FireCubez
31 mins ago
add a comment |Â
@JoKing Does it? I'll have a read
â FireCubez
54 mins ago
@Arnauld will do.
â FireCubez
45 mins ago
3
<s>Possible duplicate of Evaluate the nth hyperoperation</s>
â user202729
43 mins ago
(not really. That one "bans builtins" because it's from '13; plus, cumbersome input/output format)
â user202729
42 mins ago
@dzaima fixed it.
â FireCubez
31 mins ago
@JoKing Does it? I'll have a read
â FireCubez
54 mins ago
@JoKing Does it? I'll have a read
â FireCubez
54 mins ago
@Arnauld will do.
â FireCubez
45 mins ago
@Arnauld will do.
â FireCubez
45 mins ago
3
3
<s>Possible duplicate of Evaluate the nth hyperoperation</s>
â user202729
43 mins ago
<s>Possible duplicate of Evaluate the nth hyperoperation</s>
â user202729
43 mins ago
(not really. That one "bans builtins" because it's from '13; plus, cumbersome input/output format)
â user202729
42 mins ago
(not really. That one "bans builtins" because it's from '13; plus, cumbersome input/output format)
â user202729
42 mins ago
@dzaima fixed it.
â FireCubez
31 mins ago
@dzaima fixed it.
â FireCubez
31 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
JavaScript (ES6), Â 49Â 47 bytes
Takes input as (a)(b,n)
.
a=>g=(b,n)=>n*b?g(g(b-1,n),n-1):-~[b,a-1,-1][n]
Try it online!
Commented
a => // main function taking a
g = (b, n) => // g = recursive function taking b and n
n * b ? // if neither n nor b is equal to 0:
g( // go recursive:
g(b - 1, n), // b = g(b - 1, n)
n - 1 // decrement n
) // end of recursive call
: // else:
-~[ // this is a leaf node:
b, // return b + 1 if n = 0
a - 1, // return (a - 1) + 1 = a if n = 1
-1 // return -1 + 1 = 0 if n = 2
][n] // return -~undefined = 1 if n > 2
add a comment |Â
up vote
1
down vote
Dyalog APL, 35 bytes
âº=0:âµ+1âÂÂâµ=0:âºâºâµ1âÂÂâ¨3âÂÂâºâÂÂ(âº-1)âÂÂâºâÂÂâµ-1
Try it online!
add a comment |Â
up vote
0
down vote
Elixir, 86 bytes
(assumes functions can take a reference to itself as an argument)
fn 0,_,b,_->b+1
1,a,0,_->a
2,_,0,_->0
_,_,0,_->1
n,a,b,f->f.(n-1,a,f.(n,a,b-1,f),f)end
Try it online!
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
JavaScript (ES6), Â 49Â 47 bytes
Takes input as (a)(b,n)
.
a=>g=(b,n)=>n*b?g(g(b-1,n),n-1):-~[b,a-1,-1][n]
Try it online!
Commented
a => // main function taking a
g = (b, n) => // g = recursive function taking b and n
n * b ? // if neither n nor b is equal to 0:
g( // go recursive:
g(b - 1, n), // b = g(b - 1, n)
n - 1 // decrement n
) // end of recursive call
: // else:
-~[ // this is a leaf node:
b, // return b + 1 if n = 0
a - 1, // return (a - 1) + 1 = a if n = 1
-1 // return -1 + 1 = 0 if n = 2
][n] // return -~undefined = 1 if n > 2
add a comment |Â
up vote
2
down vote
JavaScript (ES6), Â 49Â 47 bytes
Takes input as (a)(b,n)
.
a=>g=(b,n)=>n*b?g(g(b-1,n),n-1):-~[b,a-1,-1][n]
Try it online!
Commented
a => // main function taking a
g = (b, n) => // g = recursive function taking b and n
n * b ? // if neither n nor b is equal to 0:
g( // go recursive:
g(b - 1, n), // b = g(b - 1, n)
n - 1 // decrement n
) // end of recursive call
: // else:
-~[ // this is a leaf node:
b, // return b + 1 if n = 0
a - 1, // return (a - 1) + 1 = a if n = 1
-1 // return -1 + 1 = 0 if n = 2
][n] // return -~undefined = 1 if n > 2
add a comment |Â
up vote
2
down vote
up vote
2
down vote
JavaScript (ES6), Â 49Â 47 bytes
Takes input as (a)(b,n)
.
a=>g=(b,n)=>n*b?g(g(b-1,n),n-1):-~[b,a-1,-1][n]
Try it online!
Commented
a => // main function taking a
g = (b, n) => // g = recursive function taking b and n
n * b ? // if neither n nor b is equal to 0:
g( // go recursive:
g(b - 1, n), // b = g(b - 1, n)
n - 1 // decrement n
) // end of recursive call
: // else:
-~[ // this is a leaf node:
b, // return b + 1 if n = 0
a - 1, // return (a - 1) + 1 = a if n = 1
-1 // return -1 + 1 = 0 if n = 2
][n] // return -~undefined = 1 if n > 2
JavaScript (ES6), Â 49Â 47 bytes
Takes input as (a)(b,n)
.
a=>g=(b,n)=>n*b?g(g(b-1,n),n-1):-~[b,a-1,-1][n]
Try it online!
Commented
a => // main function taking a
g = (b, n) => // g = recursive function taking b and n
n * b ? // if neither n nor b is equal to 0:
g( // go recursive:
g(b - 1, n), // b = g(b - 1, n)
n - 1 // decrement n
) // end of recursive call
: // else:
-~[ // this is a leaf node:
b, // return b + 1 if n = 0
a - 1, // return (a - 1) + 1 = a if n = 1
-1 // return -1 + 1 = 0 if n = 2
][n] // return -~undefined = 1 if n > 2
edited 43 secs ago
answered 36 mins ago
Arnauld
64.1k580270
64.1k580270
add a comment |Â
add a comment |Â
up vote
1
down vote
Dyalog APL, 35 bytes
âº=0:âµ+1âÂÂâµ=0:âºâºâµ1âÂÂâ¨3âÂÂâºâÂÂ(âº-1)âÂÂâºâÂÂâµ-1
Try it online!
add a comment |Â
up vote
1
down vote
Dyalog APL, 35 bytes
âº=0:âµ+1âÂÂâµ=0:âºâºâµ1âÂÂâ¨3âÂÂâºâÂÂ(âº-1)âÂÂâºâÂÂâµ-1
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Dyalog APL, 35 bytes
âº=0:âµ+1âÂÂâµ=0:âºâºâµ1âÂÂâ¨3âÂÂâºâÂÂ(âº-1)âÂÂâºâÂÂâµ-1
Try it online!
Dyalog APL, 35 bytes
âº=0:âµ+1âÂÂâµ=0:âºâºâµ1âÂÂâ¨3âÂÂâºâÂÂ(âº-1)âÂÂâºâÂÂâµ-1
Try it online!
answered 9 mins ago
dzaima
13.1k21652
13.1k21652
add a comment |Â
add a comment |Â
up vote
0
down vote
Elixir, 86 bytes
(assumes functions can take a reference to itself as an argument)
fn 0,_,b,_->b+1
1,a,0,_->a
2,_,0,_->0
_,_,0,_->1
n,a,b,f->f.(n-1,a,f.(n,a,b-1,f),f)end
Try it online!
add a comment |Â
up vote
0
down vote
Elixir, 86 bytes
(assumes functions can take a reference to itself as an argument)
fn 0,_,b,_->b+1
1,a,0,_->a
2,_,0,_->0
_,_,0,_->1
n,a,b,f->f.(n-1,a,f.(n,a,b-1,f),f)end
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Elixir, 86 bytes
(assumes functions can take a reference to itself as an argument)
fn 0,_,b,_->b+1
1,a,0,_->a
2,_,0,_->0
_,_,0,_->1
n,a,b,f->f.(n-1,a,f.(n,a,b-1,f),f)end
Try it online!
Elixir, 86 bytes
(assumes functions can take a reference to itself as an argument)
fn 0,_,b,_->b+1
1,a,0,_->a
2,_,0,_->0
_,_,0,_->1
n,a,b,f->f.(n-1,a,f.(n,a,b-1,f),f)end
Try it online!
answered 33 mins ago
Okx
12k27100
12k27100
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172255%2fhyperoperation-golfing%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@JoKing Does it? I'll have a read
â FireCubez
54 mins ago
@Arnauld will do.
â FireCubez
45 mins ago
3
<s>Possible duplicate of Evaluate the nth hyperoperation</s>
â user202729
43 mins ago
(not really. That one "bans builtins" because it's from '13; plus, cumbersome input/output format)
â user202729
42 mins ago
@dzaima fixed it.
â FireCubez
31 mins ago