r/adventofcode • • 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

171 comments sorted by

View all comments

Show parent comment

1

u/haljin Dec 06 '15

For the second problem one just needs to substitute the function the slight processes are running :)

bightness_light_process(Brigthness) ->
   	receive
		off when Brigthness =:= 0 ->
			bightness_light_process(0);
		off ->
			bightness_light_process(Brigthness - 1);
   		on ->
			bightness_light_process(Brigthness + 1);
		toggle ->
			bightness_light_process(Brigthness + 2);
		{get_state, Pid} ->
			Pid ! Brigthness
	end.

And modify the spawn/receive functions slightly.

After some timing: it takes about 1 min 18 seconds on my machine to go through all the instructions and send all the messages. About 4 seconds to collect the results. All in all, not too bad.