Skip to content

Instantly share code, notes, and snippets.

@broguinn
Created August 30, 2013 00:55
Show Gist options
  • Save broguinn/6385213 to your computer and use it in GitHub Desktop.
Save broguinn/6385213 to your computer and use it in GitHub Desktop.
difference_sum_squares
def difference_sum_square(number)
sum_squared = 0
number.times do |num|
sum_squared += num + 1
end
sum_squared = sum_squared ** 2
square_sums = 0
number.times do |num|
square_sums += (num + 1) ** 2
end
sum_squared - square_sums
end
puts difference_sum_square(100)
require 'rspec'
require 'difference_sum_squares'
describe 'difference_sum_square' do
it 'returns the difference between 1 squared and the sum of 1, sqaured' do
difference_sum_square(1).should eq 0
end
it 'returns the difference for the number 2' do
difference_sum_square(2).should eq 4
difference_sum_square(10).should eq 2640
end
it 'returns the difference for the number 100' do
difference_sum_square(100).should eq 25164150
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment