Gauss's Addition

Published by Matt 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.
Watch a quick demo on how Edabit works.