Skip to content

Instantly share code, notes, and snippets.

@bryanwoods
Last active December 29, 2015 05:19
Show Gist options
  • Save bryanwoods/7620549 to your computer and use it in GitHub Desktop.
Save bryanwoods/7620549 to your computer and use it in GitHub Desktop.
Feeling lazy
main :: IO()
main = do
putStrLn $ show result
where result = sum $ take 100000 (zipWith (*) [2,4..] [1,3..])
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