Skip to content

Instantly share code, notes, and snippets.

@thatrubylove thatrubylove/6.rb
Last active Dec 29, 2015

Embed
What would you like to do?
Solution for problem #6 @ http://projecteuler.net/problem=6
sum = ->(num_list) { num_list.reduce(:+) }
square = ->(number ) { number * number }
squares = ->(num_list) { num_list.map {|num| square.(num) } }
sum_squares = ->(num_list) { sum.(squares.(num_list)) }
square_sum = ->(num_list) { square.(sum.(num_list)) }
gem 'minitest'
require 'minitest/autorun'
describe "sum_squares" do
it { assert_equal 385, sum_squares.(1..10) }
end
describe "square_sum" do
it { assert_equal 3025, square_sum.(1..10) }
end
describe "answer to the solution" do
it { assert_equal 25164150, square_sum.(1..100) - sum_squares.(1..100) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.