Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
Last active December 29, 2015 07:29
Show Gist options
  • Save thatrubylove/7636180 to your computer and use it in GitHub Desktop.
Save thatrubylove/7636180 to your computer and use it in GitHub Desktop.
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