List all times in the day at a half hour rate

31

8

Shortest answer wins.

It must be sorted, and in 24hr time. The final line does not have a comma.

Output should be as follows:

'00:00',
'00:30',
'01:00',
'01:30',
'02:00',
'02:30',
'03:00',
'03:30',
'04:00',
'04:30',
'05:00',
'05:30',
'06:00',
'06:30',
'07:00',
'07:30',
'08:00',
'08:30',
'09:00',
'09:30',
'10:00',
'10:30',
'11:00',
'11:30',
'12:00',
'12:30',
'13:00',
'13:30',
'14:00',
'14:30',
'15:00',
'15:30',
'16:00',
'16:30',
'17:00',
'17:30',
'18:00',
'18:30',
'19:00',
'19:30',
'20:00',
'20:30',
'21:00',
'21:30',
'22:00',
'22:30',
'23:00',
'23:30'

Espen Schulstad

Posted 2015-05-07T08:11:46.953

Reputation: 441

6Is this 24 hour time? Could you please provide the entire output? – xnor – 2015-05-07T08:21:34.470

1Must the output be sorted? – orlp – 2015-05-07T08:30:35.700

Yes. It must be sorted, and in 24hr time. Sorry will update. – Espen Schulstad – 2015-05-07T08:39:04.290

Does the final line have a comma? – xnor – 2015-05-07T08:55:14.580

Final line does not have a comma :) – Espen Schulstad – 2015-05-07T08:57:09.710

Can we use a double quote instead of single ? – Optimizer – 2015-05-07T08:58:48.730

44What if it takes my program 23.5 hours to run? – tfitzger – 2015-05-07T13:59:45.850

9I can't see why that would be a negative. – Espen Schulstad – 2015-05-07T14:00:53.100

@tfitzger I had a go at doing that - it was 40+ more chars! – Tim – 2015-05-07T18:27:58.247

what about daylight saving, leap seconds etc? – Ewan – 2015-05-07T19:18:20.687

6Just a small suggestion about upvotes. I try to upvote every valid answer to a challenge I create as a small reward for taking the effort. I have plenty of rep and don't really need an upvote here, but please consider other answerers who may give up responding if their answers are ignored after lots of hard thinking and debugging. – Logic Knight – 2015-05-16T11:21:52.243

Taking a next step: there is an emoji for each time at a half hour rate – Matthew Roh – 2017-03-28T06:49:05.437

Answers

17

Pyth, 26 bytes

Pjbm%"'%02d:%s0',"d*U24"03

Demonstration.

We start with the cartesian product of range(24) (U24) with the string "03".

Then, we map these values to the appropriate string formating substitution (m%"'%02d:%s0',"d).

Then, the resultant strings are joined on the newline character (jb).

Finally, we remove the trailing comma (P) and print.

isaacg

Posted 2015-05-07T08:11:46.953

Reputation: 39 268

1Looks like we have a new contender for the prize. Author of pyth, that's almost cheating ;) – Espen Schulstad – 2015-05-07T18:54:08.690

15

Befunge-93, 63 bytes

0>"'",:2/:55+/.55+%.":",:2%3*v
 ^,+55,","<_@#-*86:+1,"'".0. <

 

animation (animation made with BefunExec)

Mikescher

Posted 2015-05-07T08:11:46.953

Reputation: 251

14

Bash: 58 47 46 characters

h=`echo \'{00..23}:{0,3}0\'`
echo "${h// /,
}"

manatwork

Posted 2015-05-07T08:11:46.953

Reputation: 17 865

I like this solution :) – Espen Schulstad – 2015-05-07T16:35:19.390

1Anonymous user suggested echo \'{00..23}:{0,3}0\'|sed 's/ /,\n/g' of 40 characters. Nice. Thanks. But I prefer to make use of bash's own strength. – manatwork – 2015-05-08T09:58:02.797

1printf "'%s',\n" {00..23}:{0,3}0 – izabera – 2015-05-09T12:22:29.103

@manatwork oh i didn't read the question well, sorry... – izabera – 2015-05-09T12:27:22.087

printf "'%s'\n" {00..23}:{0,3}0|sed $\!s/$/,/ is 45 bytes – izabera – 2015-05-09T12:31:04.370

Or even 44 if you include a literal line break in the format string instead of \n. Nice, but I prefer my bash solutions to be pure bash as possible. – manatwork – 2015-05-09T12:38:55.233

10

CJam, 31 30 29 bytes

24,[U3]m*"'%02d:%d0',
"fe%~7<

This is pretty straight forward using printf formatting:

24,                              e# get the array 0..23
   [U3]                          e# put array [0 3] on stack
       m*                        e# do a cartesian product between 0..23 and [0 3] array
                                 e# now we have tuples like [[0 0], [0 3] ... ] etc
         "'%02d:%d0',
"fe%                             e# this is standard printf formatting. What we do here is
                                 e# is that we format each tuple on this string
    ~7<                          e# unwrap and remove comma and new line from last line
                                 e# by taking only first 7 characters

Try it online here

Optimizer

Posted 2015-05-07T08:11:46.953

Reputation: 25 836

Looks like this is going to take the gold. We'll give it until tomorrow ;) – Espen Schulstad – 2015-05-07T16:38:15.190

@EspenSchulstad I wish it would actually give me some gold. sigh – Optimizer – 2015-05-07T16:39:17.813

3Remember, it's not only viritual gold, but also honor. What we do in life echoes in eternity. – Espen Schulstad – 2015-05-07T16:40:31.880

10

Python 2, 58 56 bytes

for i in range(48):print"'%02d:%s0',"[:57-i]%(i/2,i%2*3)

Like sentiao's answer but using a for loop, with slicing to remove the comma. Thanks to @grc for knocking off two bytes.

Sp3000

Posted 2015-05-07T08:11:46.953

Reputation: 58 729

Would this work: "'%02d:%s0',"[:57-i] – grc – 2015-05-07T14:16:08.217

@grc Ahaha of course, that's much better – Sp3000 – 2015-05-07T15:03:29.797

Better than I could do! – Tim – 2015-05-07T18:15:18.530

6

Java - 119 bytes

I started with Java 8's StringJoiner, but that means including an import statement, so I decided to do it the old way:

void f(){String s="";for(int i=0;i<24;)s+=s.format(",\n'%02d:00',\n'%02d:30'",i,i++);System.out.print(s.substring(2));}

Perhaps this can be improved by getting rid of the multiple occuring String and System keywords.

Sander

Posted 2015-05-07T08:11:46.953

Reputation: 131

a version in groovy perhaps :) – Espen Schulstad – 2015-05-07T10:24:53.700

You can shorten this to 159: Remove the space before a, move the i increment, lose the for braces, and move the comma/newline to the beginning (which lets you use the shorter substring and get rid of length()). Since functions are allowed by default, you can get make it even shorter by eliminating boilerplate: void f(){String s="";for(int i=0;i<24;)s+=String.format(",\n'%02d:00',\n'%02d:30'",i,i++);System.out.print(s.substring(2));} Even a bit more if you make it just return the string instead of printing it, but that seems to go against the spirit, if not the letter. – Geobits – 2015-05-07T13:00:42.860

Damn, that's brilliant! I got to keep those tricks in mind, thanks! – Sander – 2015-05-07T13:53:50.880

Oh, another few: change String.format to s.format. Your compiler/IDE may complain about it, but it works ;) – Geobits – 2015-05-07T13:55:33.510

1Nice one! format's a static method, so it should be accessed by its class, but indeed, using it this way also works! – Sander – 2015-05-08T06:18:36.563

5

Ruby, 94 61 56 51

$><<(0..47).map{|i|"'%02d:%02d'"%[i/2,i%2*30]}*",
"

Thanks to @blutorange (again) for his help in golfing!

rorlork

Posted 2015-05-07T08:11:46.953

Reputation: 1 421

You can reduce that to 61 bytes: puts (0..47).to_a.map{|h|"'%02d:%02d'"%[h/2,h%2*30]}.join"," (there's a newline after the last comma) – blutorange – 2015-05-07T14:37:40.663

Thank you again! I really didn't try it much... – rorlork – 2015-05-07T14:42:38.137

Ruby needs some love. 58 bytes ;) puts Array.new(48){|i|"'%02d:%02d'"%[i/2,i%2*30]}.join',' – blutorange – 2015-05-07T16:57:15.113

@blutorange @rcrmn you can reduce 4 more bytes (and get to my solution below :)) ) by replacing .join with * :) – Tomáš Dundáček – 2015-05-08T05:54:18.117

5

Perl, 52 50 48 45B

$,=",
";say map<\\'$_:{0,3}0\\'>,"00".."23"

With help from ThisSuitIsBlackNot :)

alexander-brett

Posted 2015-05-07T08:11:46.953

Reputation: 1 485

4

JAVA 95 94 bytes

I love the fact that printf exists in Java:

void p(){for(int i=0;i<24;)System.out.printf("'%02d:00',\n'%02d:30'%c\n", i,i++,(i<24)?44:0);}

Ungolfed

void p(){
    for(int i=0;i<24;)
        System.out.printf("'%02d:00',\n'%02d:30'%c\n", i,i++,(i<24)?44:0);
}

EDIT Replaced the ',' with 44

tfitzger

Posted 2015-05-07T08:11:46.953

Reputation: 979

24.times{printf("'%02d:00',\n'%02d:30'%c\n",it,it,(it<24)?44:0)}​ in groovy :) same solution, just that it's down to 65 chr – Espen Schulstad – 2015-05-07T16:24:29.667

@EspenSchulstad Would that be considered a standalone function, or is there other boilerplate that would be needed to get it to run? – tfitzger – 2015-05-07T16:28:52.573

1If you have groovy, you could either run that in groovysh or just as a groovy script in a .groovy-file. then you don't need no function. – Espen Schulstad – 2015-05-07T16:30:16.603

http://groovyconsole.appspot.com/edit/24001 – Espen Schulstad – 2015-05-07T16:33:48.500

@EspenSchulstad Interesting. I've only done minimal work with Groovy. – tfitzger – 2015-05-07T16:56:20.237

4

Pyth, 32 31 bytes

I golfed something in python but it turned out to be exactly the same as Sp3000's answer. So I decided to give Pyth a try:

V48<%"'%02d:%d0',",/N2*3%N2-54N

It's a exact translation of Sp3000 answer:

for i in range(48):print"'%02d:%d0',"[:57-i]%(i/2,i%2*3)

It's my first go at Pyth, so please do enlighten me about that 1 byte saving.

Def

Posted 2015-05-07T08:11:46.953

Reputation: 602

Nicely done, and welcome to Pyth. – isaacg – 2015-05-07T20:25:04.817

3

Ruby, 54 51 bytes

