Skip to main content
1 of 3
FryAmTheEggman
  • 17.5k
  • 3
  • 40
  • 97

##Pyth - 15 * .5 = 7.5

s+mrhQ-Qdr1Q]]Q

Try it online.

Expects input on stdin. Independently discovered algorithm.

Explanation:

Q=eval(input())       : implicit
s                     : The sum of...
 +          ]]Q       : Add [[Q]] to the end of...
  m      r1Q          : map(...,range(1,Q))
   rhQ-Qd             : range(Q-d,Q+1)[::-1]

Sadly, pyth's sum function will crash on an empty list, so I lose a byte having to add Q to the list before summing (otherwise 1 would crash).

FryAmTheEggman
  • 17.5k
  • 3
  • 40
  • 97