Rock Around the Clock

46

4

In as few Unicode characters as possible, print the following (144 characters):

1, 2, 3 o'clock, 4 o'clock rock,
5, 6, 7 o'clock, 8 o'clock rock,
9, 10, 11 o'clock, 12 o'clock rock,
We're gonna rock around the clock tonight.

You must not use any numbers in your code, except the digit 1.

rybo111

Posted 2014-07-17T11:40:21.070

Reputation: 4 071

1There are spaces at the end of first 3 lines, do those count? – aditsu quit because SE is EVIL – 2014-07-17T12:46:11.090

@aditsu: These are due to editing, as m.buettner forgot to remove them when editing back to a code block. I would amend this, but the edit is considered too minor. – Wrzlprmft – 2014-07-17T12:56:24.743

1I removed them now – aditsu quit because SE is EVIL – 2014-07-17T13:30:11.430

4Several answers use 11. Does the instruction mean you can only use the number 1 or the digit 1? – mfvonh – 2014-07-17T16:32:21.323

10@mfvonh I said you could use 1. I didn't specify how many times, so the fact that people have used 11 is a clever loophole, and I'm all for it. – rybo111 – 2014-07-17T17:17:06.213

what if character literals in my language of choice are 8-bit integers? – Sparr – 2014-08-18T02:17:53.767

@Sparr Post it anyway, but put a note for others – rybo111 – 2014-08-18T10:02:47.460

Answers

48

Javascript - 140 132

k=1,s=", ",t=" o'clock",x="";while(k<11)x+=k+++s+k+++s+k+++t+s+k+++t+" rock,\n";alert(x+"We're gonna rock around the clock tonight.")

The fact, that 11 is made out of two 1's let me pass the rules I guess.

Explanation

The k+++s is equal to (k++)+s, so it adds k first to x, then increments k and then it adds s to x. This process will be done three times before it adds the last sentence.

izlin

Posted 2014-07-17T11:40:21.070

Reputation: 1 497

I just can't stop singing out loud k+++s+k+++s+k+++t+s+k+++t (Dr. Seuss style). Guys around me at the open space think I lost it. – Jacob – 2015-04-26T09:09:21.293

Why do you {} ? It's not needed for the while, you have only 1 instruction. But as you have to use ";" you will win only 1 char. ^^ – Antoine Esteve – 2014-07-17T13:18:09.937

3What does k+++s do? Is it (k++) + s or k + (++s) or (k++) + (++s)? – seequ – 2014-07-17T15:04:18.297

Easy enough to test: Open the console: var k = 1; var s = 5; k+++s; k; will print the value of k as 2. – DLeh – 2014-07-17T15:14:14.240

31+1 for this nonsense: x+=k+++s+k+++s+k+++t+s+k+++t+u – Cruncher – 2014-07-17T16:48:38.520

131: for(s=", ",t=" o'clock",i=x='';++i<=11;x+=i+++s+i+++s+i+++t+s+i+t+" rock,\n");alert(x+"We're gonna rock around the clock tonight.") – edc65 – 2014-07-17T16:53:36.443

If you don't store " rock, \n" in a variable, you can reduce your code by 4 bytes – William Barbosa – 2014-07-17T16:53:37.543

@DLeh Would be if I had one. – seequ – 2014-07-17T17:48:25.983

this can help you reducing your character count: http://xem.github.io/obfuscatweet/

– xem – 2014-07-17T17:54:59.603

@TheRare would be easy if you had a console? F12 – DLeh – 2014-07-17T18:38:07.313

@DLeh Tried to find it there earlier, but only found the error log. Found it now though, seems like Chrome mixes error log and console. – seequ – 2014-07-17T19:02:23.310

Since everyone is saying you can put this in the console, I'll point out that you can remove "alert(" and the final ")" from your answer and just get the information output to the console itself. That would reduce this to 133 characters. – trlkly – 2014-07-17T23:54:29.867

Make that 124 using @edc65's modifications. Though I do notice a potential problem: in Firefox, at least, the output had quotation marks around it. But so does the compressed JS example which also forgoes using alert() – trlkly – 2014-07-18T00:04:47.290

2@trlkly usually golfing in JS you have to use an output statement and alert is shorter than console.log. Using the auto display of the last calculation in console is like cheating. – edc65 – 2014-07-18T05:03:15.977

At least on my PC your answer would be 132 if you substitute k=1,s=", ",t=" o'clock",x="";while(k<11) with for(k=1,s=", ",t=" o'clock",x="";k<11;). Otherwise it's 133. – core1024 – 2014-07-18T23:19:40.127

15Are you sure that's not Brainfuck? – Michael Hampton – 2014-07-20T15:58:38.407

37

C# - 186

Best golf language or best golf language?

class P{static void Main(){var s="";for(int i=1;i<11;)s+=i+++", "+i+++", "+i+++" o'clock, "+i+++" o'clock rock,\n";System.Console.Write(s+"We're gonna rock around the clock tonight.");}}

William Barbosa

Posted 2014-07-17T11:40:21.070

Reputation: 3 269

I wonder why it gained so many votes, too. People like non-golfing-friendly-language entries, maybe – William Barbosa – 2014-07-17T14:02:12.930

7He inspired me to do it in C++, so he gets a vote. Real Men(tm) don't use woosy interpreted languages for code golf! – Darren – 2014-07-17T14:56:10.823

you don't actually need the spaces in the i++ + bits – DLeh – 2014-07-17T15:23:44.930

I wrote it on dotnetfiddle and it didn't compile without the spaces. Thanks for pointing it. – William Barbosa – 2014-07-17T15:42:30.660

You can shave a couple more by doing WriteLine -> Write, and using a literal \n at the end of the string. – Alconja – 2014-07-18T09:54:35.493

By using a string you append to and thus only a single System.Console.Write you can bring it down to 186. – Joey – 2014-07-19T10:35:18.417

Save 2 chars by using c=System.Console; – Ray – 2014-07-19T11:01:23.160

Use LINQPad's Dump() method to save some chars writing to the screen (bring it down to 173): var s="";for(int i=1;i<11;)s+=i+++", "+i+++", "+i+++" o'clock, "+i+++" o'clock rock,\n";(s+"We're gonna rock around the clock tonight.").Dump();. – Abbas – 2014-07-22T14:30:04.107

27

Brainfuck (1574)

Not a serious submission, but follows the rules.

