adamcrussell

Lights On!

For the Perl Weekly Challenge 039 we are asked to compute the total time a light is on, based on some log entries.

Part 1

ch-1.pl
ch-1.pl

Sample Run

$ perl perl/ch-1.pl
1 hours 50 minutes

What I Did

I think this implementation is straightforward enough due to the use of DateTime and DateTime::Duration. Each entry in the log is parsed and the total time on is computed. The parsing itself is only complicated by the need to remove some spaces and unnecessary characters.

The main consideration, other than cleaning and parsing the input, is to detect the overlapping of times, which I use DateTime to do.

Comments for this post were locked by the author