Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Solves #6

  • Loading branch information...
commit 3d0be114c3e6d566f5e2a07591ecaccbaad22472 1 parent 0ccef80
@ckdake authored
Showing with 14 additions and 0 deletions.
  1. +1 −0  README
  2. +13 −0 src/6.rb
View
1  README
@@ -6,3 +6,4 @@ Solved!
* 3 2011.09.22 - `ruby src/3.rb` (and _much_ faster `ruby src/3.lib.rb` that uses a library to generate primes)
* 4 2011.09.22 - `ruby src/4.rb`
* 5 2011.09.22 - `ruby src/5.rb`
+* 6 2013.01.02 - `ruby src/6.rb`
View
13 src/6.rb
@@ -0,0 +1,13 @@
+#The sum of the squares of the first ten natural numbers is,
+#
+#12 + 22 + ... + 102 = 385
+#The square of the sum of the first ten natural numbers is,
+#(1 + 2 + ... + 10)2 = 552 = 3025
+#Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.
+#Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
+
+sumsq = (1..100).inject(0){ |x, i| x + (i*i) }
+sum = (1..100).inject(0){ |x, i| x + i }
+sqsum = sum*sum
+
+puts sqsum - sumsq
Please sign in to comment.
Something went wrong with that request. Please try again.