### Project Euler #6 - Sum Square Difference

#### Peter Kim Frank on May 30, 2019

Continuing the wonderful community solutions to Project Euler.
This is Problem 6, sum square difference.
The sum of the squares of the first ten...
[Read Full]

no loops!

python3

`def sum_square_difference(n):`

`return (((n**2) * (n + 1)**2) / 4) - (n * (n + 1) * (2*n + 1) / 6)`

`print(sum_square_difference(100))`

I dont know why when I tried to upload images they dont appear

Aw yeah 👌

If some are wondering, that comes from well-known formulas for the sum of the first

nintegers andnsquares. There's a generalization, too, but also a pretty common formula for the firstncubes.A solid mathematical approach can really simplify programming challenges. It almost feels like cheating.

Definitely highlights the need for maths in software development.

Woah, alright, you win 😲.

Also, there's a guide here to embed code and images in markdown (what dev.to uses).

thanks, I'm going to check it.

Python!

I surrender!

Javascript !

Yours is good. But I have a feeling it uses more then one for/for each loop. May explain why it is a bit slower then mine. Not sure.

Yeah, also the fact that I'm iterating 2 times the same array !

Ruby:

Ruby is so elegant 😍

Here is my nodejs solution

output

Yours performs faster than the one I submitted, and still looks nice, well done !

EDIT: some of the

`let`

s could be replaced with`const`

though 🙈true

Rust Solution: Playground

My take on this problem in python:

Output:

Rust

Some fun!

## Benchmark result:

From ProjectEuler:

Please do not deprive others of going through the same process by publishing your solution outside of Project Euler; for example, on other websites, forums, blogs, or any public repositories (e.g. GitHub), et cetera. Members found to be spoiling problems will have their accounts locked.

:)

## Go

## goplay.space/#rQ0XekiCknZ

You can see the complete program on the playground link.

Ruby 2.7

Swift:

I like your posts!

Elixir: