18
Challenge
Write the shortest code that can sum all the time durations that appear in the stdin. The program must only consider the strings that match with one of the following patterns and ignore the rest.
HH:MM:SS (it will be interpreted as HH hours, MM minutes and SS seconds)
H:MM:SS (it will be interpreted as H hours, MM minutes and SS seconds)
MM:SS (it will be interpreted as MM minutes, SS seconds)
M:SS (it will be interpreted as M minutes, SS seconds)
examples of strings that match with the enumerated patterns:
12:00:01
2:03:22
00:53
9:13
The output should be of the form
HHh MMm SSs (that means HH hours, MM minutes and SS seconds with non-zero-padding)
Example
STDIN
View the Welcome video.
Video: 10:37 min.
View the video introduction to the course.
Video: 3:30 min. View the video of how to use the Lesson Overview.
Video: 9:13 min.
View the video overview of how to use the Epsilen system to share your work.
Video: 03:15 min.
View the video to learn about the State of Texas Assessment of Academic Readiness (STAAR).
Video: 1:05:26 min.
STDOUT
1h 32m 1s
time is a special topic to me... I love this question! – ojblass – 2014-12-15T19:40:30.873
What about strings like
10:4:56
? According current specification they have to be treated as4m 56s
, part10
will be ignored. Same question about10:12:7
does it mean10m 12s
with ignoring of7
? Or handling of such strings can be implementation defined? – Qwertiy – 2014-12-11T10:19:36.107The program should only consider time durations with zero-padding in the minute and second fields. In your example the string "10:4:56" will be treated as 4m 56s. Also the string "10:12:7" will be interpreted as 10m 12s. – Alfredo Diaz – 2014-12-11T10:27:55.273
Strange, but ok :) – Qwertiy – 2014-12-11T10:31:05.750
How did you get
1h 19m 18s
in the output?37+30+13+15+26==121
,10+3+9+3+5==30
,1==1
, so I expect1h 32m 01s
. What's wrong in this logic? Also, such output format is that one which is expected, isn't it? – Qwertiy – 2014-12-11T10:58:09.143You are right. Sorry :S – Alfredo Diaz – 2014-12-11T11:05:44.963