Just waiting for the smallest constellation could be wrong, I can imagine the lights forming even smaller image after (or before) showing the message. So, I printed all the possibilities fitting to an old-school terminal. In my case, there were three, and one of them contained the message. I printed the time along the way, so I solved both the parts in one go.
#!/usr/bin/perlusewarnings;usestrict;useList::Utilqw{ min max };my@lights;while(<>){push@lights,[/(-?\d+)/g];}my$time=0;while(1){show()ifwidth()<80;update();++$time;}sub width{max(map $_->[0], @lights) - min(map$_->[0],@lights)}sub show{my%grid;my($min_x,$max_x,$min_y,$max_y)=($lights[0][0],$lights[0][0],$lights[0][1],$lights[0][0]);formy$light(@lights){$min_x=$light->[0]if$light->[0]<$min_x;$min_y=$light->[1]if$light->[1]<$min_y;$max_x=$light->[0]if$light->[0]>$max_x;$max_y=$light->[1]if$light->[1]>$max_y;++$grid{$light->[0]}{$light->[1]};}formy$y($min_y..$max_y){formy$x($min_x..$max_x){print$grid{$x}{$y}?'#':'.';}print"\n";}print"$time\n";}sub update{formy$light(@lights){$light->[0]+=$light->[2];$light->[1]+=$light->[3];}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just waiting for the smallest constellation could be wrong, I can imagine the lights forming even smaller image after (or before) showing the message. So, I printed all the possibilities fitting to an old-school terminal. In my case, there were three, and one of them contained the message. I printed the time along the way, so I solved both the parts in one go.