Skip to main content
added 57 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Python 3, 28 28  27 bytes

-1 thanks to xnor

lambda n:n*~-n*(n**3-~n*n)*(n/4+1/6)

Try it online!Try it online!

Implements \$n(n-1)(n+1)(3n+2)/12\$


Python 2, 29 29  28 bytes: lambda n:n*~-n*-~n*(3*n+2)/12lambda n:(n**3-n)*(3*n+2)/12

Python 3, 28 bytes

lambda n:n*~-n*-~n*(n/4+1/6)

Try it online!

Implements \$n(n-1)(n+1)(3n+2)/12\$


Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12

Python 3,  28  27 bytes

-1 thanks to xnor

lambda n:(n**3-n)*(n/4+1/6)

Try it online!

Implements \$n(n-1)(n+1)(3n+2)/12\$


Python 2,  29  28 bytes: lambda n:(n**3-n)*(3*n+2)/12

deleted 77 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Python 3, 28 bytes

(Assuming code-golf is the winning criteria, but also efficient at O(1).)

lambda n:n*~-n*-~n*(n/4+1/6)

Try it online!

Implements \$n(n-1)(n+1)(3n+2)/12\$


Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12

Python 3, 28 bytes

(Assuming code-golf is the winning criteria, but also efficient at O(1).)

lambda n:n*~-n*-~n*(n/4+1/6)

Try it online!


Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12

Python 3, 28 bytes

lambda n:n*~-n*-~n*(n/4+1/6)

Try it online!

Implements \$n(n-1)(n+1)(3n+2)/12\$


Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12

added 268 characters in body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Python 2Python 3, 2928 bytes

(Assuming code-golf is the winning criteria, but also efficient at O(1).)

lambda n:n*~-n*-~n*(3*n+2)n/124+1/6)

Try it online!Try it online!


Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12

Python 2, 29 bytes

(Assuming code-golf is the winning criteria, but also efficient at O(1).)

lambda n:n*~-n*-~n*(3*n+2)/12

Try it online!

Python 3, 28 bytes

(Assuming code-golf is the winning criteria, but also efficient at O(1).)

lambda n:n*~-n*-~n*(n/4+1/6)

Try it online!


Python 2, 29 bytes: lambda n:n*~-n*-~n*(3*n+2)/12

Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282
Loading