Multiplicative undelta

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












Let us define the "multiplicative deltas" of values $[; a_0 cdots a_N ;]$ as:



$$
[; a_1 / a_0 cdots a_i+1 / a_i cdots a_N / a_N-1 ;]
$$



The reverse operation - namely "multiplicative undelta" - returns values such that the above operation results in the given values.



Example



Given values $[; 1 quad 5 quad 3 quad 2 ;]$ a general solution to the "multiplicative undelta" operation is:



$$
[;
a_0
quad underseta_1underbracea_0 cdot 1
quad underseta_2underbracea_1 cdot 5
quad underseta_3underbracea_2 cdot 3
quad underseta_4underbracea_3 cdot 2
;]
$$



A particular solution can be obtained by setting $a_0$ to any value other than zero, for example by setting $a_0 := 1 $ we would get:



$$
[; 1 quad 1 quad 5 quad 15 quad 30 ;]
$$



Challenge



Your task for this challenge is to implement the operation "multiplicative undelta" as defined above.



Rules



Inputs are:



  • a non-zero value $a_0$

  • a non-empty list/array/vector/... of non-zero "multiplicative deltas"

Output is a list/array/vector/... of values such that the first element is $a_0$ and for which the "multiplicative deltas" are the input.



Note: If your language has no support of negative integers you may replace non-zero by positive.



Test cases



2 [21] -> [2,42]
1 [1,5,3,2] -> [1,1,5,15,30]
-1 [1,5,3,2] -> [-1,-1,-5,-15,-30]
7 [1,-5,3,2] -> [7,7,-35,-105,-210]
2 [-12,3,-17,1311] -> [2,-24,-72,1224,1604664]
-12 [7,-1,-12,4] -> [-12,-84,84,-1008,-4032]
1 [2,2,2,2,2,2,2,2] -> [1,2,4,8,16,32,64,128,256]









