/* 24 and 12 hour times (code golf) in Picat. https://codegolf.stackexchange.com/questions/80974/24-and-12-hour-times """ 24 and 12 Hour Times Write a program or function with no input that prints or returns this string of 24-hour and 12-hour times: 00:00 12:00am 01:00 1:00am 02:00 2:00am 03:00 3:00am 04:00 4:00am 05:00 5:00am 06:00 6:00am 07:00 7:00am 08:00 8:00am 09:00 9:00am 10:00 10:00am 11:00 11:00am 12:00 12:00pm 13:00 1:00pm 14:00 2:00pm 15:00 3:00pm 16:00 4:00pm 17:00 5:00pm 18:00 6:00pm 19:00 7:00pm 20:00 8:00pm 21:00 9:00pm 22:00 10:00pm 23:00 11:00pm The string must be output exactly as it appears here. The only exception is that it may optionally have a single trailing newline. So the MD5 hash of your output should be 827ae6e2dbb1df494930baedb3ee2653 if you do not have a trailing newline and cd4c3d18abee9bafb495f390a919a13f if you do. (Your hash could be different if your system uses another type of newline but that's OK.) The shortest code in bytes wins. Tiebreaker is earlier answer. """ 00:00 12:00am 01:00 1:00am 02:00 2:00am 03:00 3:00am 04:00 4:00am 05:00 5:00am 06:00 6:00am 07:00 7:00am 08:00 8:00am 09:00 9:00am 10:00 10:00am 11:00 11:00am 12:00 12:00pm 13:00 1:00pm 14:00 2:00pm 15:00 3:00pm 16:00 4:00pm 17:00 5:00pm 18:00 6:00pm 19:00 7:00pm 20:00 8:00pm 21:00 9:00pm 22:00 10:00pm 23:00 11:00pm This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go ?=> foreach(I in 0..23) p(I).print end, nl. go => true. % special modulo: if mod(N,M)=0 -> result = M m(N,M)=R=>P=mod(N,M),R=cond(P==0,M,P). p(I)=to_fstring("%02d:00 %2d:00%w\n",I,m(I,12),cond(I<12,"am","pm")).