Hyperoperation Golfing

The name of the pictureThe name of the pictureThe name of the pictureClash 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!










share|improve this question























  • @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














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!










share|improve this question























  • @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












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!










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • @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










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





share|improve this answer





























    up vote
    1
    down vote













    Dyalog APL, 35 bytes





    ⍺=0:⍵+1⋄⍵=0:⍺⍺⍵1⊃⍨3⌊⍺⋄(⍺-1)∇⍺∇⍵-1


    Try it online!





    share



























      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!






      share|improve this answer




















        Your Answer




        StackExchange.ifUsing("editor", function ()
        return StackExchange.using("mathjaxEditing", function ()
        StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
        StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
        );
        );
        , "mathjax-editing");

        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "200"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        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






























        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





        share|improve this answer


























          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





          share|improve this answer
























            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





            share|improve this answer














            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






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 43 secs ago

























            answered 36 mins ago









            Arnauld

            64.1k580270




            64.1k580270




















                up vote
                1
                down vote













                Dyalog APL, 35 bytes





                ⍺=0:⍵+1⋄⍵=0:⍺⍺⍵1⊃⍨3⌊⍺⋄(⍺-1)∇⍺∇⍵-1


                Try it online!





                share
























                  up vote
                  1
                  down vote













                  Dyalog APL, 35 bytes





                  ⍺=0:⍵+1⋄⍵=0:⍺⍺⍵1⊃⍨3⌊⍺⋄(⍺-1)∇⍺∇⍵-1


                  Try it online!





                  share






















                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Dyalog APL, 35 bytes





                    ⍺=0:⍵+1⋄⍵=0:⍺⍺⍵1⊃⍨3⌊⍺⋄(⍺-1)∇⍺∇⍵-1


                    Try it online!





                    share












                    Dyalog APL, 35 bytes





                    ⍺=0:⍵+1⋄⍵=0:⍺⍺⍵1⊃⍨3⌊⍺⋄(⍺-1)∇⍺∇⍵-1


                    Try it online!






                    share











                    share


                    share










                    answered 9 mins ago









                    dzaima

                    13.1k21652




                    13.1k21652




















                        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!






                        share|improve this answer
























                          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!






                          share|improve this answer






















                            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!






                            share|improve this answer













                            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!







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 33 mins ago









                            Okx

                            12k27100




                            12k27100



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                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













































































                                Comments

                                Popular posts from this blog

                                What does second last employer means? [closed]

                                Installing NextGIS Connect into QGIS 3?

                                One-line joke