Multiplicative undelta
Clash 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]
code-golf array-manipulation integer
add a comment |Â
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]
code-golf array-manipulation integer
add a comment |Â
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]
code-golf array-manipulation integer
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
code-golf array-manipulation integer
asked 1 hour ago
BMO
9,99921774
9,99921774
add a comment |Â
add a comment |Â
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!
add a comment |Â
up vote
1
down vote
MATL, 3 bytes
hYp
Try it online!
add a comment |Â
up vote
0
down vote
Haskell, 8 bytes
scanl(*)
Try it online!
add a comment |Â
up vote
0
down vote
Jelly, 3 bytes
;ÃÂ
Try it online!
Thanks for providing two symbols I could copy paste easily on my phone. :P
â Quintec
47 mins ago
add a comment |Â
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
.
add a comment |Â
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
(ÃÂâ£,â¢)
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
add a comment |Â
up vote
0
down vote
Perl 6, 9 bytes
[*] @_
Try it online!
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
JavaScript (ES6), 27 bytes
Takes input as (m)(a)
.
m=>a=>[m,...a.map(x=>m*=x)]
Try it online!
answered 53 mins ago
Arnauld
66k583278
66k583278
add a comment |Â
add a comment |Â
up vote
1
down vote
MATL, 3 bytes
hYp
Try it online!
add a comment |Â
up vote
1
down vote
MATL, 3 bytes
hYp
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
MATL, 3 bytes
hYp
Try it online!
MATL, 3 bytes
hYp
Try it online!
answered 21 mins ago
Giuseppe
15.2k31051
15.2k31051
add a comment |Â
add a comment |Â
up vote
0
down vote
Haskell, 8 bytes
scanl(*)
Try it online!
add a comment |Â
up vote
0
down vote
Haskell, 8 bytes
scanl(*)
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Haskell, 8 bytes
scanl(*)
Try it online!
Haskell, 8 bytes
scanl(*)
Try it online!
answered 1 hour ago
nimi
30.2k31883
30.2k31883
add a comment |Â
add a comment |Â
up vote
0
down vote
Jelly, 3 bytes
;ÃÂ
Try it online!
Thanks for providing two symbols I could copy paste easily on my phone. :P
â Quintec
47 mins ago
add a comment |Â
up vote
0
down vote
Jelly, 3 bytes
;ÃÂ
Try it online!
Thanks for providing two symbols I could copy paste easily on my phone. :P
â Quintec
47 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Jelly, 3 bytes
;ÃÂ
Try it online!
Jelly, 3 bytes
;ÃÂ
Try it online!
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
add a comment |Â
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
add a comment |Â
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
.
add a comment |Â
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
.
add a comment |Â
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
.
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
.
answered 54 mins ago
Misha Lavrov
3,387320
3,387320
add a comment |Â
add a comment |Â
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
(ÃÂâ£,â¢)
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
add a comment |Â
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
(ÃÂâ£,â¢)
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
add a comment |Â
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
(ÃÂâ£,â¢)
APL(Dyalog), 2 bytes
ÃÂ
If I have to take the number on the left and the array on the right:
7 bytes
(ÃÂâ£,â¢)
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
add a comment |Â
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
add a comment |Â
up vote
0
down vote
Perl 6, 9 bytes
[*] @_
Try it online!
add a comment |Â
up vote
0
down vote
Perl 6, 9 bytes
[*] @_
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Perl 6, 9 bytes
[*] @_
Try it online!
Perl 6, 9 bytes
[*] @_
Try it online!
answered 33 mins ago
nwellnhof
3,978715
3,978715
add a comment |Â
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
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!
edited 14 mins ago
answered 19 mins ago
Kirill L.
2,7461117
2,7461117
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%2f173537%2fmultiplicative-undelta%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