2
\$\begingroup\$

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

\$\endgroup\$
6
  • 2
    \$\begingroup\$ This 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. \$\endgroup\$
    – hyperneutrino
    Commented Dec 21, 2017 at 18:54
  • 2
    \$\begingroup\$ 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. :-) \$\endgroup\$
    – Mr. Xcoder
    Commented Dec 21, 2017 at 20:01
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Adám
    Commented Dec 21, 2017 at 20:03
  • 3
    \$\begingroup\$ @cairdcoinheringaahing That's $1+$2+$3+…+$52=$1378. \$\endgroup\$
    – Adám
    Commented Dec 21, 2017 at 20:50
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Wheat Wizard
    Commented Dec 21, 2017 at 22:34

6 Answers 6

1
\$\begingroup\$

Japt, 5 bytes

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

õ x*V

Try it

\$\endgroup\$
1
  • \$\begingroup\$ Alternatively, õ*V X \$\endgroup\$ Commented Dec 21, 2017 at 22:12
1
\$\begingroup\$

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 *.

\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica), 13 bytes

#*(#+1)*#2/2&

Try it online!

\$\endgroup\$
0
\$\begingroup\$

R, 23 bytes

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

Try it online!

Takes input as amount, weeks.

\$\endgroup\$
0
\$\begingroup\$

Python 3, 20 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Jelly, 3 bytes

R×S

Try it online!

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.