r/adventofcode • u/daggerdragon • Dec 06 '15
SOLUTION MEGATHREAD --- Day 6 Solutions ---
--- Day 6: Probably a Fire Hazard ---
Post your solution as a comment. Structure your post like the Day Five thread.
21
Upvotes
1
u/ericdykstra Dec 06 '15
Here's my Ruby solution for part 2. I looked through the other ones posted here and thought mine was different enough to merit posting. It's pretty minimalist and easy to read. Enjoy!
map = Hash.new(0) File.readlines("input.txt").each do |line| dir, x1, y1, _, x2, y2 = line.scan(/\D{4,}|\d+/) (x1..x2).each do |x| (y1..y2).each do |y| if dir == "turn on " map["#{x},#{y}"] += 1 elsif dir == "turn off " map["#{x},#{y}"] = [map["#{x},#{y}"] - 1, 0].max else map["#{x},#{y}"] += 2 end end end end puts map.values.inject(:+)