-[----->+<]>--.-----.------------.[-->+++<]>++.------.------------.++[-->+++<]>.[--->++<]>--.+++++[->+++<]>.[--->+<]>++.-[--->+<]>+.+++++++++.+++.------------.++++++++.+++[----->++<]>.------------.++[-->+++<]>+.-[--->++<]>--.+++++[->+++<]>.[--->+<]>++.-[--->+<]>+.+++++++++.+++.------------.++++++++.-[++>---<]>+.---[----->++<]>.---.------------.++++++++.+++[----->++<]>.>++++++++++.-[----->+<]>.---------.------------.-----[->++<]>.----------.------------.----[->++<]>-.+[-->+<]>++++.+++++[->+++<]>.[--->+<]>++.-[--->+<]>+.+++++++++.+++.------------.++++++++.+++[----->++<]>.------------.----[->++<]>.[-->+<]>++++.+++++[->+++<]>.[--->+<]>++.-[--->+<]>+.+++++++++.+++.------------.++++++++.-[++>---<]>+.---[----->++<]>.---.------------.++++++++.+++[----->++<]>.>++++++++++.+[->+++++<]>++.-------------.------------.[-->+++<]>+.-.----.------------.[-->+++<]>+..-[--->++<]>.+++++[->+++<]>.[--->+<]>++.-[--->+<]>+.+++++++++.+++.------------.++++++++.+++[----->++<]>.------------.[-->+++<]>+.+.--[--->++<]>.+++++[->+++<]>.[--->+<]>++.-[--->+<]>+.+++++++++.+++.------------.++++++++.-[++>---<]>+.---[----->++<]>.---.------------.++++++++.+++[----->++<]>.>++++++++++.[------>+<]>.++[->++++<]>+.---[->+++<]>+.-[->+++<]>.-------------.--[--->+<]>-.++[->+++<]>+.++++++++.-..-------------.-[->+++<]>.---[----->++<]>.---.------------.++++++++.-[++>---<]>+.[->+++<]>+.--[--->+<]>---.---.++++++.-------.----------.-[--->+<]>-.---[->++++<]>.------------.---.--[--->+<]>-.+[->+++<]>.+++++++++.+++.------------.++++++++.-[++>---<]>+.---[->++++<]>.-----.-.-----.--.+.++++++++++++.[++>---<]>.

Can be tested here.

BrunoJ

Posted 2014-07-17T11:40:21.070

Reputation: 659

12Brainfuck answers always deserve respect. – Pharap – 2014-07-19T11:37:41.410

1Perhaps we should give him the "longest answer" award? #RESPECT – Jamie – 2014-07-22T13:31:23.243

23

Ruby, 100

printf"%i, %i#{", %i o'clock"*r=-~1} rock,
"*-~r+"We're gonna rock around the clock tonight.",*1..$$

histocrat

Posted 2014-07-17T11:40:21.070

Reputation: 20 600

4You can save another few characters with s="%i, %i#{", %i o'clock"*-~1} rock,\n" (replace the \n with a literal linebreak). Great idea to use $$! – Ventero – 2014-07-17T19:04:37.583

3Expanding on my previous comment: If you assign r=-~1 inline, you can then use "..."*-~r instead of s+s+s, allowing you to drop the assignment to s. – Ventero – 2014-07-17T19:41:17.930

Very nice, will make those edits. – histocrat – 2014-07-17T19:44:44.163

18

Perl 123

$s="*, *, * o'(, * o'( ),";print"$s
$s
$s
We're gonna ) around the ( tonight."=~s![(*)]!(clock,rock)[1+1+1&ord$&]||++$i!reg

The regular expression matches (, ) and *. I used the fact that the ASCII code of ( is 40, of ) is 41 and * is 42.

The r flag of the regular expression enables "in place substitution" and the e flag enables code evaluation (similar to x.replace(/.../, function(m){...}) in JavaScript).

(clock,rock) is an array of two "bare words". $& is the current match of the regular expression and ord$& is it's ASCII value.

Masked by 3 or 1+1+1 the ASCII values are now 0, 1 and 2, so I can use them to retrieve the corresponding array element. As 2 is out of the array, the "short circuit" operator || evaluates ++$i. In the first match $i is undef so incrementing it I get 1, then 2 and so on...

In simple words. This replaces * with it's current occurrence, ( with "clock" and ) with "rock".

core1024

Posted 2014-07-17T11:40:21.070

Reputation: 1 811

1Does. Not. Compute. Explanation please? – seequ – 2014-07-17T17:29:04.190

1@TheRare Explanation added ;) – core1024 – 2014-07-17T18:09:07.873

6It's black magic. +1 – seequ – 2014-07-17T18:20:51.067

This is the kind of thing Perl was made for, unsurprising it does so well. – Pharap – 2014-07-19T11:35:47.280

16

Bash+coreutils, 120 ASCII, 92 Unicode

ASCII:

c=clock
f(){ echo $[++i], $[++i], $[++i] o\'$c, $[++i] o\'$c rock,;}
f
f
f
echo We\'re gonna rock around the $c tonight.

Unicode:

iconv -t unicode<<<挊挽潬正昻⤨⁻捥潨␠⭛椫ⱝ␠⭛椫ⱝ␠⭛椫⁝屯␧Ᵽ␠⭛椫⁝屯␧⁣潲正㬬㭽㭦㭦㭦捥潨圠履爧⁥潧湮⁡潲正愠潲湵⁤桴⁥挤琠湯杩瑨ਮ|sed 1d|bash

base64 encoded Unicode version (in case unicode renderings get messed up):

aWNvbnYgLXQgdW5pY29kZTw8POaMiuaMvea9rOato+aYiuKkqOKBu+aNpea9qOKQoOKtm+akq+Kx
neKQoOKtm+akq+KxneKQoOKtm+akq+KBneWxr+KQp+Kxo+KQoOKtm+akq+KBneWxr+KQp+KBo+a9
suato+OsrOCpveCppuCppuCppuaNpea9qOWcoOWxpeeIp+KBpea9p+a5ruKBoea9suato+aEoOa9
sua5teKBpOahtOKBpeaMpOeQoOa5r+adqeeRqOCornxzZWQgMWR8YmFzaAo=

Digital Trauma

Posted 2014-07-17T11:40:21.070

Reputation: 64 644

2120, as the semicolon after the function declaration's closing brace is not needed. – manatwork – 2014-07-17T16:44:45.183

@manatwork Oops good catch - I don't know how that one snuck in there. Thanks! – Digital Trauma – 2014-07-17T16:53:44.057

1I'm on Windows now, but what is the reason to use eval instead of pipeing to bash or sh? – core1024 – 2014-07-17T17:34:20.990

@core1024 No reason other than me forgetting the possibility ;-) Thanks for the tip! – Digital Trauma – 2014-07-17T17:38:24.703

why not use a variable for rock too, the same way you did for clock? – Shahbaz – 2014-07-18T09:25:47.240

@Shahbaz It's not worth it. 8 chars for two instances of the string literal rock vs. 11 chars for r=rock; + two references of $r – Digital Trauma – 2014-07-18T16:45:17.120

1Oops, didn't count the $rs! – Shahbaz – 2014-07-18T17:14:13.707

13

Brainfuck, 1299

Bleuuuurgh. That was terrible. I don't know why I did this, it seemed quite easy at the start. First and probably last Brainfuck script. Try it here.

With some help from an automated code generator, I was able to write a script which reused most of the characters instead of generating each one from scratch. It's only 275 characters shorter than the one automatically generated, posted here.

The output isn't newline-terminated.

I might put a bit of explanation in later on. Essentially, any long line which isn't something like >>>>>>> or <<<<<<< or >>.>>.>>.>>. generates a character or a series of them.

-[----->+<]>--.
>
++[------>+<]>+.------------.
[-]<<+.>
++[------>+<]>+.------------.
[-]<<+.>
++++[->++++++++<]>.
>
+[------->++<]>+.
>
+[------->+++<]>++.
>
--[----->+<]>---.
>
+[------->++<]>--.
>
+[------->++<]>+.
>
--[----->+<]>---.
>
+[----->+++<]>++++.
>
++[------>+<]>+.
>
++++[->++++++++<]>.
<<<<<<<<<<<<<<<<<<<<+.
>>.>>.>>.>>.>>.>>.>>.>>.>>>>.
>
+[--------->++<]>.
>
+[------->++<]>+.
>
--[----->+<]>---.
>
+[----->+++<]>++++.
<<<<<<<<<<.
<++++++++++.
<<<<<<<<<<
<<<<<<<
+.
>>>>>>>>>>
>>>>>>>>.
<<<<<<<<<<
<<<<<<
.<<+.
>>>>>>>>>>
>>>>>>>>.
<<<<<<<<<<
<<<<<<
.<<+.
>>.>>.>>.>>.>>.>>.>>.>>.>>.
<<<<<<<<<<
<<<<<<
.<<+.
>>.>>.>>.>>.>>.>>.>>.>>.>>>>.
>>.>>.>>.>>.
<<<<<<<<<<.
<.
<<<<<<<<<
<<<<<<<<
+.[-]<
++[------>+<]>+.
>>.
[-]<<[-]<
-[----->+<]>--.-.
[-]<
++[------>+<]>+.------------.
[-]<
-[----->+<]>--..
>
++++[->++++++++<]>.
>>.>>.>>.>>.>>.>>.>>.>>.>>.
>>>>>>>>>
-[----->+<]>--.+.
<<<<<<<<<
<<<<<<<<<
<<<<<<<<<
<.
>>.>>.>>.>>.>>.>>.>>.
>>>>.
>>.>>.>>.>>.
>>[-]
++[------>+<]>+.>++++++++++.
>
+[--->++<]>+.++[->++++<]>+.---[->+++<]>+.-[->+++<]>.-------------.--[--->+<]>-.++[->+++<]>+.++++++++.-..-------------.
<<<<<<<<<<
<<<<<<<<<.
>>.>>.>>.>>.
<<[-]<<[-]<<[-]<<.
>
--[----->+<]>-----.--[--->+<]>---.---.++++++.-------.----------.
[-]<<<.
>
--------[-->+++<]>.------------.---.
<<.
<<<<<<<<<<
<<.
>>.>>.>>.>>.
>>>>.
>>[-]
--------[-->+++<]>.-----.-.-----.--.+.++++++++++++.[++>---<]>.

user16402

Posted 2014-07-17T11:40:21.070

Reputation:

10

Lua - 217 164 154 151 149 143

Modified the old one to use a loop instead, saves a boat-load of characters. Thanks to TeunPronk for helping me shave off another 10 characters and to WilliamBarbosa for shaving off another 3 characters. 2 more characters can be saved by using the variable k. 6 more characters are saved by eliminating the variable r=" rock," since it is used once.

o=" o'clock"c=", "w=io.write k=1+1 for i=1,11,k+k do w(i,c,i+1,c,i+k,o,c,i+k+1,o," rock,\n")end w("We're gonna rock around the clock tonight.")

Ungolfed,

o=" o'clock"
c=", "
w=io.write
k=1+1
for i=1,11,k+k do 
   w(i,c,i+1,c,i+k,o,c,i+k+1,o," rock,\n")
end
w("We're gonna rock around the clock tonight.")

Kyle Kanos

Posted 2014-07-17T11:40:21.070

Reputation: 4 270

I wonder if it might be shorter if you use a loop instead of j and k. – Teun Pronk – 2014-07-17T14:20:09.353

@TeunPronk: haha, I was just changing that as your comment pinged me – Kyle Kanos – 2014-07-17T14:20:38.557

1You can bring it down to 157. You dont need the comma after every 3rd number. Put the space infront of O, remove O from R, place a space in R and replace R by O,R in your io.write :) – Teun Pronk – 2014-07-17T14:29:01.233

And also, remove variable N and just type "\n" at the end of your io.write, saves an another 3 characters. – Teun Pronk – 2014-07-17T14:31:13.373

1@TeunPronk: Updated. Thanks for your help! – Kyle Kanos – 2014-07-17T14:32:57.407

1You can store io.write in a variable (f=io.write) and reduce this even further – William Barbosa – 2014-07-17T15:48:31.097

@WilliamBarbosa: Thanks, updated! – Kyle Kanos – 2014-07-17T15:50:14.417

8

CJam - 90 ASCII / 54 Unicode

ASCII:

{{T):T}:F~", ":CFCF" o'clock":OCFO" rock,
"}Z*"We're gonna rock around the clock tonight."

Unicode:

"ξ漰㠬༳ᆧᶃ㸩씪咦⏚騤䖫퍃᰽薂ᴤਥ궋씻㱗㽫Ƶꐥ勋䎔䃱魠ꝯ朐酠礢璿狮꓈执낦덋觫ᥛ琚"GZ)#bBC*b:c~

Try them at http://cjam.aditsu.net/

aditsu quit because SE is EVIL

Posted 2014-07-17T11:40:21.070

Reputation: 22 326

Your unico... "This answer has been edited." Oh, nevermind. – seequ – 2014-07-17T12:57:15.670

8

Python (123)

print((1+1+1)*"%i, %i, %i o'clock, %i o'clock rock,\n"%tuple(range(1,11+1+1))+"We're gonna rock around the clock tonight.")

PYG (112)

P((1+1+1)*"%i, %i, %i o'clock, %i o'clock rock,\n"%T(R(1,11+1+1))+"We're gonna rock around the clock tonight.")

Ian D. Scott

Posted 2014-07-17T11:40:21.070

Reputation: 1 841

7

Brainfuck - 680

test it here: ideone.com/Wi9ftB

>>>++++[>+++++++++[>+++[<<<<+<+>>>>>-]<<<+<<<+<+>>>>>>-]<-]+<++++++++<+++<---------<++++++++
++++<----<++++++++++<+++[>>>+.>>>.<<<<.>>>>>>[>[<<<<<<--------.-.>>>.<<<<.>+..<.>>>.>-----.<
------------.+++++++++.+++.------------.++++++++.++++>+++++.<<<<.>.+.>>>>->>-]+<<+>-]+<[<<<<
+.>>>.<<<<.>+.<.>>>.>-----.<<.>---.+++.<.>----.++++>+++++.<<<<.>+.>>>>-]<<<<<.>>>.>-----.<<.
>---.+++.<.>----.<<<.>>>+++++++.---.<.>----.++++>+++++.<<<<<.<-]>[>>++++<<-]>>---.[-]<[>+<-]
>>++.>>-----.<+++.<.<.>++.>---.-..<------.<.>>++++.---.<++.>----.<<.>--.>+++++++.---.++++++.
-------.<+++.<.>>++++++.<++++.---.<.>--.>--------.+++.<.>----.<<.>>+++++++++.-----.-.-----.-
-.+.>[>+++<-]>-.<<<---[>>+<<--]>>--.

as i promised, here's a better version. my brain feels like.. ooh so that's where the name comes from.

explanation: (because it is unmaintainable and i don't want to forget how it works)

firstly you have to choose the best data layout for this challenge. i came up with

-4 outmost loop -3 newline char -2 space -1 numbers 1 lowercase #1 2 lowercase #2 3 comma, apostrophe, period 4 condition (outmost loop < 3) 5 inner loop 6 second inner loop

We have to belive this is optimal unless there will be too many shifts (which case you have to rearrange the layout)

After that I used a 4x9x3 loop to set the starting values for newline, number, the two lowercase letter and the comma. (all the smaller ascii codes got 4x9=36 and the two lowercase letter got 4x9x3=108, then I added and substracted some to get their real value)

When the preset is done, the code enters the outmost loop that cycles 3 times. I explain it by pseudocode.

for 3 to 1 where i = numbers
    print '++i, '
    while inner_loop != 0              # this is true after the first loop
        while second_inner_loop != 0   # and this is true after the second
            print '10, 11 o'clock, 12' # prints the difference
            condition = 0              # it prevents the printing below
        second_inner_loop += 1
    inner_loop += 1
    while condition != 0
        print '++i, ++i o'clock, ++i'
    print ' o'clock rock,\n'

When this section is done I just have to print the last line. But we have an uppercase W that must be produced without using too many characters. At this point we are here:

Address  Value  Pointer
     -4      0  <--
     -3     10
     -2     32
     -1     50
      1     99
      2    111
      3     44

so I put [-3] 4 times to [-1] and substract 3 to get 87 (W): >[>>++++<<-]>>---.
then erase it [-]
and move [-2] to this location [-1] so space will be close to the lowercase letters. <[>+<-]

After that it just prints the letters. lowercase #1 is for the lower part 97-107 and lowercase #2 is for the above region.

bebe

Posted 2014-07-17T11:40:21.070

Reputation: 3 916

2+1 for being 300 characters shorter than the other BF answers – durron597 – 2014-07-21T13:13:32.630

i was thinking about going even lower. conditions are awful to create without a decent tutorial (esolangs is down) but it can be shorter by ~200 chars more – bebe – 2014-07-21T13:26:04.780

6

JavaScript, 111 107 chars, without using any number.

Execute these snippets in your browser's JS console:

107 (inspired by http://xem.github.io/obfuscatweet/ plus the other JS answer):

eval(unescape(escape('').replace(/uD./g,'')))

111 (just packing all the string and removing the eval around):

unescape(escape('').replace(/uD./g,''))

xem

Posted 2014-07-17T11:40:21.070

Reputation: 5 523

4anyone else see a turtle in there...? wtf – Dunno – 2014-07-21T19:38:50.453

hehe, yeah, the "random" Unicode characters generated by obfuscatweet sometimes lead to emoji :) – xem – 2014-07-22T06:55:35.310

5

PHP - 125 129

Version 1 (129)

$i;while($i<11)echo++$i.", ".++$i.", ".++$i." o'clock, ".++$i." o'clock rock,\n";echo"We're gonna rock around the clock tonight";

Version 2 (125)

while($i++<11)echo"$i, ".++$i.", ".++$i." o'clock, ".++$i." o'clock rock,\n";echo"We're gonna rock around the clock tonight";

Clean version:

while($i++<11)
    echo "$i, ".++$i.", ".++$i." o'clock, ".++$i." o'clock rock,\n";
echo "We're gonna rock around the clock tonight";

Samuel

Posted 2014-07-17T11:40:21.070

Reputation: 150

5

C - 145 - try me

main(i){i<11?main(i-~1+1,printf("%d, %d, %d o'clock, %d o'clock rock,\n"
,i++,i,i-~1,i-~1+1)):puts("We're gonna rock around the clock tonight.");}

C - 172 - try me

#define l ,__LINE__+~1
#define f ;printf("%d, %d, %d o'clock, %d o'clock rock,\n"
main(){f l
l
l
l)f
l
l
l
l)f
l
l
l
l);puts("We're gonna rock around the clock tonight.");}

bebe

Posted 2014-07-17T11:40:21.070

Reputation: 3 916

1I'm not much of a C programmer, so forgive me if I am being naive, but don't you need #include <stdio.h> to use printf? – Kyle Kanos – 2014-07-17T18:55:43.840

1default libraries are linked to the source in vc++ and gcc (so if you don't need something special, you can freely start a golfing challenge by typing main(){... – bebe – 2014-07-17T19:00:25.390

Ah, I see. That's strange that it spits out a warning if it's accepted by default (just checked with my gcc & icc, no vc++ to test). – Kyle Kanos – 2014-07-17T19:05:55.867

it also spits sequence point warning so...-w :) – bebe – 2014-07-17T19:13:14.563

@Kyle include files defines how external functions work (return type and parameters). Nothing to do with linking libraries. A standard C compiler will passs whatever parameters you like to any function (with warnings) and return values are often ignored, so it works anyway. – edc65 – 2014-07-17T20:21:28.853

@KyleKanos FYI http://codegolf.stackexchange.com/a/2204/11259

– Digital Trauma – 2014-07-17T23:53:21.990

I love the way you didn't need any #define macros to make this work. – Darren – 2014-07-18T03:26:18.090

Doesn't the first one rely on function argument evaluation order and could in fact output totally different numbers? (ETA: Just tested and I get »1, 1, 3 o'clock, 4 o'clock rock,« – and that was even without optimisations) – Joey – 2014-07-19T11:02:13.313

@bebe What version of VC++ does that? – Pharap – 2014-07-19T12:12:06.843

albeit i'm aware of the argument evaluation order, i checked it in the 2010 version and it worked fine. – bebe – 2014-07-19T14:02:08.567

Why the recursion and so much of obfuscation without code size reduction? condition+call to main is longer than a simple for loop... – V-X – 2014-10-30T09:06:15.833

5

Perl, 114 111 110 108

$s=", X o'clock";$_="X, X$s$s rock,
"x(1+1+1)."We're gonna rock around the clock tonight.";s/X/++$i/eg;print

110:

$s=", X o'clock";print(("X, X$s$s rock,
"x(1+1+1)."We're gonna rock around the clock tonight.")=~s/X/++$i/egr)

111:

print(("X, X, X o'clock, X o'clock rock,
"x(1+1+1)."We're gonna rock around the clock tonight.")=~s/X/++$i/egr)

114:

($s="X, X, X o'clock, X o'clock rock,
"x(1+1+1)."We're gonna rock around the clock tonight.")=~s/X/++$i/ge;print$s

Thaylon

Posted 2014-07-17T11:40:21.070

Reputation: 1 324

4

C++ 261 203

#include<iostream>
#define x i++;
#define y std::cout<<
#define z y x y
void m(){for(int i=1;i<11;){z", ";z", ";z" o'clock, ";z" o'clock rock, "<<"\n";}y"We're gonna rock around the clock tonight.";}

Edited my first attempt; it worked when I first tested it, but that seems to be a fluke; post-increment in a stream is "undefined behaviour", and it did weird things (including blue screening Windows 7!) when I tried re-running it. I think that using printf instead of std::cout could be used with post-increment to get a shorter program.

Edited again, got it down to 231 by re-implementing the loop. Edited yet again, now down to 203...those #defines weren't all useful in the looping version.

For those wondering how C++ can run a function "m", the entry point can be defined as any function with just a compiler option, as can setting all funcs to be stdcall; I used both switches when compiling the above. If you don't like the redefined entry point, add 3 to my character count.

Darren

Posted 2014-07-17T11:40:21.070

Reputation: 261

Which compiler are you using? gcc (4.7.1) doesn't allow me to call the main function m(). You can however drop the void and save 5 characters (or 2 if you name the method main) – Christoph Böhmwalder – 2014-07-17T17:18:36.730

how on earth did it get any upvotes? firstly you wrote a function called 'm' that will not compile by default, secondly every compiler shows the hours in reverse order. this needs a BIG correction – bebe – 2014-07-17T18:59:00.823

1@HackerCow I can't seem to make VS2013 work without the void return type defined; is there a compiler switch that would allow that? – Darren – 2014-07-17T23:57:09.620

1@bebe I explain the m() entry point in my edit; as for the output hours being printed in reverse order, I never managed to duplicate that, but I did manage to get it to print correctly (the first time I tried it), then on retesting all 1's, 5's and 12's, then on another retest it crashed the OS. So, technically it ran once, but relying on undefined behaviour is probably a 'bad idea', so I rewrote it :) – Darren – 2014-07-18T00:00:25.003

@Darren you shouldn't use entry point modification as it is quite a loophole like macro abusing.

– bebe – 2014-07-18T00:33:08.113

1@bebe I'm cool either way; in no way am I going to "win" any code golf puzzle with C++, so adding 3 characters is no biggie. I agree that -D switch macro definitions would be cheating, but pretty much any other compiler flags seem legit to me, as they also seemed legit to folks in the thread you linked. Any advantage you squeeze out of simple compiler switches won't exactly even the playing field between C++ and Python/Bash/Perl etc. – Darren – 2014-07-18T02:55:55.337

@bebe Don't complain about entry point modification when your submission relies on non-standard compiler features. – Pharap – 2014-07-19T12:15:18.270

4

Swift - 136 134

var x=1
for;x<11;{print("\(x++), \(x++), \(x++) o'clock, \(x++) o'clock rock,\n")}
print("We're gonna rock around the clock tonight.")

KFuzz

Posted 2014-07-17T11:40:21.070

Reputation: 51

3

Befunge-98 (402 268)

Now a unefunge!

".thginot kcolc eht dnuora kcor annog er'eW"a11+/a*1-> #;:,1+" ,",,:,1+" ,",,:,1+" ,kcolc'o "a1-k,:,1+a",kcor kcolc'o "ek,:a11+/a*b1111+++-+-#;_:,a-1+" ,",,:a111++-:*,,1+" ,",,:a111++-:*,,1+" ,kcolc'o "a1-k,:a111++-:*,,1+a",kcor kcolc'o "ek,:a11+/a*b1111+++-+$$$aa*k,@

waylon531

Posted 2014-07-17T11:40:21.070

Reputation: 411

1Random bits of backward text, ,,:,1+, a11+/a*b1111+++-+w:,, stray characters underneath the main line of code... typical Befunge. Most of the online interpreters are having problems with the line length (it's way over the limit), do you know of one that doesn't mind? – None – 2014-07-17T18:24:24.233

I couldn't find any Befunge-98 compilers online, but you could use pyfunge which is available in PyPI. – waylon531 – 2014-07-17T19:51:46.873

3

Java, 228

A hardcoded solution would have probably been shorter.

public static void main(String[] a){
        String s = "";
        int i=1,j=1;
        for(i--,j--;i<=11;){
            s += ++i + (j > 1 ? " o'clock rock, ":", ");
            if(j == "one".length()){
                j -= j;
                s +="\n";
            }else
                j++;
        }
        System.out.println(s+"We're gonna rock around the clock tonight");
}

Undeserved

Posted 2014-07-17T11:40:21.070

Reputation: 159

3+1 for the realization that hard-coding would be shorter. – Kyle Kanos – 2014-07-18T13:52:26.223

1+1+1 is 9 characters shorter than "two".length()". And is String[] a necessary? – Kyle Kanos – 2014-07-18T13:53:58.020

That kinda felt like cheating, and yes, String[] a is necessary. – Undeserved – 2014-07-18T14:07:26.097

It's not cheating, several people have used it :D – Kyle Kanos – 2014-07-18T14:09:55.653

3

Groovy - 140 139 chars

Golfed, influenced by William Barbosa's answer:

s="ock"
i=1
f={->println "${i++}, ${i++}, ${i++} o'cl$s, ${i++} o'cl$s r$s,"}
f();f();f()
println "We're gonna r$s around the cl$s tonight"

Ungolfed:

s = "ock"
i = 1
f = { ->
    println "${i++}, ${i++}, ${i++} o'cl$s, ${i++} o'cl$s r$s,"}
}

f();f();f()

println "We're gonna r$s around the clock tonight"

Michael Easter

Posted 2014-07-17T11:40:21.070

Reputation: 585

2

Mathematica - 153

i=1;
StringReplace[
  StringJoin[
    Riffle[{s="X, X, X o'clock, X o'clock rock,",s,s},"\n"]]<>
    "\nWe're gonna rock around the clock tonight.","X":>ToString[i++]]

mfvonh

Posted 2014-07-17T11:40:21.070

Reputation: 300

+1, I think this is the best strategy but it can be shorter.

– None – 2014-07-19T01:59:59.177

2

C++ 252

#define P(x) cout<<x
#define Q cout<<", "
#define N cout<<endl
#define C P(" o'clock")
#define R P(" rock")
#define F P(++i);Q;P(++i);Q;P(++i);C;Q;P(++i);C;R;N;
int i;
main()
{
    F F F
    P("We're gonna rock around the clock tonight.");
}

bacchusbeale

Posted 2014-07-17T11:40:21.070

Reputation: 1 235

1Unless my math sucks, using P(", ") in place of Q saves you 2 characters. – Kyle Kanos – 2014-07-17T19:46:11.500

2N and R only appear once: it would be better to inline them than to make a macro. – None – 2014-07-18T01:31:17.753

Using the above comments and more this can be condensed to 200 (even with the include and namespaces my compiler wants): #include<iostream> #define P std::cout<<++i<< #define C" o'clock" #define F P", ";P", ";P C<<", ";P C<<" rock"<<std::endl; int i;main(){F F F std::cout<<"We're gonna rock around the clock tonight.";} – Hagen von Eitzen – 2014-07-23T14:10:51.763

2

PowerShell, 123 118 109

1,1,1|%{"$('',''," o'clock"," o'clock rock"|%{"$((++$a))$_,"})"}
"We're gonna rock around the clock tonight."

After a horrible start (167) I got rid of a few idioms I didn't even need and at least got it shorter than the reference.

Joey

Posted 2014-07-17T11:40:21.070

Reputation: 12 260

2

Java (v2) - 250 241 232 chars

This is a complete running program, influenced by William Barbosa's answer.

Golfed:

public class R{
static int o=1;
static String c(){return o+++", "+o+++", "+o+++" o'clock, "+o+++" o'clock rock,\n";}
public static void main (String[] a){System.out.println(c()+c()+c()+"We're gonna rock around the clock tonight");}}

Ungolfed:

public class R {
    static int o = 1;
    static String c() { 
        return o+++", "+o+++", "+o+++" o'clock, "+o+++" o'clock rock,\n";
    }

    public static void main (String[] a) {
        System.out.println(c()+c()+c()+"We're gonna rock around the clock tonight");
    }
}

Michael Easter

Posted 2014-07-17T11:40:21.070

Reputation: 585

2

ECMAScript6 - 136 135

Doesn't even use the allowed 1 digit:

alert([,...a=[s=", ",s,(c=" o'clock")+s,c+" rock,\n"],...a,...a].map((x,i)=>i+x).join("")+"We're gonna rock around the clock tonight.")

Tested in Firefox console.

Alconja

Posted 2014-07-17T11:40:21.070

Reputation: 647

or 114 chars using http://xem.github.io/obfuscatweet/ ;)

– xem – 2014-07-18T16:21:35.580

4@xem, I know it fits in with the letter of the law, but I'm not a fan of Unicode compression (or any other compilers/generators). In my mind, golf is a test of skill and all code should be hand crafted... but that's just me. – Alconja – 2014-07-18T22:43:18.417

2

Haskell -- 138 137 chars

As a standalone program:

r n=show n++s!!n
s=" o'clock rock,\n":c:c:" o'clock, ":s
c=", "
main=putStr$(r=<<)[1..11+1]++"We're gonna rock around the clock tonight."

Edit: I used to have a helper function o used to define s by

s=o" rock,\n":c:c:o c:s;o=(" o'clock"++)

but it turns out to cost 1 extra character. Is there any way to compress all of the "o'clock"s / "rock"s / "ock"s?

Matt Noonan

Posted 2014-07-17T11:40:21.070

Reputation: 1 014

2

JavaScript, 140

a=", x o'clock",b="x, x"+a+a+" rock,\n",b+=b+=b+"We're gonna rock around the clock 
tonight.";for(i=1;i<=11+1;)b=b.replace("x",i++);alert(b)

I make a string like "x, x, x o'clock x o'clock rock,\n..." Then I replace the "x's" with numbers.

JeffSB

Posted 2014-07-17T11:40:21.070

Reputation: 357

1

PHP 258 220 only with Manatwork's help

EDIT: Thank you manatwork, again you did stuff there I didn't know you could do. Thanks!

<?php $a='clock';$b=" o'";$c="$b$a rock,";$d=1+1;$e=$d+$d;$f=", ";$g=$e+$e;echo"1$f$d$f",$d+1,"$b$a$f$e$c
",$e+1,$f,$e+$d,$f,$g-1,"$b$a$f$g$c
",$g+1,$f,$g+$d,$f,"11$b$a$f","1$d$c
We're gonna rock around the clock tonight.";

I must admit I thought this was going to be quite a dull question but it turned out to be quite fun. I thought I might have a chance with this one in php. Sadly not to be :-(

Edit: Actually it might not be PHP at fault, just that I need to learn more and do a bit practice at code golf - it is actually my own fault :-)

I enjoyed trying anyway.

Original 258 chars:

<?php $a='clock';$b=" o'";$c=$b.$a." rock,";$d=1+1;$e=$d+$d;$f=", ";$g=$e+$e;echo"1".$f.$d.$f.($d+1).$b.$a.$f.$e.$c."
".($e+1).$f.($e+$d).$f.($g-1).$b.$a.$f.($g).$c."
".($g+1).$f.($g+$d).$f."11".$b.$a.$f."1".$d.$c."
We're gonna rock around the clock tonight.";?>

Paul Drewett

Posted 2014-07-17T11:40:21.070

Reputation: 181

How you got 258? The entire text is 262, the bare minimal is 257 (no closing PHP tag and short opening PHP tag), just the code part is 254. – manatwork – 2014-07-17T17:15:45.283

1

Just a quick review. Changed some concatenations to string interpolations and others to separate parameters to reduce to 223 characters: http://pastebin.com/k0sxN8nw

– manatwork – 2014-07-17T17:29:02.820

1PHP isn't that bad ;) I got 129, trick is to really see what you want to use variables for – Samuel – 2014-07-17T18:42:43.390

1That is amazing. I love the use of WHILE for the first few lines. I didn't think of that. I also did not know you could miss out the braces in the case of a single statement and the php tags when quoting the program. Just checked on php.net and it is absolutely correct. I really must go and lookup some of the functions that I take for granted and see what else they can do. First it was FOR loops, now WHILE loops. I am going now to read about IF and see what I missed. Thanks for the great example. I shall do better next time. – Paul Drewett – 2014-07-18T08:19:47.633

@manatwork - thank you for that reworking, it was very interesting to see how you did that. As for the original count my openoffice text document says it is 258 characters. – Paul Drewett – 2014-07-18T15:52:45.480

1

PowerShell, 156 140 136 129 127

for($i=1;$i-lt11){$i++,$i++,"$(($i++)) o'clock","$(($i++)) o'clock rock,"-join', '}"We're gonna rock around the clock tonight."

Ungolfed:

for($i = 1; $i -lt 11){
    $i++, $i++ , "$(($i++)) o'clock", "$(($i++)) o'clock rock," -join ', '
}
"We're gonna rock around the clock tonight." 

DarkAjax

Posted 2014-07-17T11:40:21.070

Reputation: 669

You can get it down to 127 by using $i++,$i++,"$(($i++)) o'clock","$(($i++)) o'clock rock,"-join', ' within the loop. – Joey – 2014-07-17T21:07:17.177

@Јοеу Indeed, thanks for the advice! – DarkAjax – 2014-07-17T21:11:36.490

1

PHP 150

No numbers, including the 11 which would not be two 1's stuck together, but the number value eleven.

function f(){static $i;echo++$i.", ".++$i.", ".++$i." o'clock, ".++$i." o'clock rock,\n";}f();f();f();echo"We're gonna rock around the clock tonight";

user29540

Posted 2014-07-17T11:40:21.070

Reputation: 11

It's missing the trailing full-stop. – Joey – 2014-07-19T10:30:37.377

1

Cobra - 193

class P
    var i=1-1
    def main
        print[.f,.f,.f,"We're gonna rock around the clock tonight."].join("")
    def f as String
        return"[[.i+=1,.i+=1,.i+=1].join(", ")] o'clock, [.i+=1] o'clock rock,\n"

Οurous

Posted 2014-07-17T11:40:21.070

Reputation: 7 916

1

AWK, 164 139

Boring, but my first AWK golf attempt.

BEGIN{OFS=", "
k=" o'clock "
r="rock"
print ++t,++t,++t k,++t k r,"\n"++t,++t,++t k,++t k r,"\n"++t,++t,++t k,++t k r",\nWe're gonna "r" around the clock tonight."}

OFS comes in handy here.

Shorter version:

func p(){print ++t,++t,++t k,++t k r OFS}BEGIN{OFS=", "
k=" o'clock"
r=" rock"
p()
p()
p()
print"We're gonna"r" around the clock tonight."}

shadowtalker

Posted 2014-07-17T11:40:21.070

Reputation: 461

1

Haskell -- 155/141 147/133 chars

147 characters as a program:

main=putStrLn.(++"We're gonna rock around the clock tonight.").concat.zipWith((++).show)[1..11+1].cycle$[", ",", "," o'clock, "," o'clock rock,\n"]

133 characters as String expression:

(++"We're gonna rock around the clock tonight.").concat.zipWith((++).show)[1..11+1].cycle$[", ",", "," o'clock, "," o'clock rock,\n"]

Rhymoid

Posted 2014-07-17T11:40:21.070

Reputation: 181

1

MATLAB, 199 192 182

f=1+1+1+1;a=[1,1+1,f-1,f];b=' o''clock';c=' rock';
for i=1:f-1;fprintf('%g, %g, %g,%s, %g%s%s,\n',a(1:f-1),b,a(f),b,c);a=a+f;end
fprintf('We''re gonna%s around the clock tonight.',c)

Takatam

Posted 2014-07-17T11:40:21.070

Reputation: 11

Counting characters here (and using just a single space/tab for indentation) yields 198 characters, actually. Also I wonder whethe indentation is even necessary at all because the loop is bounded by for and end, which would save two characters. Then there is an unnecessary space between the comma and the \n in the string. – Joey – 2014-07-18T14:32:05.393

Another thing I wondered: Are semicolons needed after a line? If not, then you can save two of them as well (line 1 and 4). – Joey – 2014-07-18T14:34:39.923

Good observations, thanks! They aren't, but omitting a semicolon will print out the variables, which I think is not desired. – Takatam – 2014-07-18T14:38:00.063

You could use c=' rock', i.e. with a leading space to use a format string in the last string as well, saving another character. You can then do the same trick with b as well, saving two more characters in total. – Joey – 2014-07-18T15:27:30.167

1

Scala, 156

for(i<-1 to 11 by 1+1+1+1){println(i+", "+(i+1)+", "+(i+1+1)+" o'clock, "+(i+1+1+1)+" o'clock rock,")};println("We're gonna rock around the clock tonight.")

Leonardo Scattola

Posted 2014-07-17T11:40:21.070

Reputation: 19

1

Golflua -125

Basically a direct translation of my Lua solution:

k=1+1o=" o'clock"c=", "~@i=1,11,k+k I.w(i,c,i+1,c,i+k,o,c,i+k+1,o," rock,\n")$w("We're gonna rock around the clock tonight.")

Kyle Kanos

Posted 2014-07-17T11:40:21.070

Reputation: 4 270

1

Python 3, 100 99 Unicode

Using Unicode:

t=1+1;eval('瀠楲瑮㌨⠪┢Ⱪ┠≩㈫∪‬椥漠挧潬正⬢•潲正尬≮┩畴汰⡥慲杮⡥ⰱ㌱⤩∫敗爧⁥潧湮⁡潲正愠潲湵⁤桴⁥汣捯潴楮桧⹴⤢'.encode('utf%i'%(t*t<<t))[t:])

Encodes that string as UTF-16, dropping the first 2 bytes, resulting in:

 print(3*("%i, %i"+2*", %i o'clock"+" rock,\n")%tuple(range(1,13))+"We're gonna rock around the clock tonight.")

Note the initial space to make an even number of ASCII characters.

Checked if there were any illegal digits in there, such as from other languages, looks like I'm safe:

>>> set(c for c in """<code>""" if unicodedata.category(c)[0] == 'N')
{'1'}

Dan Getz

Posted 2014-07-17T11:40:21.070

Reputation: 533

1

ECMAScript: 127 characters

i=1;alert("%, %, % o'clock, % o'clock rock,\n".repeat(1+1+1).replace(/%/g,x=>i++)+"We're gonna rock around the clock tonight.")

Just to promote some ECMAScript 6 features.

manatwork

Posted 2014-07-17T11:40:21.070

Reputation: 17 865

1

Clojure - 261 244 178 176 chars

I'm a newbie to Clojure... suggestions welcome.

Golfed:

(let[i(atom(dec 1))](defn f[](swap! i inc))(defn p[](printf "%d, %d, %d o'clock, %d o'clock rock,\n"(f)(f)(f)(f)))(p)(p)(p)(print"We're gonna rock around the clock tonight."))

Ungolfed:

(let [i (atom (dec 1))]
  (defn f [] (swap! i inc) )
  (defn p [] (printf "%d, %d, %d o'clock, %d o'clock rock,\n" (f)(f)(f)(f)) )
  (p)(p)(p)
  (print "We're gonna rock around the clock tonight.")
)

Michael Easter

Posted 2014-07-17T11:40:21.070

Reputation: 585

1

Delphi, 186

Ungolfed:

var c:int32;

function i:int32;
begin
  c:=c+1;
  i:=c;
end;

begin
  while c<11 do
    writeln(i,', ',i,', ',i,' o''clock, ',i,' o''clock rock,');
  write('We''re gonna rock around the clock tonight.');
end.

Golfed:

var c:int32;function i:int32;begin c:=c+1;i:=c;end;begin while c<11do writeln(i,', ',i,', ',i,' o''clock, ',i,' o''clock rock,');write('We''re gonna rock around the clock tonight.')end.

Marko Paunovic

Posted 2014-07-17T11:40:21.070

Reputation: 131

1

Rebmu, 117 chars

O{ o'}C{clock}R{rock}S{, }T1 Ndz[igTad11 1[p[{We're going to}r{around the}c{tonight.}]qt]++T]fv[pCB[nSnSnOcSnOcSPrS]]

Un-"mushed":

o: " o'" c: "clock" r: "rock" s: ", " t: 1 n: dz [ig t ad 11 1 [p ["We're going to" r "around the" c "tonight."] qt] ++ t] fv [p cb [n s n s n o c s n o c sp r s]]

Commented:

; Define some string constants
o: { o'}
c: {clock}
r: {rock}
s: {, }

t: 1 ; assign one to T

; define a function with no arguments N (N does "DZ" the following)
n: dz [
    ; if T is greater than adding 11 to 1 (IG = If Greater, AD = Add), 
    ; print the final message and then quit 
    ig t ad 11 1 [
        p [{We're going to} r {around the} c {tonight.}] qt
    ]

    ; increment t but return its old value
    ++ t
]

; loop forever (will be exited by a quit during an invocation of N
; once it gets bigger than 12)
fv [
    ; print the result of combining (CB = Combine) the progressively
    ; increased values with the defined strings (also, SP = space)
    p cb [n s n s n o c s n o c sp r s]
]

COMBINE is being incubated in Rebmu, but hopefully on the roadmap for main Rebol/Red, see this article.

HostileFork says dont trust SE

Posted 2014-07-17T11:40:21.070

Reputation: 2 292

1

Scala, 142

Based on Leonardo Scattola's answer.

for(i<-1 to(11,1+1+1+1))println(f"$i, ${i+1}, ${i+1+1} o'clock, ${i+1+1+1} o'clock rock,");print("We're gonna rock around the clock tonight.")

randak

Posted 2014-07-17T11:40:21.070

Reputation: 141

1

><> (Fish), 133

(Uses only printable ascii.)

".thginot kcolc eht dnuora kcor annog er'eW"11.
v da-
>:?!\1-&a",kcor kcolc'o y ,kcolc'o y ,y ,y"&
/&+1/
>l?!v:bb*-?!\o
\  &;!+1n:&~/

Method:

  • Push the last line once and the first one 3 times onto the stack with the numbers changed to the letter "y".
  • Print everything from the stack if that's not an "y" while printing the value of an increasing counter if the character is an "y".

2 bytes saved thanks to @Sp3000.

randomra

Posted 2014-07-17T11:40:21.070

Reputation: 19 909

I don't know if b is allowed, but if it is then you might as well do da- instead of 11+1+ – Sp3000 – 2015-04-23T11:33:55.470

@Sp3000 I think it's allowed. Edited. – randomra – 2015-04-23T11:57:33.917

0

JavaScript - 138

with(console){for(b=1;11>b;)log("%d, %d, %d o'clock, %d o'clock rock,",b++,b++,b++,b++);log("We're gonna rock around the clock tonight.")}

Try it in the console (uses console.log).

Inspired by izlin's answer, I just shortened it using console.log instead of alert.

soktinpk

Posted 2014-07-17T11:40:21.070

Reputation: 4 080

Why those a.calls? l=console.log;for(b=1-1;11>b;)l("%d, %d, %d o'clock, %d o'clock rock,",++b,++b,++b,++b);l("We're gonna rock around the clock tonight.") – manatwork – 2014-07-18T14:16:18.057

@manatwork Illegal invocation error, console.log needs to run in the context of console – soktinpk – 2014-07-18T14:18:31.530

Interesting. It works for me in Firefox 30.0, Firebug 2.0.2 console. – manatwork – 2014-07-18T14:19:37.913

Why not use alert instead? – Jamie – 2014-07-22T13:29:52.803

1@Jamie because alert takes more space because you can't use "%d". – soktinpk – 2014-07-22T21:41:50.917

Nice. But I am counting 154 characters. a=(c=console).log;for(b=1-1;11>b;)a.call(c,"%d, %d, %d o'clock, %d o'clock rock,",++b,++b,++b,++b);a.call(c,"We're gonna rock around the clock tonight."); Maybe I'm doing it wrong. – JeffSB – 2014-07-24T19:11:08.933

0

Java - 219 215 212 208

I know there's some other Java answers, but this should be the shortest...

class A{public static void main(String[]z){String o="",c=" o' clock",r=c+" rock,\n",p=", ";for(int i=1;i<=11;)o+=i+++p+i+++p+i+++c+p+i+++r;System.out.println(o+"We're gonna rock around the clock tonight.");}}

Rich Smith

Posted 2014-07-17T11:40:21.070

Reputation: 411

Contains a 0 which isn't allowed. It's missing the comma after the first three lines. Also you can save a space in the arguments of main. And another one after the for. And yet another one after class A. Using System.out.print would save another two bytes. Did you golf this? – Joey – 2014-07-18T20:43:50.693

Not very well clearly :/ Fixed. Though removing the ln seems like cheating. – Rich Smith – 2014-07-18T21:25:09.233

The reference text is 144 characters. This does not include a trailing newline. So just using print is actually okay, I guess. – Joey – 2014-07-18T21:51:20.467

0

Python - 195 chars

b=", ";x=" o'clock";y=' rock,\n';c=1;s="";n=1+1+1
for i in range(n):
 for j in range(n):s+=str(c)+b;c+=1
 s=s[:-1-1]+x+b+str(c)+x+y;c+=1
print s+"We're gonna rock around the clock tonight."

Maltysen

Posted 2014-07-17T11:40:21.070

Reputation: 59

0

Javascript, 179 174

This is not gonna be the shortest one, but just for fun!

Golfed:

a="";for(i=1;i<=11+1;i++){a+=i.toString()+(!((i+1)%4)?" o'clock":"")+(!(i%4)?" o'clock rock":"")+", "+(!(i%4)?"\n":"");}alert(a+"We're gonna rock around the clock tonight.");

Ungolfed:

a="";
for(i=1;i<=11+1;i++){
    a+=i.toString()
        +(!((i+1)%4)?" o'clock":"")
        +(!(i%4)?" o'clock rock":"")
        +", "
        +(!(i%4)?"\n":"");
}
alert(a+"We're gonna rock around the clock tonight.");
a="";

Jamie

Posted 2014-07-17T11:40:21.070

Reputation: 166

0

F# - 173 136

Version 2 - 136

for x in[1..4..12]do printfn"%d, %d, %d o'clock, %d o'clock rock"x (x+1)(x+2)(x+3)
printfn"We're gonna rock around the clock tonight."

Version 1 - 173

System.Console.WriteLine("1, 2, 3 o'{0}, 4 o'{0} {1},\n5, 6, 7 o'{0}, 8 o'{0} {1},\n9, 10, 11 o'{0}, 12 o'{0} {1},\nWe're gonna {1} around the {0} tonight.","clock","rock")

Koopakiller

Posted 2014-07-17T11:40:21.070

Reputation: 129

0

Julia - 134

r="rock"
for i=1:4:12
    println("$i, $(i+1), $(i+2) $r $(i+3) o'clock $r")
end
println("We're gonna rock around the clock tonight.")

user11030

Posted 2014-07-17T11:40:21.070

Reputation:

The rules say 'you must not use any digits in your code, except for the digit 1.' – ASCIIThenANSI – 2015-04-23T14:42:21.747

0

Octave, 125 characters

d="%d, %d, %d o'clock, %d o'clock rock,\n";
printf([d d d "We're gonna rock around the clock tonight.\n"],v=1:(a=1+1)*a++*a);

I construct [1 .. 12] vector using only ones and assignment operator, and pass it as variable argument list to printf, taking advantage of fact that printf (fmt, a, a, a) and printf(fmt, [a a a]) are both correct ways of supplying variable argument list to function.

pawel.boczarski

Posted 2014-07-17T11:40:21.070

Reputation: 1 243