share|improve this question

























    up vote
    2
    down vote

    favorite












    Let us define the "multiplicative deltas" of values $[; a_0 cdots a_N ;]$ as:



    $$
    [; a_1 / a_0 cdots a_i+1 / a_i cdots a_N / a_N-1 ;]
    $$



    The reverse operation - namely "multiplicative undelta" - returns values such that the above operation results in the given values.



    Example



    Given values $[; 1 quad 5 quad 3 quad 2 ;]$ a general solution to the "multiplicative undelta" operation is:



    $$
    [;
    a_0
    quad underseta_1underbracea_0 cdot 1
    quad underseta_2underbracea_1 cdot 5
    quad underseta_3underbracea_2 cdot 3
    quad underseta_4underbracea_3 cdot 2
    ;]
    $$



    A particular solution can be obtained by setting $a_0$ to any value other than zero, for example by setting $a_0 := 1 $ we would get:



    $$
    [; 1 quad 1 quad 5 quad 15 quad 30 ;]
    $$



    Challenge



    Your task for this challenge is to implement the operation "multiplicative undelta" as defined above.



    Rules



    Inputs are:



    • a non-zero value $a_0$

    • a non-empty list/array/vector/... of non-zero "multiplicative deltas"

    Output is a list/array/vector/... of values such that the first element is $a_0$ and for which the "multiplicative deltas" are the input.



    Note: If your language has no support of negative integers you may replace non-zero by positive.



    Test cases



    2 [21] -> [2,42]
    1 [1,5,3,2] -> [1,1,5,15,30]
    -1 [1,5,3,2] -> [-1,-1,-5,-15,-30]
    7 [1,-5,3,2] -> [7,7,-35,-105,-210]
    2 [-12,3,-17,1311] -> [2,-24,-72,1224,1604664]
    -12 [7,-1,-12,4] -> [-12,-84,84,-1008,-4032]
    1 [2,2,2,2,2,2,2,2] -> [1,2,4,8,16,32,64,128,256]









    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Let us define the "multiplicative deltas" of values $[; a_0 cdots a_N ;]$ as:



      $$
      [; a_1 / a_0 cdots a_i+1 / a_i cdots a_N / a_N-1 ;]
      $$



      The reverse operation - namely "multiplicative undelta" - returns values such that the above operation results in the given values.



      Example



      Given values $[; 1 quad 5 quad 3 quad 2 ;]$ a general solution to the "multiplicative undelta" operation is:



      $$
      [;
      a_0
      quad underseta_1underbracea_0 cdot 1
      quad underseta_2underbracea_1 cdot 5
      quad underseta_3underbracea_2 cdot 3
      quad underseta_4underbracea_3 cdot 2
      ;]
      $$



      A particular solution can be obtained by setting $a_0$ to any value other than zero, for example by setting $a_0 := 1 $ we would get:



      $$
      [; 1 quad 1 quad 5 quad 15 quad 30 ;]
      $$



      Challenge



      Your task for this challenge is to implement the operation "multiplicative undelta" as defined above.



      Rules



      Inputs are:



      • a non-zero value $a_0$

      • a non-empty list/array/vector/... of non-zero "multiplicative deltas"

      Output is a list/array/vector/... of values such that the first element is $a_0$ and for which the "multiplicative deltas" are the input.



      Note: If your language has no support of negative integers you may replace non-zero by positive.



      Test cases



      2 [21] -> [2,42]
      1 [1,5,3,2] -> [1,1,5,15,30]
      -1 [1,5,3,2] -> [-1,-1,-5,-15,-30]
      7 [1,-5,3,2] -> [7,7,-35,-105,-210]
      2 [-12,3,-17,1311] -> [2,-24,-72,1224,1604664]
      -12 [7,-1,-12,4] -> [-12,-84,84,-1008,-4032]
      1 [2,2,2,2,2,2,2,2] -> [1,2,4,8,16,32,64,128,256]









      share|improve this question













      Let us define the "multiplicative deltas" of values $[; a_0 cdots a_N ;]$ as:



      $$
      [; a_1 / a_0 cdots a_i+1 / a_i cdots a_N / a_N-1 ;]
      $$



      The reverse operation - namely "multiplicative undelta" - returns values such that the above operation results in the given values.



      Example



      Given values $[; 1 quad 5 quad 3 quad 2 ;]$ a general solution to the "multiplicative undelta" operation is:



      $$
      [;
      a_0
      quad underseta_1underbracea_0 cdot 1
      quad underseta_2underbracea_1 cdot 5
      quad underseta_3underbracea_2 cdot 3
      quad underseta_4underbracea_3 cdot 2
      ;]
      $$



      A particular solution can be obtained by setting $a_0$ to any value other than zero, for example by setting $a_0 := 1 $ we would get:



      $$
      [; 1 quad 1 quad 5 quad 15 quad 30 ;]
      $$



      Challenge



      Your task for this challenge is to implement the operation "multiplicative undelta" as defined above.



      Rules



      Inputs are:



      • a non-zero value $a_0$

      • a non-empty list/array/vector/... of non-zero "multiplicative deltas"

      Output is a list/array/vector/... of values such that the first element is $a_0$ and for which the "multiplicative deltas" are the input.



      Note: If your language has no support of negative integers you may replace non-zero by positive.



      Test cases



      2 [21] -> [2,42]
      1 [1,5,3,2] -> [1,1,5,15,30]
      -1 [1,5,3,2] -> [-1,-1,-5,-15,-30]
      7 [1,-5,3,2] -> [7,7,-35,-105,-210]
      2 [-12,3,-17,1311] -> [2,-24,-72,1224,1604664]
      -12 [7,-1,-12,4] -> [-12,-84,84,-1008,-4032]
      1 [2,2,2,2,2,2,2,2] -> [1,2,4,8,16,32,64,128,256]






      code-golf array-manipulation integer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      BMO

      9,99921774




      9,99921774




















          8 Answers
          8






          active

          oldest

          votes

















          up vote
          1
          down vote













          JavaScript (ES6), 27 bytes



          Takes input as (m)(a).





          m=>a=>[m,...a.map(x=>m*=x)]


          Try it online!






          share|improve this answer



























            up vote
            1
            down vote














            MATL, 3 bytes



            hYp


            Try it online!






            share|improve this answer



























              up vote
              0
              down vote













              Haskell, 8 bytes



              scanl(*)


              Try it online!






              share|improve this answer



























                up vote
                0
                down vote














                Jelly, 3 bytes



                ;×


                Try it online!






                share|improve this answer




















                • Thanks for providing two symbols I could copy paste easily on my phone. :P
                  – Quintec
                  47 mins ago

















                up vote
                0
                down vote














                Wolfram Language (Mathematica), 14 bytes



                FoldList@Times


                Try it online!



                FoldList[Times, a0, x1, x2, ..., xn] produces the desired output. FoldList[Times] is the curried form that produces a pure function still waiting for its a0 and x1, x2, ..., xn.






                share|improve this answer



























                  up vote
                  0
                  down vote













                  APL(Dyalog), 2 bytes



                  ×



                  If I have to take the number on the left and the array on the right:



                  7 bytes



                  (×⊣,⊢)






                  share|improve this answer




















                  • If the input of the 2-byte solution is the concatenation of the integer and the array, I don't think you're complying with the challenge rules.
                    – Dennis♦
                    13 mins ago










                  • @Dennis Well they are automatically concatenated, it seems, for example × 1 1 5 3 2, which doesn't really distinguish from the number and the array
                    – Quintec
                    4 mins ago

















                  up vote
                  0
                  down vote














                  Perl 6, 9 bytes





                  [*] @_


                  Try it online!






                  share|improve this answer



























                    up vote
                    0
                    down vote














                    R, 15 bytes





                    cumprod(scan())


                    Try it online!



                    Full program. Function is longer (unless we were allowed to "glue" the inputs together, so that built-in cumprod would suffice as a complete answer):




                    R, 28 bytes





                    function(i,x)cumprod(c(i,x))


                    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%2f173537%2fmultiplicative-undelta%23new-answer', 'question_page');

                      );

                      Post as a guest






























                      8 Answers
                      8






                      active

                      oldest

                      votes








                      8 Answers
                      8






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes








                      up vote
                      1
                      down vote













                      JavaScript (ES6), 27 bytes



                      Takes input as (m)(a).





                      m=>a=>[m,...a.map(x=>m*=x)]


                      Try it online!






                      share|improve this answer
























                        up vote
                        1
                        down vote













                        JavaScript (ES6), 27 bytes



                        Takes input as (m)(a).





                        m=>a=>[m,...a.map(x=>m*=x)]


                        Try it online!






                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          JavaScript (ES6), 27 bytes



                          Takes input as (m)(a).





                          m=>a=>[m,...a.map(x=>m*=x)]


                          Try it online!






                          share|improve this answer












                          JavaScript (ES6), 27 bytes



                          Takes input as (m)(a).





                          m=>a=>[m,...a.map(x=>m*=x)]


                          Try it online!







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 53 mins ago









                          Arnauld

                          66k583278




                          66k583278




















                              up vote
                              1
                              down vote














                              MATL, 3 bytes



                              hYp


                              Try it online!






                              share|improve this answer
























                                up vote
                                1
                                down vote














                                MATL, 3 bytes



                                hYp


                                Try it online!






                                share|improve this answer






















                                  up vote
                                  1
                                  down vote










                                  up vote
                                  1
                                  down vote










                                  MATL, 3 bytes



                                  hYp


                                  Try it online!






                                  share|improve this answer













                                  MATL, 3 bytes



                                  hYp


                                  Try it online!







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered 21 mins ago









                                  Giuseppe

                                  15.2k31051




                                  15.2k31051




















                                      up vote
                                      0
                                      down vote













                                      Haskell, 8 bytes



                                      scanl(*)


                                      Try it online!






                                      share|improve this answer
























                                        up vote
                                        0
                                        down vote













                                        Haskell, 8 bytes



                                        scanl(*)


                                        Try it online!






                                        share|improve this answer






















                                          up vote
                                          0
                                          down vote










                                          up vote
                                          0
                                          down vote









                                          Haskell, 8 bytes



                                          scanl(*)


                                          Try it online!






                                          share|improve this answer












                                          Haskell, 8 bytes



                                          scanl(*)


                                          Try it online!







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered 1 hour ago









                                          nimi

                                          30.2k31883




                                          30.2k31883




















                                              up vote
                                              0
                                              down vote














                                              Jelly, 3 bytes



                                              ;×


                                              Try it online!






                                              share|improve this answer




















                                              • Thanks for providing two symbols I could copy paste easily on my phone. :P
                                                – Quintec
                                                47 mins ago














                                              up vote
                                              0
                                              down vote














                                              Jelly, 3 bytes



                                              ;×


                                              Try it online!






                                              share|improve this answer




















                                              • Thanks for providing two symbols I could copy paste easily on my phone. :P
                                                – Quintec
                                                47 mins ago












                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote










                                              Jelly, 3 bytes



                                              ;×


                                              Try it online!






                                              share|improve this answer













                                              Jelly, 3 bytes



                                              ;×


                                              Try it online!







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 1 hour ago









                                              Erik the Outgolfer

                                              29.7k42899




                                              29.7k42899











                                              • Thanks for providing two symbols I could copy paste easily on my phone. :P
                                                – Quintec
                                                47 mins ago
















                                              • Thanks for providing two symbols I could copy paste easily on my phone. :P
                                                – Quintec
                                                47 mins ago















                                              Thanks for providing two symbols I could copy paste easily on my phone. :P
                                              – Quintec
                                              47 mins ago




                                              Thanks for providing two symbols I could copy paste easily on my phone. :P
                                              – Quintec
                                              47 mins ago










                                              up vote
                                              0
                                              down vote














                                              Wolfram Language (Mathematica), 14 bytes



                                              FoldList@Times


                                              Try it online!



                                              FoldList[Times, a0, x1, x2, ..., xn] produces the desired output. FoldList[Times] is the curried form that produces a pure function still waiting for its a0 and x1, x2, ..., xn.






                                              share|improve this answer
























                                                up vote
                                                0
                                                down vote














                                                Wolfram Language (Mathematica), 14 bytes



                                                FoldList@Times


                                                Try it online!



                                                FoldList[Times, a0, x1, x2, ..., xn] produces the desired output. FoldList[Times] is the curried form that produces a pure function still waiting for its a0 and x1, x2, ..., xn.






                                                share|improve this answer






















                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote










                                                  Wolfram Language (Mathematica), 14 bytes



                                                  FoldList@Times


                                                  Try it online!



                                                  FoldList[Times, a0, x1, x2, ..., xn] produces the desired output. FoldList[Times] is the curried form that produces a pure function still waiting for its a0 and x1, x2, ..., xn.






                                                  share|improve this answer













                                                  Wolfram Language (Mathematica), 14 bytes



                                                  FoldList@Times


                                                  Try it online!



                                                  FoldList[Times, a0, x1, x2, ..., xn] produces the desired output. FoldList[Times] is the curried form that produces a pure function still waiting for its a0 and x1, x2, ..., xn.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered 54 mins ago









                                                  Misha Lavrov

                                                  3,387320




                                                  3,387320




















                                                      up vote
                                                      0
                                                      down vote













                                                      APL(Dyalog), 2 bytes



                                                      ×



                                                      If I have to take the number on the left and the array on the right:



                                                      7 bytes



                                                      (×⊣,⊢)






                                                      share|improve this answer




















                                                      • If the input of the 2-byte solution is the concatenation of the integer and the array, I don't think you're complying with the challenge rules.
                                                        – Dennis♦
                                                        13 mins ago










                                                      • @Dennis Well they are automatically concatenated, it seems, for example × 1 1 5 3 2, which doesn't really distinguish from the number and the array
                                                        – Quintec
                                                        4 mins ago














                                                      up vote
                                                      0
                                                      down vote













                                                      APL(Dyalog), 2 bytes



                                                      ×



                                                      If I have to take the number on the left and the array on the right:



                                                      7 bytes



                                                      (×⊣,⊢)






                                                      share|improve this answer




















                                                      • If the input of the 2-byte solution is the concatenation of the integer and the array, I don't think you're complying with the challenge rules.
                                                        – Dennis♦
                                                        13 mins ago










                                                      • @Dennis Well they are automatically concatenated, it seems, for example × 1 1 5 3 2, which doesn't really distinguish from the number and the array
                                                        – Quintec
                                                        4 mins ago












                                                      up vote
                                                      0
                                                      down vote










                                                      up vote
                                                      0
                                                      down vote









                                                      APL(Dyalog), 2 bytes



                                                      ×



                                                      If I have to take the number on the left and the array on the right:



                                                      7 bytes



                                                      (×⊣,⊢)






                                                      share|improve this answer












                                                      APL(Dyalog), 2 bytes



                                                      ×



                                                      If I have to take the number on the left and the array on the right:



                                                      7 bytes



                                                      (×⊣,⊢)







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered 49 mins ago









                                                      Quintec

                                                      795417




                                                      795417











                                                      • If the input of the 2-byte solution is the concatenation of the integer and the array, I don't think you're complying with the challenge rules.
                                                        – Dennis♦
                                                        13 mins ago










                                                      • @Dennis Well they are automatically concatenated, it seems, for example × 1 1 5 3 2, which doesn't really distinguish from the number and the array
                                                        – Quintec
                                                        4 mins ago
















                                                      • If the input of the 2-byte solution is the concatenation of the integer and the array, I don't think you're complying with the challenge rules.
                                                        – Dennis♦
                                                        13 mins ago










                                                      • @Dennis Well they are automatically concatenated, it seems, for example × 1 1 5 3 2, which doesn't really distinguish from the number and the array
                                                        – Quintec
                                                        4 mins ago















                                                      If the input of the 2-byte solution is the concatenation of the integer and the array, I don't think you're complying with the challenge rules.
                                                      – Dennis♦
                                                      13 mins ago




                                                      If the input of the 2-byte solution is the concatenation of the integer and the array, I don't think you're complying with the challenge rules.
                                                      – Dennis♦
                                                      13 mins ago












                                                      @Dennis Well they are automatically concatenated, it seems, for example × 1 1 5 3 2, which doesn't really distinguish from the number and the array
                                                      – Quintec
                                                      4 mins ago




                                                      @Dennis Well they are automatically concatenated, it seems, for example × 1 1 5 3 2, which doesn't really distinguish from the number and the array
                                                      – Quintec
                                                      4 mins ago










                                                      up vote
                                                      0
                                                      down vote














                                                      Perl 6, 9 bytes





                                                      [*] @_


                                                      Try it online!






                                                      share|improve this answer
























                                                        up vote
                                                        0
                                                        down vote














                                                        Perl 6, 9 bytes





                                                        [*] @_


                                                        Try it online!






                                                        share|improve this answer






















                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote










                                                          Perl 6, 9 bytes





                                                          [*] @_


                                                          Try it online!






                                                          share|improve this answer













                                                          Perl 6, 9 bytes





                                                          [*] @_


                                                          Try it online!







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered 33 mins ago









                                                          nwellnhof

                                                          3,978715




                                                          3,978715




















                                                              up vote
                                                              0
                                                              down vote














                                                              R, 15 bytes





                                                              cumprod(scan())


                                                              Try it online!



                                                              Full program. Function is longer (unless we were allowed to "glue" the inputs together, so that built-in cumprod would suffice as a complete answer):




                                                              R, 28 bytes





                                                              function(i,x)cumprod(c(i,x))


                                                              Try it online!






                                                              share|improve this answer


























                                                                up vote
                                                                0
                                                                down vote














                                                                R, 15 bytes





                                                                cumprod(scan())


                                                                Try it online!



                                                                Full program. Function is longer (unless we were allowed to "glue" the inputs together, so that built-in cumprod would suffice as a complete answer):




                                                                R, 28 bytes





                                                                function(i,x)cumprod(c(i,x))


                                                                Try it online!






                                                                share|improve this answer
























                                                                  up vote
                                                                  0
                                                                  down vote










                                                                  up vote
                                                                  0
                                                                  down vote










                                                                  R, 15 bytes





                                                                  cumprod(scan())


                                                                  Try it online!



                                                                  Full program. Function is longer (unless we were allowed to "glue" the inputs together, so that built-in cumprod would suffice as a complete answer):




                                                                  R, 28 bytes





                                                                  function(i,x)cumprod(c(i,x))


                                                                  Try it online!






                                                                  share|improve this answer















                                                                  R, 15 bytes





                                                                  cumprod(scan())


                                                                  Try it online!



                                                                  Full program. Function is longer (unless we were allowed to "glue" the inputs together, so that built-in cumprod would suffice as a complete answer):




                                                                  R, 28 bytes





                                                                  function(i,x)cumprod(c(i,x))


                                                                  Try it online!







                                                                  share|improve this answer














                                                                  share|improve this answer



                                                                  share|improve this answer








                                                                  edited 14 mins ago

























                                                                  answered 19 mins ago









                                                                  Kirill L.

                                                                  2,7461117




                                                                  2,7461117



























                                                                       

                                                                      draft saved


                                                                      draft discarded















































                                                                       


                                                                      draft saved


                                                                      draft discarded














                                                                      StackExchange.ready(
                                                                      function ()
                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173537%2fmultiplicative-undelta%23new-answer', 'question_page');

                                                                      );

                                                                      Post as a guest













































































                                                                      Comments

                                                                      Popular posts from this blog

                                                                      Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                                                      Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                                                      Confectionery