puts (0..23).map{|h|"'#{h}:00',
'#{h}:30'"}.join",
"

golgappa

Posted 2015-05-07T08:11:46.953

Reputation: 31

1You can reduce 3 bytes by changing \n to actual newlines and removing the space between join and ". On the other hand, take note that the specified output has leading zeros for the hours. – rorlork – 2015-05-07T16:13:27.663

Also, some more bytes by changing puts to $><< (without space) and .join with *. You still have the leading zero problem for the hours, though. – rorlork – 2015-05-08T08:57:23.630

3

PHP, 109 bytes

foreach(new DatePeriod("R47/2015-05-07T00:00:00Z/PT30M")as$d)$a[]=$d->format("'H:i'");echo implode(",\n",$a);

nickb

Posted 2015-05-07T08:11:46.953

Reputation: 351

3

C, 116,115,101,100,95,74,73, 71

May be able to scrape a few more bytes off this...

main(a){for(;++a<50;)printf("'%02d:%d0'%s",a/2-1,a%2*3,a<49?",\n":"");}

Joshpbarron

Posted 2015-05-07T08:11:46.953

Reputation: 787

You can save 3 bytes by creating a function rather than a complete program. Just replace "main" with "f", or whatever your favourite letter is. – Bijan – 2017-03-27T22:14:29.567

Oh thats a very nice suggestion.....one I always forget! – Joshpbarron – 2017-03-28T07:15:03.463

3

T-SQL, 319 307 305 bytes

WITH t AS(SELECT t.f FROM(VALUES(0),(1),(2),(3),(4))t(f)),i AS(SELECT i=row_number()OVER(ORDER BY u.f,v.f)-1FROM t u CROSS APPLY t v),h AS(SELECT i,h=right('0'+cast(i AS VARCHAR(2)),2)FROM i WHERE i<24)SELECT''''+h+':'+m+CASE WHEN i=23AND m='30'THEN''ELSE','END FROM(VALUES('00'),('30'))m(m) CROSS APPLY h

Un-golfed version:

WITH
t AS(
    SELECT
        t.f
    FROM(VALUES
         (0),(1),(2),(3),(4)
    )t(f)
),
i AS(
    SELECT
        i = row_number() OVER(ORDER BY u.f,v.f) - 1
    FROM t u 
    CROSS APPLY t v
),
h AS(
    SELECT
        i,
        h = right('0'+cast(i AS VARCHAR(2)),2)
    FROM i
    WHERE i<24
)
SELECT
    '''' + h + ':' + m + CASE WHEN i=23 AND m='30' 
                              THEN '' 
                              ELSE ',' 
                         END
FROM(
    VALUES('00'),('30')
)m(m)
CROSS APPLY h

Pieter Geerkens

Posted 2015-05-07T08:11:46.953

Reputation: 131

2

Pyth, 34 bytes

j+\,bmjk[\'?kgd20Z/d2\:*3%d2Z\')48

This can definitely be improved.

Try it online: Pyth Compiler/Executor

Explanation:

     m                          48   map each d in [0, 1, ..., 47] to:
        [                      )       create a list with the elements:
         \'                              "'"
           ?kgd20Z                       "" if d >= 20 else 0
                  /d2                    d / 2
                     \:                  ":"
                       *3%d2             3 * (d%2)
                            Z            0
                             \'          "'"
      jk                               join by "", the list gets converted into a string
j+\,b                                join all times by "," + "\n"

Jakube

Posted 2015-05-07T08:11:46.953

Reputation: 21 462

Always impressive with these golfing languages :) I do somehow appreciate it more when it's done in a non-golfing language. Does anyone know if there is a golf-jar-lib to java for instance? – Espen Schulstad – 2015-05-07T10:30:05.680

Obligatory port of sentiao's gives 31: j+\,bm%"'%02d:%s0'",/d2*3%d2 48 with string formatting

– Sp3000 – 2015-05-07T12:28:43.717

2

Swift, 74 bytes

Updated for Swift 2/3...and with new string interpolation...

for x in 0...47{print("'\(x<20 ?"0":"")\(x/2):\(x%2*3)0'\(x<47 ?",":"")")}

GoatInTheMachine

Posted 2015-05-07T08:11:46.953

Reputation: 463

The final line is specified to not have a comma & your code prints it. – Kyle Kanos – 2015-05-07T13:32:16.230

2

Python 2, 69 bytes

print',\n'.join(["'%02d:%s0'"%(h,m)for h in range(24)for m in'03'])

Quite obvious, but here's an explanation:

  • using double-for-loop
  • alternating between '0' and '3' in string format is shorter than a list
  • %02d does the padding for h
  • mdoesn't need padding as the alternating character is on a fixed position
  • '\n'.join() solves the final-line requirements

I have no idea if it can be done shorter (in Python 2).

by Sp3000, 61 bytes : print',\n'.join("'%02d:%s0'"%(h/2,h%2*3)for h in range(48))

sentiao

Posted 2015-05-07T08:11:46.953

Reputation: 61

1How about: print',\n'.join("'%02d:%s0'"%(h/2,h%2*3)for h in range(48)) – Sp3000 – 2015-05-07T11:29:47.653

Brilliant, Sp3000! (you should post it) – sentiao – 2015-05-07T11:32:11.607

1Nah, not different enough to post in my book. All I did was drop the square brackets (which are unnecessary even in your one) and drop m. (Also it's 59 bytes, not 61) – Sp3000 – 2015-05-07T11:35:59.847

2

golflua 52 51 chars

~@n=0,47w(S.q("'%02d:%d0'%c",n/2,n%2*3,n<47&44|0))$

Using ascii 44 = , and 0 a space saves a character.

An ungolfed Lua version would be

for h=0,47 do
   print(string.format("'%02d:%d0'%c",h/2,h%2*3, if h<47 and 44 or 0))
end

The if statement is much like the ternary operator a > b ? 44 : 0.

Kyle Kanos

Posted 2015-05-07T08:11:46.953

Reputation: 4 270

2

Julia: 65 64 61 characters

[@printf("'%02d:%d0'%s
",i/2.01,i%2*3,i<47?",":"")for i=0:47]

Julia: 64 characters

(Kept here to show Julia's nice for syntax.)

print(join([@sprintf("'%02d:%d0'",h,m*3)for m=0:1,h=0:23],",
"))

manatwork

Posted 2015-05-07T08:11:46.953

Reputation: 17 865

2

Python, 60 58 64 bytes

for i in range(24):print("'%02d:00,\n%02d:30'"%(i,i)+', '[i>22])

Ungolfed:

for i in range(24):
    if i <23:
        print( ('0'+str(i))[-2:] + ':00,\n' + str(i) + ':30,')
    else:
        print( ('0'+str(i))[-2:] + ':00,\n' + str(i) + ':30')

Try it online here.

Tim

Posted 2015-05-07T08:11:46.953

Reputation: 2 789

1Why not put it on 1 line, and save another 2 bytes. – isaacg – 2015-05-07T18:15:15.323

I don't think this works - no leading zero on the hour. – isaacg – 2015-05-07T18:17:12.190

1@isaacg fixed that! – Tim – 2015-05-07T18:25:37.090

The output is not the same as in the original question. – sentiao – 2015-05-08T08:51:11.397

@sentiao what is different? – Tim – 2015-05-08T11:41:05.713

you can save a couple of bytes by mixing single and double quotes instead of escaping your quotes '\'%02d:00,\n%02d:30\'' could be "'%02d:00,\n%02d:30'" saving 2 bytes for the slashes – Alan Hoover – 2015-05-08T22:56:25.963

2

Haskell, 85 bytes

putStr$init$init$unlines$take 48['\'':w:x:':':y:"0',"|w<-"012",x<-['0'..'9'],y<-"03"]

Unfortunately printf requires a 19 byte import, so I cannot use it.

nimi

Posted 2015-05-07T08:11:46.953

Reputation: 34 639

2

JavaScript (ES6), 77 86+1 bytes

Didn't realize there had to be quotes on each line (+1 is for -p flag with node):

"'"+Array.from(Array(48),(d,i)=>(i>19?"":"0")+~~(i/2)+":"+3*(i&1)+0).join("',\n'")+"'"

old solution:

Array.from(Array(48),(d,i)=>~~(i/2).toFixed(2)+":"+3*(i&1)+"0").join(",\n")

ungolfed version (using a for loop instead of Array.from):

var a = [];
// there are 48 different times (00:00 to 23:30)
for (var i = 0; i < 48; i++) {
    a[i] =
        (i > 19 ? "" : "0") +
            // just a ternary to decide whether to pad
            // with a zero (19/2 is 9.5, so it's the last padded number)
        ~~(i/2) +
            // we want 0 to 24, not 0 to 48
        ":" +  // they all then have a colon
        3*(i&1) +
            // if i is odd, it should print 30; otherwise, print 0
        "0" // followed by the last 0
}
console.log(a.join(",\n"));

royhowie

Posted 2015-05-07T08:11:46.953

Reputation: 151

72: Array.from(Array(48),(d,i)=>\'${i>19?"":0}${0|i/2}:${i%2*3}0'`).join`,\n``. Replace \n with an actual newline. – Mama Fun Roll – 2015-11-07T00:22:54.187

2

Fortran 96

do i=0,46;print'(a1,i2.2,a,i2.2,a2)',"'",i/2,":",mod(i,2)*30,"',";enddo;print'(a)',"'23:30'";end

Standard abuse of types & requirement only for the final end for compiling. Sadly, due to implicit formatting, the '(a)' in the final print statement is required. Still, better than the C and C++ answers ;)

Kyle Kanos

Posted 2015-05-07T08:11:46.953

Reputation: 4 270

2

C# - 120 bytes

class P{static void Main(){for(var i=0;i<24;i++)System.Console.Write("'{0:00}:00',\n'{0:00}:30'{1}\n",i,i==23?"":",");}}

Berend

Posted 2015-05-07T08:11:46.953

Reputation: 131

2

, 39 chars / 67 bytes (non-competing)

↺;Ḁ⧺<Ḱ;)ᵖ`'⦃Ḁ<Ḕ?0:⬯}⦃0|Ḁ/2}:⦃Ḁ%2*3}0',”

Try it here (Firefox only).

Not a single alphabetical character in sight...

Mama Fun Roll

Posted 2015-05-07T08:11:46.953

Reputation: 7 234

2

PHP, 69 70 62 bytes

for($x=-1;++$x<47;)printf("'%02d:%d0',
",$x/2,$x%2*3)?>'23:30'

Try it online

Outputting '23:30' at the end is a bit lame, and so is closing the php context using ?> without opening or re-opening it. An cleaner alternative (but 65 bytes) would be:

for($x=-1;++$x<48;)printf("%s'%02d:%d0'",$x?",
":'',$x/2,$x%2*3);

Try it online

Thank you @Dennis for the tips. Alternative inspired by the contribution of @ismael-miguel.

mk8374876

Posted 2015-05-07T08:11:46.953

Reputation: 21

1Welcome to Programming Puzzles & Code Golf! Your code prints a null byte at the end. I'm not sure if that is allowed. – Dennis – 2016-01-11T05:44:38.700

@Dennis Thank you, you're right... I assumed PHP would see it as end-of-string. Posted a new version. – mk8374876 – 2016-01-11T18:43:06.280

<?...?>'23:30' saves three bytes. Also, you can replace \n with an actual newline. – Dennis – 2016-01-11T19:07:28.503

1

Python 2, 74 65 bytes

We generate a 2 line string for each hour, using text formatting:

print',\n'.join("'%02u:00',\n'%02u:30'"%(h,h)for h in range(24))

This code is fairly clear, but the clever indexing and integer maths in the answer by Sp3000 gives a shorter solution.

Logic Knight

Posted 2015-05-07T08:11:46.953

Reputation: 6 622

1no reason to use formatting for 00 and 30, save 9 bytes with "'%02u:00',\n'%02u:30'"%(h,h) – DenDenDo – 2015-05-07T10:42:33.120

you could save some bytes by having too loops : print',\n'.join("'%02u:%02u'"%(h,i)for h in range(24)for i in[0,30]) – dieter – 2015-05-07T11:01:02.417

Thanks DenDenDo. I used this to save some bytes. Dieter, I can see where your idea may help, but I could save more bytes with that idea from DenDenDo. – Logic Knight – 2015-05-08T11:25:35.810

1

Javascript, 89 bytes

for(i=a=[];i<24;)a.push((x="'"+("0"+i++).slice(-2))+":00'",x+":30'");alert(a.join(",\n"))

SuperJedi224

Posted 2015-05-07T08:11:46.953

Reputation: 11 342

1

Quick question: how many arguments Array.push() supports? ;)

– manatwork – 2015-05-07T14:31:54.913

You're right. That is a polyad. Thanks, I'll make that change after I finish testing my entry for another challenge. – SuperJedi224 – 2015-05-07T15:09:04.730

A few more characters can be removed with some elementary reorganizations: for(i=a=[];i<24;)a.push((x=("0"+i++).slice(-2))+":00",x+":30");alert(a.join(",\n")) – manatwork – 2015-05-07T15:28:25.883

There, I fixed it. – SuperJedi224 – 2015-05-07T15:38:32.603

That reuse of variable x is quite ugly coding habit. If you change the loop control variable to something else (as in my suggestion at 2015-05-07 15:28:25Z), then you can add the opening single quotes to x's value to reduce the two "'"+ pieces to one: for(i=a=[];i<24;)a.push((x="'"+("0"+i++).slice(-2))+":00'",x+":30'");alert(a.join(",\n")) – manatwork – 2015-05-07T15:58:29.777

That one's giving me a syntax error for some reason: "Invalid character '\u8203'" – SuperJedi224 – 2015-05-07T16:19:55.483

No idea what kind of crappy character keeps infiltrating in that text. If you type in the alert()'s parameter by hand, the rest of code should be fine. – manatwork – 2015-05-07T16:29:43.510

@manatwork Just asked google, unicode 8203 is a zero-width space, apparently. – SuperJedi224 – 2015-11-24T16:56:58.010

1

Python 2: 64 bytes

print ',\n'.join(['%02d:00,\n%02d:30'%(h,h) for h in range(24)])

Alan Hoover

Posted 2015-05-07T08:11:46.953

Reputation: 141

The output is not the same as in the original question. – sentiao – 2015-05-08T08:51:34.330

I don't know what happened to the edit I made. here is the correct version also 64 chars: print',\n'.join("'%02d:00',\n'%02d:30'"%(h,h)for h in range(24)) – Alan Hoover – 2015-05-08T14:04:09.080

1

Ruby - 52 bytes

puts (0..47).map{|i|"'%02d:%02d'"%[i/2,i%2*30]}*",
"

Tomáš Dundáček

Posted 2015-05-07T08:11:46.953

Reputation: 121

This seems like my solution with just the change of the .join for *... It's common courtesy to instead of just posting a new answer with a minor improvement, to suggest the improvement to the original poster. See http://meta.codegolf.stackexchange.com/questions/75/what-should-the-policy-on-improving-or-incorperating-other-peoples-solutions-be

– rorlork – 2015-05-08T08:13:12.850

@rcrmn I agree I made a mistake and I apologize for it - should've had looked for other ruby answers first. Great work though in your answer with $><<! – Tomáš Dundáček – 2015-05-08T08:45:40.757

Don't worry about it, you are new here: I was advising you so that you could avoid this in the future. – rorlork – 2015-05-08T08:55:01.303

1

PHP 89 88 87 85 bytes

<?for($i=0;$i<24;$i++){$a=sprintf("%02d",$i);echo"'$a:00',\n'$a:30'",$i<23?",\n":'';}

I tried but it isn't the shortest in PHP.

Old code:

<?for($i=0;$i<24;$i++){($i<10?$a="0$i":$a=$i);echo"'$a:00',\n'$a:30'".($i==23?'':",\n");}

Timo

Posted 2015-05-07T08:11:46.953

Reputation: 181

Why the parenthesis around the whole first ternary expression? And reverse the last ternary to use the shorter < operator instead of ==: $i<23?",\n":''. – manatwork – 2015-05-08T13:25:15.040

@manatwork So it adds the 0 in front of every number lower than 10, without the parenthesis it wouldn't work. With the < it would add a comma at the end – Timo – 2015-05-08T13:29:27.217

Works for me. But anyway, you are using the ternary in a strange way. Usually the assignment is done outside. And that expression could also be rewritten to compare against 9 instead of 10, sparing another 1 character: <?php for($i=0;$i<24;$i++){$a=$i>9?$i:"0$i";echo"'$a:00',\n'$a:30'".($i<23?",\n":'');} – manatwork – 2015-05-08T13:34:36.217

Ah yes, I had it the other way around. Thank you. – Timo – 2015-05-08T13:42:53.690

One more thing: the parenthesis around the last (now only) ternary is required just because you concatenate it to the other piece of string. As echo supports multiple parameters, just enumerate them separated with comma and you can spare the parentheses. – manatwork – 2015-05-08T13:43:58.583

1

PowerShell, 69 Bytes

$d=date 0;(0..47|%{"'{0:HH:mm}'"-f$d;$d=$d.AddMinutes(30)})-join",`n"

I love how it's shorter to use actual date functions than simply try to brute force the numbers with .ToString operators to pad zeroes and logic to decide if we're in a 00 or a 30 output.

Sets a new date $d to be 00:00:00 Jan 1 0000, then goes into a loop 48 times with 0..47|%{..}. Each time in the loop we generate our output using the -f operator. The HH:mm format for dates gives us 24-hour time with minutes, just as we want. Then, we addMinutes(30) to prep us for the next go-round. Outside the loop, we -join everything together with a comma and a newline.

AdmBorkBork

Posted 2015-05-07T08:11:46.953

Reputation: 41 581

1

TreeHugger, 1433 Bytes

TreeHugger is a bf variant that uses a binary tree instead of a linear tape. Read about it here and you can run scripts on the implementation here. As for how this program works, here is a rough run down:

  • Store the characters needed
    • In the first loop, get within 5 of the desired value
    • Manually adjust to the correct value
  • Walk through the tree and print the proper characters in the proper order
    • WARNING: This step is a little tedious
++++++++++[>++++++>+++++>+++++>++++>++++>+^^^^^<+++++>+++++^^^<++++>+++++>+++++^<+++++^^<+++++>+++++>++++++^<++++++^^<+++++>++++++^<+++++^^^^-]>-->+>-->->++++>^^^^^<+++>++^^^<->->+++^<++^^<-->+>---^<----^^<>-----^<++++^^^^<.<..^^>.>>.[.>]^^^^^^^^<.<..^^>[.>]^^^^^^^^<.<.^>.^^>.>>.[.>]^^^^^^^^<.<.^>.^^>[.>]^^^^^^^^<.<.<.^^^>.>>.[.>]^^^^^^^^<.<.<.^^^>[.>]^^^^^^^^<.<.>.^^^>.>>.[.>]^^^^^^^^<.<.>.^^^>[.>]^^^^^^^^<.<.^><.^^^>.>>.[.>]^^^^^^^^<.<.^><.^^^>[.>]^^^^^^^^<.<.^>>.^^^>.>>.[.>]^^^^^^^^<.<.^>>.^^^>[.>]^^^^^^^^<.<.<<.^^^^>.>>.[.>]^^^^^^^^<.<.<<.^^^^>[.>]^^^^^^^^<.<.<>.^^^^>.>>.[.>]^^^^^^^^<.<.<>.^^^^>[.>]^^^^^^^^<.<.><.^^^^>.>>.[.>]^^^^^^^^<.<.><.^^^^>[.>]^^^^^^^^<.<.>>.^^^^>.>>.[.>]^^^^^^^^<.<.>>.^^^^>[.>]^^^^^^^^<.>.^<.^^>.>>.[.>]^^^^^^^^<.>.^<.^^>[.>]^^^^^^^^<.>..^^>.>>.[.>]^^^^^^^^<.>..^^>[.>]^^^^^^^^<.>.^<<.^^^>.>>.[.>]^^^^^^^^<.>.^<<.^^^>[.>]^^^^^^^^<.>.^<>.^^^>.>>.[.>]^^^^^^^^<.>.^<>.^^^>[.>]^^^^^^^^<.>.<.^^^>.>>.[.>]^^^^^^^^<.>.<.^^^>[.>]^^^^^^^^<.>.>.^^^>.>>.[.>]^^^^^^^^<.>.>.^^^>[.>]^^^^^^^^<.>.^<<<.^^^^>.>>.[.>]^^^^^^^^<.>.^<<<.^^^^>[.>]^^^^^^^^<.>.^<<>.^^^^>.>>.[.>]^^^^^^^^<.>.^<<>.^^^^>[.>]^^^^^^^^<.>.^<><.^^^^>.>>.[.>]^^^^^^^^<.>.^<><.^^^^>[.>]^^^^^^^^<.>.^<>>.^^^^>.>>.[.>]^^^^^^^^<.>.^<>>.^^^^>[.>]^^^^^^^^<.<<.^.^^>.>>.[.>]^^^^^^^^<.<<.^.^^>[.>]^^^^^^^^<.<<.^^>.^^>.>>.[.>]^^^^^^^^<.<<.^^>.^^>[.>]^^^^^^^^<.<<..^^^>.>>.[.>]^^^^^^^^<.<<..^^^>[.>]^^^^^^^^<.<<.^>.^^^>.>>.[.>]^^^^^^^^<.<<.^>.^^^>.>.>.>.

Un-Golfed

The three digit numbers are the ASCII values we're aiming for in the approximation and adjustment phases. The numbers in the print phase, indicate the hour that we are printing.

# Approximation
+++++ +++++ [
058 > +++++ +
051 > +++++
048 > +++++
039 > ++++
044 > ++++
010 > +
^^^^^ 
053 < +++++ 
052 > +++++
^^^
039 < ++++
049 > +++++
053 > +++++
^
052 < +++++
^^
048 < +++++
051 > +++++
057 > +++++ +
^
056 < +++++ + 
^^
050 < +++++ 
055 > +++++ +
^
054 < +++++
^^^^ -
]
# Adjustment
058 > --
051 > +
048 > --
039 > -
044 > ++++
010 >
^^^^^ 
053 < +++ 
052 > ++
^^^
039 < -
049 > -
053 > +++
^
052 < ++
^^
048 < --
051 > +
057 > ---
^
056 < ----
^^
050 < 
055 > -----
^
054 < ++++ 
^^^^
# Print
0
<.<..^^     >.>>.[.>] ^^^^^ ^^^
<.<..^^     >[.>] ^^^^^ ^^^
1
<.<.^>.^^   >.>>.[.>] ^^^^^ ^^^
<.<.^>.^^   >[.>] ^^^^^ ^^^
2
<.<.<.^^^   >.>>.[.>] ^^^^^ ^^^
<.<.<.^^^   >[.>] ^^^^^ ^^^
3
<.<.>.^^^   >.>>.[.>] ^^^^^ ^^^
<.<.>.^^^   >[.>] ^^^^^ ^^^
4
<.<.^><.^^^ >.>>.[.>] ^^^^^ ^^^
<.<.^><.^^^ >[.>] ^^^^^ ^^^
5
<.<.^>>.^^^ >.>>.[.>] ^^^^^ ^^^
<.<.^>>.^^^ >[.>] ^^^^^ ^^^
6
<.<.<<.^^^^ >.>>.[.>] ^^^^^ ^^^
<.<.<<.^^^^ >[.>] ^^^^^ ^^^
7
<.<.<>.^^^^ >.>>.[.>] ^^^^^ ^^^
<.<.<>.^^^^ >[.>] ^^^^^ ^^^
8
<.<.><.^^^^ >.>>.[.>] ^^^^^ ^^^
<.<.><.^^^^ >[.>] ^^^^^ ^^^
9
<.<.>>.^^^^ >.>>.[.>] ^^^^^ ^^^
<.<.>>.^^^^ >[.>] ^^^^^ ^^^
10
<.>.^<.^^   >.>>.[.>] ^^^^^ ^^^
<.>.^<.^^   >[.>] ^^^^^ ^^^
11
<.>..^^     >.>>.[.>] ^^^^^ ^^^
<.>..^^     >[.>] ^^^^^ ^^^
12
<.>.^<<.^^^ >.>>.[.>] ^^^^^ ^^^
<.>.^<<.^^^ >[.>] ^^^^^ ^^^
13
<.>.^<>.^^^ >.>>.[.>] ^^^^^ ^^^
<.>.^<>.^^^ >[.>] ^^^^^ ^^^
14
<.>.<.^^^   >.>>.[.>] ^^^^^ ^^^
<.>.<.^^^   >[.>] ^^^^^ ^^^
15
<.>.>.^^^   >.>>.[.>] ^^^^^ ^^^
<.>.>.^^^   >[.>] ^^^^^ ^^^
16
<.>.^<<<.^^^^ >.>>.[.>] ^^^^^ ^^^
<.>.^<<<.^^^^ >[.>] ^^^^^ ^^^
17
<.>.^<<>.^^^^ >.>>.[.>] ^^^^^ ^^^
<.>.^<<>.^^^^ >[.>] ^^^^^ ^^^
18
<.>.^<><.^^^^ >.>>.[.>] ^^^^^ ^^^
<.>.^<><.^^^^ >[.>] ^^^^^ ^^^
19
<.>.^<>>.^^^^ >.>>.[.>] ^^^^^ ^^^
<.>.^<>>.^^^^ >[.>] ^^^^^ ^^^
20
<.<<.^.^^      >.>>.[.>] ^^^^^ ^^^
<.<<.^.^^      >[.>] ^^^^^ ^^^
21
<.<<.^^>.^^  >.>>.[.>] ^^^^^ ^^^
<.<<.^^>.^^  >[.>] ^^^^^ ^^^
22
<.<<..^^^    >.>>.[.>] ^^^^^ ^^^
<.<<..^^^    >[.>] ^^^^^ ^^^
23
<.<<.^>.^^^    >.>>.[.>] ^^^^^ ^^^
<.<<.^>.^^^    >.>.>.>.

This can be golfed down more, I have a 1198 byte version that should work, but I think this implementation might have a bug. So stay tuned until I finish debugging my own implementation.

NonlinearFruit

Posted 2015-05-07T08:11:46.953

Reputation: 5 334

1

Java, 93 bytes

void t(){for(int i=0;i<24;)System.out.printf("'%02d:00',\n'%02d:30'%s",i,i,i++<23?",\n":"");}

Ungolfed

void t()
{
    for(int i = 0; i < 24; i++)
    {
        System.out.printf("'%02d:00',\n", i);
        System.out.printf(   "'%02d:30'", i);
        System.out.printf( i < 23 ?",\n":"");
    }
}

Khaled.K

Posted 2015-05-07T08:11:46.953

Reputation: 1 435

0

Java 7, 88 bytes

void c(){for(int i=0;i<48;)System.out.printf("'%02d:%s0'%s",i/2,i%2*3,i++<47?",\n":"");}

Shorter than the other three Java answers: 93 bytes & 94 bytes & 119 bytes

Explanation:

void c(){                  // Method
  for(int i=0;i<48;)       //  Loop from 0 to 48 (exclusive)
    System.out.printf(     //   Print with format:
      "'%02d:%s0'%s",      //    "'##:#0'X" (where `#` is a digit, and `X` is a String)
      i/2,                 //    (%02d) Current index divided by 2 and automatically floored
      i%2 * 3              //    (%s0) i%2 is either 0 or 1 (multiplied by 3 is either 0 or 3)
      i++<47 ? ",\n" : ""  //    (%s) A comma and new-line, unless it's the final line
                           //  End of loop
}                          // End of method

Try it here.

Kevin Cruijssen

Posted 2015-05-07T08:11:46.953

Reputation: 67 575

0

AHK, 96 bytes

t=20000101000000
Loop,48{
FormatTime,i,%t%,HH:mm
Send,'%i%',`n
EnvAdd,t,30,Minutes
}
Send,{BS 2}

AHK does not play nicely with time values so I have to store two variables: one to track the time in the format YYYYMMDDHH24MISS and another just to store the pretty text in the format HH:MI.

Engineer Toast

Posted 2015-05-07T08:11:46.953

Reputation: 5 769

0

JavaScript, 127 bytes

I'm not a very good golfer :s

var r='',i,m=":00',\n",q="'"
for(i=0;i<23;i++){
h=("0"+i).slice(-2)
r+=q+h+m+q+h+":30',\n"
}
r+=q+i+m+q+i+":30'"
console.log(r)

Java, 179 bytes

public class M{public static void main(String[] a){String r="",f="'%02d:%s',\n";for(int i=0;i<24;i++)r+=String.format(f+f,i,"00",i,"30");System.out.print(r.replaceAll(".$",""));}}

ungolfed

public class M {
    public static void main(final String[] a) {
        String r = "", f = "'%02d:%s',\n";
        for (int i = 0; i < 24; i++)r += String.format(f + f, i, "00", i, "30");
        System.out.print(r.replaceAll(".$", ""));
    }
}

dwana

Posted 2015-05-07T08:11:46.953

Reputation: 531

don't be that modest! :) – Espen Schulstad – 2015-05-07T11:20:06.530

I'm not super good with javascript but I made a couple of improvements to bring it down to 104 bytes :) I removed some whitespace and moved the 23:** hour into the loop. This means you don't need the r+=q+i+m+q+i+":30'" line, but there is an extra comma, so you have to cut it off when you print it. That lets you save a lot of bytes, both from the removed line and variable initialization. You also might want to look into making this a 0-arg function, so you can use ES6 function syntax. There's a bit of boilerplate code you have to add, but usually returning > printing.

– undergroundmonorail – 2015-05-07T13:13:23.940

0

C++ - 104 bytes

I spend a while trying to find an obtuse way to remove the comma, but in the end the simple approach seemed to be by far the most efficient.

#include<cstdio>
int main(int c,char**v){for(c=-1;c++<47;printf("'%.2d:%d0'%s\n",c/2,c%2*3,c>46?"":","));}

I shouldn't need to initialize c to -1 but I couldn't get an inline postfix increment to work how I expected.

BMac

Posted 2015-05-07T08:11:46.953

Reputation: 2 118

You can reduce one byte by #include<cstdio>. Also, one byte can go from the c=-1 by changing it to c=0 and moving the increment inside the printf like for(c=0;48>c;printf("'%.2d:%d0'%s\n",c/2,c%2*3,c++>46?"":","));. Note that with this, the actual output may depend on the compiler, the processor, etc, because of the unsequenced modification of c, and the compiler will give a warning accordingly. – rorlork – 2015-05-08T08:36:54.237

@rcrmn Thanks! Unfortunately, that for loop is what I had initially, but it doesn't behave as I would expect on MSVC++. Your code gives me 00:30 to 24:00, which indicates right-to-left argument evaluation, but if I move the ++ into c/2 I get the 00s and 30s swapped, which would indicate left-to-right evaluation. My guess is the compiler is attempting to optimize by doing c++/2 first and using the result to calculate c%2. – BMac – 2015-05-08T16:25:02.280

Oh I see. Using Apple LLVM version 6.0 (clang-600.0.57) here. I thought I was using gnu g++, but it seems apple likes to hide these things to the user. – rorlork – 2015-05-08T16:27:56.763

0

JavaScript (ES6), 81 77 bytes

Template strings work well for cutting down the size.

alert([...Array(48)].map((x,i)=>`'${i<20?0:''}${i/2|0}:${i%2*3}0'`).join`,
`)

Mwr247

Posted 2015-05-07T08:11:46.953

Reputation: 3 494

Usually we call such code ECMAScript to emphasize the presence of experimental features. By the way, your code generates no output. (In JavaScript Standards for IO meta discussion we concluded that JavaScript should also use explicit output methods when output is requested.)

– manatwork – 2015-05-07T19:51:31.423

@manatwork Thanks for that link! I figured there would be something like that, but couldn't find anything, and having seen other examples elsewhere on the site without explicit prints, I just went with it. I'll update the answer. Good to know on the ECMAScript detail as well! =) – Mwr247 – 2015-05-07T20:01:15.400

I don't think this works: http://www.es6fiddle.net/i9essmvf/

– royhowie – 2015-05-07T23:21:42.207

@royhowie For some reason, es6fiddle requires variables be declared with var (add it before the i=0 and you'll see it works). While usually a good idea to have, it is not required. – Mwr247 – 2015-05-08T05:46:35.530

It certainly works as is in Firefox. And 1 more character can be spared thanks to the template strings: instead of \n in join()'s parameter, make that string also a template string and include a literal newline. – manatwork – 2015-05-08T07:37:24.337

0

PHP, 82 77 bytes

Nothing fancy, just abusing PHP's string capacities.

<?for($H=-1;$H++<23;)echo$H?",
'":"'",$H=str_pad($H,2,0,0),":00',
'$H:30'";

Probably there's something that I can cut off.

Old version, 82 bytes:

<?foreach(range(0,23)as$H)echo$H?",
'":"'",$H=str_pad($H,2,0,0),":00',
'$H:30'";

Ismael Miguel

Posted 2015-05-07T08:11:46.953

Reputation: 6 797

0

C# - lots (but give away free with windows)

using System;
using System.Collections.Generic;
using System.Linq;
class P
{
    static void Main()
    {
        Console.Write(String.Join(",\n", Enumerable.Range(0, 48).Select(i => "'" + i / 2 + ":" + (i % 2) * 3 + "0'")));
    }
}

Ewan

Posted 2015-05-07T08:11:46.953

Reputation: 151

0

PostgreSQL: 97 characters

select string_agg(to_char(x*interval'30m','''hh24:mi'''),','||chr(10))from generate_series(0,47)x

PostgreSQL: 132 131 116 characters

Kept here to show PostgreSQL's cool way to generate timestamp series.

select string_agg(to_char(x,'''hh24:mi'''),','||chr(10))from generate_series('150511','150511 23:59',interval'.5h')x

manatwork

Posted 2015-05-07T08:11:46.953

Reputation: 17 865

0

Python, 145 bytes

import time as t;i=48;a=t.asctime;w=3600;s=t.sleep;s(24-int(a()[11:13])*w+w-60*int(a()[14:16]));
while i:print '\''+a()[11:16]+'\',';i-=1;s(w)

I guess the code is fairly readable (altough quite long). Once you run the program it waits until actual local time is 00:00h, then prints the time and waits for 30 min, time in which the program prints the hour again. It keeps repeating this process until 00:00h of the next day is reached. Therefore, with lots of patience and no incidents that force your computer to shutdown all the times get printed.

Ioannes

Posted 2015-05-07T08:11:46.953

Reputation: 595

0

Ceylon, 101 bytes

shared void run(){print(",\n".join{for(h in 0..23)for(m in[0,3])"'``"``h``".pad(2,'0')``:``m``0'"});}

Formatted:

shared void run() {
    // original:
    print(",\n".join {
            for (h in 0..23)
                for (m in [0, 3])
                    "'``"``h``".pad(2, '0')``:``m``0'"
        });
}

This uses an iterable comprehension with two for-clauses, and nested string templates. "``h``" is a shorter way of writing h.string (we can't pad an integer directly). ",\n".join(iterable) puts the commas and new-lines between the strings (this way we can avoid the , in the last line).

Unfortunately Ceylon has no printf functionality, which would certainly make things shorter (no .pad or .string necessary).

After finding that "straightforward" solution, I experimented with some variations, which unfortunately result in slightly longer shrinked solutions:

shared void run() {
    print(",\n".join(
            (0..23)
                *.string
                *.pad(2, '0')
                .map((x) => "'``x``:00',\n'``x``:30'")
        ));
}

(102 bytes)

shared void run() {
    print(",\n".join {
            for (h in 0..23)
                let (x = "``h``".pad(2, '0'))
                    "'``x``:00',\n'``x``:30'"
        });
}

(104 bytes)

shared void run() {
    print(",\n".join(
            (0..23)
                .map((i) => "``i``".pad(2, '0'))
                .map((x) => "'``x``:00',\n'``x``:30'")));
}

(111 bytes)

Paŭlo Ebermann

Posted 2015-05-07T08:11:46.953

Reputation: 1 010

0

Burlesque, 30 bytes

Burlesque is sadly rather weak when it comes to formatting because it doesn't have a printf (yet).

23rzm{2'0lp}":00 :30"wdcp)\[uN

Details see here.

mroman

Posted 2015-05-07T08:11:46.953

Reputation: 1 382

0

Pyth, 24 bytes

V24V2%"'%02d:%d0',",N*3H

Run code

V24                     for loop 0-23, N counter
  V2                    for loop 0-1, H counter
    %                   format string
      "'%02d:%d0',"     source string
      ,                 begin list tuple
        N               first element, hour
        *3H             second element, minutes

Every second iteration of the second for loop, H is 1, which toggles the minutes digit between 0 and 3.

Interpreted code generated by the debugger:

for N in num_to_range(24):
 for H in num_to_range(2):
  imp_print(mod("'%02d:%d0',",[N,times(3,H)]))

benstopics

Posted 2015-05-07T08:11:46.953

Reputation: 61

0

PHP, 104 96 bytes

for($h=$m=0;$h<24;){echo($h||$m?",\n":"")."'".($h<10?0:"")."$h:".($m*3)."0'";if($m)$h++;$m=!$m;}
exploded view
for ($h = $m = 0; $h < 24; ) {
  echo ($h || $m ? ",\n" : "") . "'" . // echoes ",\n" on all but the first loop
       ($h < 10 ? 0 : "") . "$h:" .    // leading 0 for 0:00 - 9:30
       ($m * 3) . "0'";                // :00 if $m=0, :30 if $m=1
  if ($m) $h++;                        // increments $h if :30
  $m = !$m;                            // swaps :00 <-> :30
}

ricdesi

Posted 2015-05-07T08:11:46.953

Reputation: 499