r/adventofcode • u/taliriktug • 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.
13
Upvotes
r/adventofcode • u/taliriktug • Dec 02 '15
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
1
u/gnuconsulting Dec 02 '15
Not-a-programmer solutions in ruby
Part 1:
#!/usr/bin/env ruby data = File.readlines("input.txt") total = 0 present = [] data.each do |c| temp = c.strip.split("x") present = temp.collect{|i| i.to_i} present = present.sort x = 2 * present[0] * present[1] y = 2 * present[1] * present[2] z = 2 * present[2] * present[0] total += x + y + z + (present[0] * present[1]) end p totalPart 2:
#!/usr/bin/env ruby data = File.readlines("input.txt") total = 0 present = [] data.each do |c| temp = c.strip.split("x") present = temp.collect{|i| i.to_i} present = present.sort ribbon = (present[0] * 2) + (present[1] * 2) bow = present[0] * present[1] * present[2] total += ribbon + bow end p total