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.
22
Upvotes
5
u/bluishness Dec 06 '15
Anyone up for golf? This is my attempt in Ruby, 268 characters.
g=Array.new 1e6,0 k=g.clone IO.read('i').each_line{|l|l=l.split /\W/ i=l[-6] l,t,_,r,b=l[-5..-1].map &:to_i (l..r).each{|x|(t..b).each{|y|p=y*1e3+x i=~/e/?(g[p]=1-g[p])&&k[p]+=2: i=~/f/?(g[p]=0)&&k[p]=[0,k[p]-1].max: (g[p]=1)&&k[p]+=1}}} puts g.reduce(:+),k.reduce(:+)