-
-
Save bryanwoods/7620549 to your computer and use it in GitHub Desktop.
Feeling lazy
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
main :: IO() | |
main = do | |
putStrLn $ show result | |
where result = sum $ take 100000 (zipWith (*) [2,4..] [1,3..]) |
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
RANGE = 1..Float::INFINITY | |
def evens | |
RANGE.lazy.select(&:even?) | |
end | |
def odds | |
RANGE.lazy.select(&:odd?) | |
end | |
def solution | |
evens.zip(odds).map { |x, y| x * y }.take(100_000).reduce(:+) | |
end | |
p solution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment