Gauss's Addition

Published by persolut in

Watch the video about Gauss's Addition in the Resources tab to see how you can use the formula for your function.

Gauss

Create a function that adds all the numbers together from 1 to n or, if two numbers are given: n to m. The input can be in any order.

Examples

Gauss({ 100 }) ➞ 5050 // From the video

Gauss({ 5001, 7000 }) ➞ 12001000 // Also ^^

Gauss({ 1975, 165 }) ➞ 1937770

Notes

  • Try not to use a for or while loop.
  • Try not to create a recursive function.
  • Use the formula explained in the video.
  • Bonus kudos if you can do it without watching the video!
Watch a quick demo on how Edabit works.