r/adventofcode • • Dec 02 '15

Spoilers Day 2 solutions

Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.

14 Upvotes

161 comments sorted by

View all comments

Show parent comment

1

u/haitei Dec 02 '15
m.combination(2).map{ |x| x.reduce(:*) }.reduce(:+)*2 + m.take(2).reduce(:*)

I did something like this at first but in the end

2*m[0]*m[1] + 2*m[0]*m[2] + 2*m[1]*m[2] + m[0]*m[1]

is just shorter and more readable :x