52 Week Challenge

2

The 52 week challenge is a way to save money. For example, Week 1, you save $1.00. Week 2 you save $2.00, and it continues through the year, adding one more dollar to each week’s savings goal. By Week 52, you’ll set aside $52.00, which will bring the year’s total savings to $1,378! Of course, you can decide how much money you start saving and how many weeks.

Given an amount for Week 1 and the number of weeks the challenge should run for, return the total amount saved at the end of the challenge.

Week 2 will have as twice the amount of Week 1, Week 3 will have thrice the amount of Week 1, etc.

Examples

1 and 52 weeks: 1378

5 and 6 weeks: 105

.25 and 100 weeks: 1262.5

10 and 1 week: 10

7 and 0 weeks: 0

0 and 30 weeks: 0

0 and 0 weeks: 0

James

Posted 2017-12-21T18:47:46.020

Reputation: 75

Question was closed 2017-12-21T22:33:41.163

2This challenge is very poorly specified; the task is unclear and it lacks any winning or validity criterion. Please respecify it so the exact task is clear and it is easy to determine if a submission is valid and which submissions win. – HyperNeutrino – 2017-12-21T18:54:35.090

2

Hi, Welcome to PPCG! We generally host programming competitions, and the challenges here should have a clear specification in order to indisputably decide whether an answer is valid and a winning criterion to determine which submission wins. For guidance, you can visit this meta thread: How does this site work? It might be worth reading through this too. For future challenges, we can help you improve them with the Sandbox. :-)

– Mr. Xcoder – 2017-12-21T20:01:21.513

2

I've edited your post to conform to our standards while following a possible interpretation of your original text. If it doesn't suit you, feel free to roll the edit back.

– Adám – 2017-12-21T20:03:49.740

I think this challenge has one thing preventing it being reopened: How does setting aside $52 bring the year's total to $1378? What mapping is being done? – caird coinheringaahing – 2017-12-21T20:23:38.440

3@cairdcoinheringaahing That's $1+$2+$3+…+$52=$1378. – Adám – 2017-12-21T20:50:58.367

1

I've voted to close this as a duplicate of sum all integers from 1 to n, because it requires simply computing that result and multiplying it by another input.

– Post Rock Garf Hunter – 2017-12-21T22:34:48.813

Answers

1

Japt, 5 bytes

Takes weeks as the first input and starting amount as the second.

õ x*V

Try it

Shaggy

Posted 2017-12-21T18:47:46.020

Reputation: 24 623

Alternatively, õ*V X – ETHproductions – 2017-12-21T22:12:23.630

1

J, 6 bytes

*2!1+]

Takes the amount as the left argument and the weeks as the right argument.

Try it online!

Explanation

* 2 ! 1 + ]
      1 + ]  Add 1 to the weeks.
  2 !        (Weeks + 1 choose 2)
*            Multiply by the starting amount.

This takes advantage of the fact that the nth triangle number is (n+1 choose 2). Perhaps unsurprisingly, this is almost the exact same answer as the one I have for the sum of digits from 1 to n challenge. Just substitute >: for 1+] and tack on the *.

cole

Posted 2017-12-21T18:47:46.020

Reputation: 3 526

0

R, 23 bytes

function(a,w)sum(0:w*a)

Try it online!

Takes input as amount, weeks.

Giuseppe

Posted 2017-12-21T18:47:46.020

Reputation: 21 077

0

Python 3, 20 bytes

lambda a,w:a*w*-~w/2

Try it online!

ovs

Posted 2017-12-21T18:47:46.020

Reputation: 21 408

0

Jelly, 3 bytes

R×S

Try it online!

dylnan

Posted 2017-12-21T18:47:46.020

Reputation: 4 993

0

ovs

Posted 2017-12-21T18:47:46.020

Reputation: 21 408