24
\$\begingroup\$

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.

\$\endgroup\$

34 Answers 34

1
2
0
\$\begingroup\$

Groovy, 90/94 bytes

90 byte version (only works in a script):

24.times{a->s=' ';m=a%12?:12;println"${a<10?0:''}$a:00 ${m<10?s:''}$m:00${a<12?'a':'p'}m"}

94 byte version:

24.times{a->def s=' ',m=a%12?:12;println"${a<10?0:''}$a:00 ${m<10?s:''}$m:00${a<12?'a':'p'}m"}
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

VBA, 91 Bytes

Anonymous VBE immediate window function that outputs to the VBE immediate window.

For i=0To 23:t=TimeSerial(i,0,0):?Format(t,"hh:mm")Right("  "+Format(t,"h:mmam/pm"),8):Next
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Hi Sir, you can save 8 bytes by replacing Right(" "+Format(t,"h:mmam/pm"),8) with &" "&format(t,"h:mmam/pm") :) \$\endgroup\$ – remoel Nov 6 '17 at 10:53
  • \$\begingroup\$ @remoel - unfortunately the correction you have purposed is not valid as it does not account for the double spacing on hours that have a single digit hour value - and thus does not produce the correct MD5 hash \$\endgroup\$ – Taylor Scott Nov 6 '17 at 18:20
  • \$\begingroup\$ ah Yes. I'm sorry. I forgot about the md5. my bad. Just one more thing, your code output 12am-12am not 12am-11pm. :3 \$\endgroup\$ – remoel Nov 7 '17 at 6:49
  • \$\begingroup\$ @remoel, ahh - you are correct; and I have fixed this \$\endgroup\$ – Taylor Scott Nov 7 '17 at 17:23
0
\$\begingroup\$

LOLCODE, 365 bytes

I'll golf down...

HAI 1.3
VISIBLE "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 1:00pm"
KTHXBYE

Try it online!

| improve this answer | |
\$\endgroup\$
-1
\$\begingroup\$

C#, 91 bytes

for(var i=0;i<24;i++){Console.Write($"{i:00}:00 {(i+11)%12+1,2}:00 {(i>11?"p":"a")}m\n");};

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ hmmm... for values of I less than 10, this doesn't print a leading 0 for the hour of the military time. \$\endgroup\$ – STLDev Jun 1 '16 at 0:24
  • \$\begingroup\$ good call, should display it properly now \$\endgroup\$ – AntonB Jun 2 '16 at 2:06
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.