

Shortest program to print "Never gonna give you up..." - lini
http://codegolf.stackexchange.com/questions/6043/were-no-strangers-to-code-golf-you-know-the-rules-and-so-do-i

======
blauwbilgorgel
Joke answer

    
    
      $h = "549d9635795ef37857e0b3dc02e52e53";
      $v = 0;
      while( $v == 0 ){
        $n = "";
        for( $i=0; $i<1943; $i++ ){
          $n .= chr(rand(0, 127));
        }
        if( md5($n) == $h ){
          echo $n;
          $v = 42;
        }
      }
    

By the time we have our answer (or a collision), we forgot what the question
was.

~~~
btilly
It is only funny because it is true.

Change your loop to only loop while $v < 42, and then when the md5 matches,
set $v to be the number of copies of "gonna" in the text. ( * ) Print the
final string at the end.

If you had a good random generator then with very high probability this
program would be correct, although it is unable to run in any reasonable time.

* There are exactly 42 copies of "gonna" in that text. Did God speaking through Douglas Adams subtly rickroll all of us?

~~~
christiangenco
Could this not also theoretically colide with a string with the same hash and
_more_ than 42 occurrences of "gonna"? Better set the flag to `$v==42` just to
be safe.

~~~
btilly
The probability is overwhelmingly against there being another string of the
same length and even 10 copies of "gonna".

The odds of another one with under 2k bytes and exactly 42 copies of "gonna"
is a lot higher than having one with 43 copies of "gonna".

In a code golf competition, one character matters. Therefore the odds are that
you should use "<" not "==" here.

------
ColinWright
597 bytes of Python:

    
    
        : d="""ou@on@he@ell@ w@ay it
        : @ otUr@BVna @make4 @ve@'re@ing@t's been@ a@
        : (Ooh@o @ g@
        : YX@ t@ know@nd @
        : N2@ how I'm feelJ
        : @iL4 up@6)E)8giL, n2giL
        : (G@ yX@
        : I justSannaxT47Gotta Munderstand0@eLrP@
        : 
        : We'Lqn eachQ for sClVgzr UarHFchJ butzKxoCshyxCsRInsideSe bothqShaHBoJ V
        : WeqxUBameF9weKPplR@
        : 8g68let4 down8runFrX9a9desert48Mcry8sayBoodbye8tTF lieF9hurt4@WeK nCstrangersxCloLzqxU rulesF9sCdCI
        : A full commitment'sShat I'mxhinkJ ofzSXldn'tBetxhis fromFnyQBuy31A9if4Fsk me7DV'txT me4KxoCbli9tCsee00
        : E,B6)E,B556)1300
        : """
        : for s in 'XVUTSRQPMLKJHFECBzxq9876543210':
        :  a,b=d.split('@',1)
        :  d=b.replace(s,a)
        : print d
    

I could make it a little better, but could only spend 30 minutes or so.

 _Added in edit: a small tweak gets it to 594 bytes - not included here._

~~~
goatforce5
"not included here."

Didn't we learn anything from Fermat?

~~~
ColinWright
OK, 589 bytes:

    
    
        : d="""ellU wTay it
        : S otherRConna Qmake4 PveMndL aK'reJingHt's beenFo E gC
        : (OohB
        : Youz txKL q know9
        : N28 how I'm feelH
        : 7iM4 up66)B)8giM, n2giM
        : (G5 you4
        : I justTannaxU47Gotta PuLerstaL03eMrQ2
        : 
        : We'M9n eachR for sElongzr hearFKchH butzJxoEshyxEsSInsideTe both9ThaFCoH on
        : We9xheCameqweJQplS1
        : 8g68let4 down8runKrouLqdesert48Pcry8sayCoodbye8tUK lieqhurt40WeJ nEstrangersxEloMz9xhe rulesqsEdEI
        : A full commitment'sThat I'mxhinkH ofzTouldn'tCetxhis fromKnyRCuy31AL if4Ksk me7Don'txU me4JxoEbliLxEsee00
        : B,C6)B,C556)1300"""
        : for s in'UTSRQPMLKJHFECBzxq9876543210':a,b=d.split(s,1);d=b.replace(s,a)
        : print d

------
x1
The thing I find interesting is this simple task highlights a constant problem
with programming: clarification. Looking at the utf8 example, who wins, the
fewest bytes or the fewest characters? It's always those little details that
tend to cause the biggest issues.

------
Akram
I wonder how long the program would be if written in Malbolge.
<http://www.99-bottles-of-beer.net/language-malbolge-995.html>

------
ctdonath
I started writing a solution in Google Blockly, but alas it does not yet save
programs, and procedures have incomplete implementation.

------
ibotty
the sed one is great!

------
n-gauge
104 bytes:

<iframe src="<http://pastebin.com/raw.php?i=wwvdjvEj> width="100%"
height="100%" frameborder=no></iframe>

~~~
kapitalx
no external sources allowed :)

~~~
n-gauge
Doesn't say that in this thread! (prior to your reply)

