← Back to challenges

Gauss's Addition

PythonHardmathnumbers

Instructions

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.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.