-
-
Save thatrubylove/7636180 to your computer and use it in GitHub Desktop.
Solution for problem #6 @ http://projecteuler.net/problem=6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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