290
\$\begingroup\$

Write the shortest program that prints the entire lyrics of "Never Gonna Give You Up" by Rick Astley.

Rules:

  • Must output the lyrics exactly as they appear in the above pastebin*. Here's the raw dump: http://pastebin.com/raw/wwvdjvEj
  • Cannot rely on any external resources - all lyrics must be generated by / embedded in code.
  • No use of existing compression algorithms (e.g. gzip / bzip2) unless you include the full algorithm in your code.
  • Use any language, shortest code wins.

Update, 1st June 2012:
For solutions containing non-ASCII text, the size of your solution will be counted in bytes, based on UTF-8 encoding. If you use codepoints that cannot be encoded in UTF-8, your solution will not be judged as valid.

Update, 7th June 2012:
Thank you all for your awesome solutions! I'll be accepting the shortest answer tomorrow afternoon. Right now, Peter Taylor's GolfScript answer is winning, so get cracking on some improvements if you want to beat him! :)

*There is a typo in the Pastebin (line 46, "know" should be "known"). You may either replicate it or not at your discretion.

\$\endgroup\$
31
  • 4
    \$\begingroup\$ @w0lf You're correct. I only scanned the lyrics to verify their accuracy, I must've missed that one. I'll accept either "know" or "known". \$\endgroup\$
    – Polynomial
    May 29, 2012 at 7:30
  • 13
    \$\begingroup\$ 26k+ views in just 3 days. WOW... \$\endgroup\$
    – Gaffi
    Jun 1, 2012 at 21:30
  • 13
    \$\begingroup\$ How in the world did this generate so many views and votes? Whatever he did, I'm going to reverse engineer it. \$\endgroup\$
    – PhiNotPi
    Jun 2, 2012 at 21:27
  • 49
    \$\begingroup\$ @PhiNotPi Good luck reverse engineering "Jeff Atwood tweeting you". \$\endgroup\$
    – breadbox
    Jun 3, 2012 at 8:04
  • 11
    \$\begingroup\$ The restriction with UTF-8 makes no sense. What if my code is shorter when encoded as UTF-16 or as Latin-1? You should either count the number of bytes or the number of characters, but leave the encoding up to the author. \$\endgroup\$
    – Timwi
    Jan 25, 2014 at 0:22

73 Answers 73

5
\$\begingroup\$

05AB1E, 528 446 444 438 433 430 429 428 427 425 393 bytes

crossed out 444 is still regular 444 ;(

„†™º¢.ªð“†¿€î€¾
†³€î„‹
‡Ð…¡€ƒµ‰€î
‚§€îÀ¤
…è‚¿bye
ˆœ€…º¤€ƒ»å€î“«¶¡«»¶DJU'‹â™“We'veŠ¢‚Ì€¶€‡€ÊƒÈ
Your‰á's€Ý›šhing€³
You're…«½ºy€„…耕
ÿ€¦ƒìƒ€€À's€Ý…쀉
Weƒ€€€„…€ƒ€¦'reº¢†•€•
“V“
I‚‰Åˈœ€î€ß I'm¥ª
Gotta‚§€îíŒ

“©XÐrY¶'†™™“(Ooh)
ÿº¢†¿,†™º¢†¿
(Give€î€¾)
“D“(Ooh,†¿€î€¾)
“DXDYX®“We're€¸æÊs€„„Î
Youƒ€€€‰ï€ƒ€Ê€· I
A‚è©—'s€À I'm™Ð€‚
You€Þn't€Õ€Œ€š€Æ€¶ïíÿÿÿAnd€¬€îˆ¹€á€ß I'm¥ª
Don'tˆœ€á€î're…«³¶€„€È

“rJ

Try it online! Beats all other answers.

\$\endgroup\$
2
  • \$\begingroup\$ @Shaggy stop editing these lines away, thanks. \$\endgroup\$
    – Makonede
    Jun 12, 2023 at 16:27
  • 5
    \$\begingroup\$ No, they are unnecessary, irrelevant and, worst of all, obnoxious. \$\endgroup\$
    – Shaggy
    Jun 12, 2023 at 16:52
4
\$\begingroup\$

JavaScript, 1428 1451 883* characters

Definitely not the shortest solution, but here it goes.

d="(Give you up):(Ooh):(Ooh, give you up):A full commitment's what I'm thinking of:And if you ask me how I'm feeling:Don't tell me you're too blind to see:Gotta make you understand:I just wanna tell you how I'm feeling:Inside we both know what's been going on:Never gonna give you up:Never gonna give, never gonna give:Never gonna let you down:Never gonna make you cry:Never gonna run around and desert you:Never gonna say goodbye:Never gonna tell a lie and hurt you:We know the game and we're gonna play it:We're no strangers to love:We've know each other for so long:We've known each other for so long:You know the rules and so do I:You wouldn't get this from any other guy:Your heart's been aching but:You're too shy to say it:".split(/:/);"hk3l76o9bdcefojmn8g45o9bdcefo9bdcefo221a01a0oimn8go76o9bdcefo9bdcefo9bdcef".split("").map(function(i){return d[parseInt(i,25)]}).join("\n")

Solution logic is pretty simple:

d="dictionary:of:uniqe:lines".split("/:/");
"012345".split("").map(function(i){return d[parseInt(i,25)]}).join("\n")

*Of course the solution becomes a lot shorter when taking unique lines instead of unique words.

\$\endgroup\$
4
\$\begingroup\$

CoffeeScript, 1054 1047 bytes

Uses a Burrows-Wheeler transform and simple run-length encoding and prints out the lyrics to the console.

c=d='';n=1
for b in "w3tol6nnd6e6seemn6us4oeegglu6d6ou6wnm3rrsAeet,,a10nnr22eer18y6r3euud7y4IIe3uhhea12o3a8kl,,eg3hhyaaea12o5drroa6taaw3mtsyyde3u12tteeddswwufe6t6lle13t12I4e3u3t5nnee/6p4h4e4)3/utuedudu)uItg3/ytt/6))p6u6n6y6e6nn//efttgg/3((/4 5/40(4//|/8n16 6n6ttn22ee  m8gg 15ttrww 7ee h3s6llss 9d6a4 7n25o6iinn 6l 7i6mmwwhhrrmvWWvrhr3ddk8v10mwwW3v4ey6v  hhsf3b4e3t9e4mhhv40hgdds6ld6gl6N8nnN30io 7n10  n 64ttcco4w3t3  t3cctt 9s4l6 lhhkool3hh 4mgGgGg10  sa8n 7l10ppuu 12be9ue3 3o'4 8aa  tmoeeu6weedow6oon44u6a12Aaia4uu  i8ooaio42aa k7IIeados3t4oono6 O4ggrcD  llg42t3g6ffbb 3GGy15Yy12YyYYy11wr6YYylh3n7d6u10  e43uuoot'6fa6e3u5e6uaa 7c6e'4ir' 9e6  nna 3uurr a''esse6r14aani4uuttss 9oo 3o3  i 7so46rfr6o6 12ooh6jjbbgo''i14oe40o9 9o7 a10nhhur6b6 40u"
 x=b.charCodeAt 0
 if x<48||x>57
  d+=c for r in [1..n]
  c=b;n=1
 else if n==1
  n=b
 else
  n+=b
d+=c for r in [1..n]
t=[];l=d.length
for i in [1..l]
 t[j]=d[j]+(t[j] ? '') for j in [0...l]
 t.sort()
for i in [0...l]
 if t[i][l-1]=='|'
  console.log t[i][0..-2].replace /\//g,"\n"
\$\endgroup\$
4
\$\begingroup\$

///, 585 bytes

/?/ve//>/'re//=/ing //</ other //;/

We'?3//:/o //9/
(Ooh//8/t's been //7/
You//6/ t//5/ and //4/ gonna //3/ know//2/ how I'm feeling
//1/i?- up//-/ you//&/1)9)#gi?, ne?r4gi?
(G//%/
I just wanna6ell-2Gotta make- understand!//#/
Ne?r4//"/ each<for s:long7r hear8ach=but7>6o:shy6:say it
Inside we both3 wha8go=on
We36he game5we>4play it
//!/
#g1#let- down#run around5desert-#make- cry#say goodbye#tell a lie5hurt-/We> n:strangers6:lo?736he rules5s:d:I
A full commitment's what I'm6hink=of7 wouldn't get6his from any<guy%;n"And if- ask me2Don't6ell me->6o:blind6:see!!
9, g1)9, g&&1);"%!!

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Befunge-93, 1760 1476 1434 1329 1326 1323 bytes

>9#*9#5*#24#p9#0*#11#-+#<+00p57*1-10p"vv#"56+6*9p56+6*8p89*4+8p >
<v"tell a lie and hurt you"*25
<vp30"<say goodbye"*25  #
 vp40"<make you cry"*25
 vp50"<run around and desert you"*25
 vp60"<let you down"*25 #
 vp70"vgive you up"*25
^>" annog reveN"       #^   #1 #<
>"^ ":::03p04p05p06p07p10g:03g`#^_v$
v5"Gotta make you understand":*25$<
>2*"gnileef m'I woh uoy llet annaw tsuj I"25*:"ti yalp an#"65+6v^ <p01*48p<
v"what's been going on"*52"We know the game and we're gon"p*53*<
>" wonk htob ew edisnI"25*"ti yas ot yhs oot er'uoY"25*"tub gnih"v
 v*52"We've know each other for so long"*52"Your heart's been ac"<#
v>25*")pu uoy eviG("25*"evig annog reven ,evig annog reveN"25*")hoO("
<^p+780"v"
>52*")pu uoy evig ,hoO("52*")pu uoy evig ,hoO("25*">"57*2-:10p1+8p^>65+6*8^
v"e how I'm feeling"*25"Don't tell me you're too blind to see":*25<^">"*52<
>"m ksa uoy fi dnA"25*"ti yalp annog er'ew dna emag eht wonk eW"52v>"v'eW"^
v"too shy to say it"*25"Inside we both know what's been going on"*<^"e kn"<
>" er'uoY"25*"tub gnihca neeb s'traeh ruoY"25*"gnol os rof rehto hcae nwo"^
v52"I just wanna tell you how I'm feeling"*52"Gotta make you understand":*52<
>*"yug rehto yna morf siht teg t'ndluow uoY"25*"fo gnikniht m'I tahw s'tnemtim"v
v"We're no strangers to love"*52"You know the rules and so do I"*52"A full com"<
>:#,_@

Try it online!

Golfed 284 bytes by removing Whitespace that I used in my previous attempt

Golfed 42 bytes by moving a few pointers around.

Golfed 105 bytes by using the p Instruction more often.

Golfed 3 bytes by moving p01*48p< 3 lines up.

Golfed 3 bytes by using the full length on the last 2 lines

\$\endgroup\$
4
\$\begingroup\$

JavaScript REPL, 577 559 bytes

for(_=` w} a|th{erzndo ive're
(Ooh I'm telling  t youmake ay it

You know gonna  o{z | , g tot's been  {e 	evz up howfeeling

N))g, ng
(G
glet downrun|roudesztcrysay goodbye| liehurt
I just}anna Gotta uzsta

We'ven eachfor slongr hearachbutshysInside}e bo{}hagoon
We	gameweplWe nstrangzslove	rulessdI
A full commitment's}hat{inkof}ouldn't get {is from|nyguyA if|sk meDon't  meblisee
))`;G=/[^\n^ -y]/.exec(_);)with(_.split(G))_=join(shift())

Playing around with http://siorki.github.io/regPack.html settings

\$\endgroup\$
1
  • 6
    \$\begingroup\$ Welcome to Code Golf! \$\endgroup\$
    – Dennis
    Jun 16, 2019 at 1:58
4
\$\begingroup\$

HTML/CSS, 47 + 907 = 954 bytes

v:after{content:'Never gonna give you up\ANever gonna let you down\ANever gonna run around and desert you\ANever gonna make you cry\ANever gonna say goodbye\ANever gonna tell a lie and hurt you\A\A'}h:after{content:"We're no strangers to love\AYou know the rules and so do I\a A full commitment's what I'm thinking of\AYou wouldn't get this from any other guy"}k:after{content:"\AI just wanna tell you how I'm feeling\AGotta make you understand\A\A"}y:after{content:"We've known each other for so long\AYour heart's been aching but\AYou're too shy to say it\AInside we both know what's been going on\AWe know the game and we're gonna play it"}o:after{content:"\A And if you ask me how I'm feeling\A Don't tell me you're too blind to see\A\A"}l:after{content:"\A"}z:after{content:"(Ooh, give you up)\A(Ooh, give you up)\A(Ooh)\ANever gonna give, never gonna give\A(Give you up)\A(Ooh)\ANever gonna give, never gonna give\A(Give you up)\A\A"
<pre><v><v><v><k><l><y><z><v><v><o><y><v><k><h>

Quite compressible. Uses a bunch of nonexistent elements.

\$\endgroup\$
3
\$\begingroup\$

Delphi/Pascal. Some issues with casing though. WIP. 1018 characters, including unnecessary whitespace.

program X;
{$APPTYPE CONSOLE}
const
 w:array[32..114] of string = (#10,'(Give','(Ooh)','(Ooh,','A','aching','and','any','around','ask','been','blind','both','but','commitment''s','cry','desert','do','Don''t','down','each','feeling','for','from','full','game','get','give','give,','going','gonna','goodbye','Gotta','guy','heart''s','how','hurt','I','if','I''m','Inside','it','just','know','known','let','lie','long','love','make','me','Never','no','of','on','other','play','rules','run','say','see','shy','so','strangers','tell','the','thinking','this','to','too','understand','up','up)','wanna','we','We''re','We''ve','what','what''s','wouldn''t','You','Your','You''re');
 c='S>;pg S>Mp3 S>Z(&0p S>Qp/ S>[? S>`$N&Dp  ';
 x='kT_dP pKaY&^1E $8.mGbU po:c7''WA EJi`pCG5 @Qpf  '+c+'lL4W6^O qB*%- re]d[I Hj,Kn*=V jKa9&k>XI &Fp)RCG5 2`Rre+d\  '+c+c+  '#;ph #;ph " S><S>; !ph " S><S>; !ph  lK4W6^O qB*%- re]d[I Hj,Kn*=V jKa9&k>XI  EJi`pCG5 @Qpf  '+c+c+c;
var i: Integer;
begin
 for i := 1 to Length(x) do
  write(w[Ord(x[i])]+' ');
end.
\$\endgroup\$
3
\$\begingroup\$

Java - 903 Bytes

Here is my Java take at it, no compression algorithms used, just a dictionary.

In a single line:

class R {static String n(String w){return "Never gonna "+w+"\n";}public static void main(String[] args){String d[]={"(Ooh, give you up)\n","(Ooh)\n",n("give you up")+n("let you down")+n("run around and desert you")+n("make you cry")+n("say goodbye")+n("tell a lie and hurt you")+"\n","(Give you up)\n",n("give, never gonna give"),"We've known each other for so long\nYour heart's been aching but\nYou're too shy to say it\nInside we both know what's been going on\nWe know the game and we're gonna play it\n","\nI just wanna tell you how I'm feeling\nGotta make you understand\n\n","We're no strangers to love\nYou know the rules and so do I\nA full commitment's what I'm thinking of\nYou wouldn't get this from any other guy","And if you ask me how I'm feeling\nDon't tell me you're too blind to see\n\n","\n"};int n[]={7,6,2,5,8,2,2,0,0,1,4,3,1,4,3,9,5,6,2,2,2};for(int i:n){System.out.print(d[i]);}}}

And pretty printed for readability

class R {
    static String n(String w) {
        return "Never gonna " + w + "\n";
    }

    public static void main(String[] args) {
        String d[] = {"(Ooh, give you up)\n",
                "(Ooh)\n",
                n("give you up") +
                        n("let you down") +
                        n("run around and desert you") +
                        n("make you cry") +
                        n("say goodbye") +
                        n("tell a lie and hurt you") +
                        "\n",
                "(Give you up)\n",
                n("give, never gonna give"),
                "We've known each other for so long\nYour heart's been aching but\nYou're too shy to say it\nInside we both know what's been going on\nWe know the game and we're gonna play it\n",
                "\nI just wanna tell you how I'm feeling\nGotta make you understand\n\n",
                "We're no strangers to love\nYou know the rules and so do I\nA full commitment's what I'm thinking of\nYou wouldn't get this from any other guy",
                "And if you ask me how I'm feeling\nDon't tell me you're too blind to see\n\n",
                "\n"
        };
        int n[] = {7, 6, 2, 5, 8, 2, 2, 0, 0, 1, 4, 3, 1, 4, 3, 9, 5, 6, 2, 2, 2};
        for (int i : n) {
            System.out.print(d[i]);
        }
    }
}
\$\endgroup\$
3
\$\begingroup\$

Just for fun, here is the start of sub routine for an excel macro that will spit out a text file after building the song into a spreadsheet and then deleting the spreadsheet. Just thought it would be fun. I figure I can reduce the code later. Just make sure you are using 2007 or above and save the initial spreadsheet as an .xlsm

Sub R()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "R"
With Sheets("R")
.Cells(1, 1) = "We're no strangers to love"
.Cells(2, 1) = "You know the rules and so do I"
.Cells(3, 1) = "A full commitment's what I'm thinking of"
.Cells(4, 1) = "you wouldn't get this from any other guy"
.Cells(5, 1) = "I just wanna tell you how I'm feeling"
.Cells(6, 1) = "Gotta make you understand"
g = "Never gonna"
.Cells(8, 1) = g & " give you up"
.Cells(9, 1) = g & " let you down"
.Cells(10, 1) = g & " run around and desert you"
.Cells(11, 1) = g & " make you cry"
.Cells(12, 1) = g & " say goodbye"
.Cells(13, 1) = g & " tell a lie and hurt you"
.Cells(23, 1).Resize(7, 1) = .Cells(8, 1).Resize(7, 1).Value
.Cells(30, 1).Resize(7, 1) = .Cells(8, 1).Resize(7, 1).Value
.Cells(55, 1).Resize(7, 1) = .Cells(8, 1).Resize(7, 1).Value
.Cells(62, 1).Resize(7, 1) = .Cells(8, 1).Resize(7, 1).Value
.Cells(69, 1).Resize(7, 1) = .Cells(8, 1).Resize(7, 1).Value
.Cells(15, 1) = "We've known each other for so long"
.Cells(16, 1) = "Your heart's been aching but"
.Cells(17, 1) = "you're too shy to say it"
.Cells(18, 1) = "Inside we both know what's been going on"
.Cells(19, 1) = "We know the game and we're gonna play it"
.Cells(20, 1) = "And if you ask me how I'm feeling"
.Cells(21, 1) = "Don't tell me you're too blind to see"
.Cells(37, 1) = "(Ooh, give you up)"
.Cells(38, 1) = .Cells(37, 1)
.Cells(39, 1) = "(Ooh)"
 x = "Never gonna give"
.Cells(40, 1) = x & "," & x
.Cells(41, 1) = "(Give you up)"
.Cells(42, 1) = "(Ooh)"
.Cells(43, 1).Resize(2, 1) = Cells(40, 1).Resize(2, 1).Value
.Cells(46, 1).Resize(5, 1) = Cells(15, 1).Resize(5, 1).Value
.Cells(52, 1).Resize(2, 1) = Cells(5, 1).Resize(2, 1).Value
End With
sf = Left(ThisWorkbook.Name, InStr(ThisWorkbook.Name, ".xlsm") - 1) & Format(Now(), "_YYYY_MM_DD") & Format(Now(), "_HH_MM_SS") & ".txt"
iu = FreeFile
Open ThisWorkbook.Path & "\" & sf For Output As #iu
    With Sheets("R")
    For rr = 1 To 75
        Print #iu, .Cells(rr, 1).Text
    Next
    End With
    Close iu
sp= ThisWorkbook.Path & "\" & sf
ro = Shell("notepad.exe " & sp, vbNormalFocus)
    Sheets("R").Select
    ActiveWindow.SelectedSheets.Delete
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
\$\endgroup\$
3
\$\begingroup\$

Ruby (549) binary chars

I recently found that you can enter arbitrary binary characters (including those with value between 128 and 255) in ruby strings, as long as you follow some simple ruby escaping rules. Packing information into binary enables more efficient compression. Unfortunately, display of the "code", when written in binary, is problematic; thus, I created a generic program that reads in an existing ruby text program (assumed to not use chars with value > 127), and creates a secondary ruby source code that does exactly the same thing. This secondary code uses one long string with binary characters in it, and can be shorter than the original, in terms of number of bytes.

Here is the source "code-packer.rb"; it transforms input ruby source code into equivalent "compressed" output ruby source code. All it really does is binary packing of the original source code string, along with printing code for binary unpacking of the binary string.

Addendum: It appears that the original code-packer produces code that does not represent valid UTF-8 encoded binary strings, and thus is technically invalid according to the rules. To make it valid, we must use only character values up to 128. I recently read the UTF-8 encoding rules, and trying to use all 8 bits and generate UTF-encoded strings is not fruitful because most binary strings (over half of all possibly binary strings of any given length) will not represent valid UTF-8 encodings. So using straight up 7-bit ascii code is more efficient. I've modified the code-packer code below to produce only unreadable 7-bit ascii strings by replacing "256" with "128" and "<<8" with "<<7". This makes the packing compression idea not worthwhile for small programs (< 700 or so bytes), although it does still reduce Actven's 1000+ byte solution down to 937 bytes.

#!/usr/bin/env ruby
# This program takes a ruby file as input
# and outputs an equivalent ruby file as output that
# is functionally equivalent, but "compressed". 
# Compression is done by creating a string representing the original program
# which contains unprintable characters (including chars with value between 128 and 255)
# The string is just a binary packed version of the input program text.
# 
# the "decompression" algorithm for the string is written in ruby as part of the output, 
# along with an eval on the decompressed string. 
# NOTE: assumes input file doesn't contain any unprintable chars with value > 126, otherwise this will fail.

DEBUG=false # turn on debug to produce larger code that uses code sequences for the unprintable characters, 
         # and prints debugging information, and ruby code instead of executing it.
#DEBUG=true

# returns array of frequency counts for str
def frequency_count(str)
  freq= Array.new(127,0)
  str.bytes {|b| freq[b]+=1}
  freq
end

# figure out an appropriate contiguous
# range of characters (via ASCII) to use for representing str. 
# returns 
#  1) forward hash of chars, when applied to str, give only chars in the range
#  2) backward hash of chars for undoing #1
#  3) start character of range
#  4) length of range
def translate_range(str)
  freq = frequency_count(str)
  forward_hash = {}
  backward_hash = {}
  left_index = 0
  right_index = 126

  # ignore unused top range
  while right_index > 0 && freq[right_index] == 0
    right_index -= 1
  end

  if right_index == -1
    raise "Error: empty input string"
  end
  last_char_index = right_index

  # figure out chars to swap to get contiguous range
  # we want to minimize number of swaps, so this
  # naive approach won't always yield the best results.
  while left_index < right_index do
    if freq[left_index] == 0
       left_index += 1
       next
    end

    if freq[right_index] > 0
       right_index -= 1
       next
    end

    # found char on left that can move to empty spot on right
    forward_hash[left_index] = right_index
    backward_hash[right_index] = left_index
    freq[right_index] = 1 # mark it as filled.
    left_index +=1
    right_index -=1
  end 

  while freq[left_index]== 0
     left_index +=1
  end

  [forward_hash, backward_hash, left_index, last_char_index - left_index + 1]
end

# translates text into big num of given base, assuming all chars in string
# are in range start_char..(start_char+base-1)
def text_to_num (str, start_char, base)
   num = 0
   if (str[0] == start_char)
     raise "Sorry.. I can't handle strings that start with #{start_char.chr}"
   end  
   str.reverse.bytes {|x| num = num * base + (x - start_char)}
   num
end

# translates back from num to text. 
def num_to_text (num, start_char, base)
   text = ""
   while num > 0 do
      text += (num % base + start_char).chr
      num /= base
   end
  text
end

# translates from packed num string to original string, without translation part
# will be output into code.. present here for testing.
def packed_num_decode(str, start_char, base)
    m=0;str.bytes{|x|m=(m<<8)+x}
    t=""
    while m>0 ; t+=(m%base+start_char).chr;m/=base end
    t
end

# takes a string used for input into translate, and escapes
# chars with special meaning (^ at beginning, '-' between two chars, backslash)
def tr_escapes(str)
   str.sub("\\","\\\\\\\\").sub(/^\^/,"\\^").sub(/(.)-(.)/m, "\\1\\-\\2")
end

# takes a binary string, and escapes out characters problematic
# when writing the string within single quotes. 
# this includes ' and \.
def packed_string_escapes(str)
  chars_to_escape = "\\\'"
  escaped_str = ""
  str.bytes {|b| if chars_to_escape.include?(b.chr) 
    then
       escaped_str += "\\" + b.chr
    else
       escaped_str += b.chr
    end
  }
  escaped_str 
end

#======== Main program ========
if (ARGV.length != 2)
   puts "Usage: #{__FILE__} <input program> <output program>"
end
inputfile = ARGV[0] 
outputfile = ARGV[1]

inputtext = File.read(inputfile)
input_info = translate_range(inputtext)

from = ""
to = ""
input_info[0].each_pair {|x,y| from += x.chr ; to += y.chr }
input_mod = inputtext.tr(tr_escapes(from), tr_escapes(to))

input_num = text_to_num(input_mod, input_info[2], input_info[3])

packed_num = num_to_text(input_num,0,128).reverse # do reverse so decompression code doesn't have to do it.


if (DEBUG) then 
   pretext="input_mod=#{input_mod.inspect}\nfrom=#{from.inspect}\nto=#{to.inspect}\n"
   packed_num_with_quotes = packed_num.inspect
   operation = "puts \"t=\#\{t.inspect\}\";puts"
else
   pretext=""
   packed_num_with_quotes = "'" +  packed_string_escapes(packed_num) + "'"
   operation = "eval"
end

start_char = input_info[2]
base = input_info[3]
from = ""
to = ""
input_info[1].each_pair {|x,y| from += x.chr ; to += y.chr }

from_str = tr_escapes(from).inspect
to_str = tr_escapes(to).inspect

File.open(outputfile, "w+") {|f|f.puts("#{pretext}m=0;#{packed_num_with_quotes}.bytes{|x|m<<=7;m+=x};" +
              "t=\"\";while m>0;t+=(m%#{base}+#{start_char}).chr;m/=#{base} end;" +
              "#{operation} t.tr(#{from_str},#{to_str})")}

Although the above can be applied to any ruby code (and could be modified to work with other languages), I've applied it to the following short 556 char solution:

i=47
puts"W> n:trangMsL;loT96Ke rules8s;d;I
AJull commit7nt'sHhatVKink= of9HXldn'tRetKisJrom?nyERuy02A@ ifC?sk 75DS'tLU 7C>Lo;bli@L:ee11
O,R4)O,R334)2011|
I justHannaLUC5Gotta Bu@Msta@1|
Ng4NletC downNrun?rX@8desMtCNBcryNsayRoodbyeNtU? lie8hurtC|

W'T6n eachEJor s;lSg9r hear<?ch= but9>Lo:hyL:FInsideHe both6Hha<Ro= S
W6KeRa78we>QplF|4)O)NgiT, nPgiT
(G|iTC up| howVJeel=
| know|me|?@ |
YX|;s|o |t's been|ing|'re| a|nd|A|makeC | yX|D| othM|ay it
|G| w|I| f|Lh| t|er|
NP|
(Ooh|eTrQ|RSna | g|on|ve|ell| I'm|We|ou".split("|").inject{|m,o|m.gsub((i+=1).chr,o)}

The short 556 character solution above is essentially my previous solution, with substitution characters changed, so that the binary packing works better.

If you run the original code-packer program on the above short solution, it will generate a solution that is valid ruby source code that is 549 bytes long. Running this generated ruby source code will print out the required lyrics. Note that although the compressed string is over 100 bytes shorter than the original program, most of the savings is taken up by the decompression code.

If you run the current code-packer program on the above short solution, you get an expansion to 627 bytes. The packed string itself is about 50 bytes shorter, but adding the decompression code blows up the overall size.

Thanks to the commenters for pointing out the technicalities of UTF-8 encoding. To me, the "valid UTF-8" restriction seems rather arbitrary-- if you're going to allow unprintable ascii characters in valid code, why shouldn't you also allow "invalidly coded UTF-8 characters?" The original code-packer still does generate valid ruby source code that really takes up only 549 bytes of storage when run on the 556-byte solution presented above.

\$\endgroup\$
2
  • \$\begingroup\$ Is the packed code valid UTF8? \$\endgroup\$
    – a sad dude
    Jun 6, 2012 at 7:33
  • \$\begingroup\$ Check the problem description. Your byte values between 128 and 255 have to be measured as UTF-8-encoded -- in other words as taking up two bytes each. (This rule change is why I had to withdraw my solution.) \$\endgroup\$
    – breadbox
    Jun 6, 2012 at 12:22
3
\$\begingroup\$

Python 2.7, 845 bytes

Encodes words and then lines as ASCII characters.

w="\n|gonna|you|Never|and|give||tell|make|say|goodbye|a|desert|lie|up|hurt|down|let|run|cry|know|around|it|been|I'm|to|up)|the|so|I|other|how|feeling|too|(Ooh)|play|aching|heart's|You|Your|understand|but|what's|both|we're|long|We've|wanna|on|never|Inside|we|for|give,|each|shy|game|(Ooh,|Gotta|me|(Give|going|We|just|You're|what|A|no|if|any|this|And|known|commitment's|from|you're|love|blind|wouldn't|of|ask|do|full|strangers|see|guy|Don't|rules|get|thinking|We're|*".split("|")
o="!UVN7M:`S!&$4%3!cDZ<,9!&$+%6!jg%s^B;C!&$XT$(!y*^nDp<w!&$,-!@bR*%B;C!Q7YAW?P!I7>z'?t@!]+%K!euld;|r!&$(%1!E!_%=!Iq{imhAx!}fv<o!\(%=!&$*.0'2%!JH:GL!&$58'/%!QkYAW?P!a7>['O$F9!"
l="5.04,/#1%9'+7#:8&$;(*#1%9'+7#1%9'+7#662)32)3#-8&$;#,/#1%9'+7#1%9'+7#1%9'+7"
print "\n".join([[" ".join(["".join(w[ord(p)-35]) for p in k]) for k in o.split("!")][ord(m)-35] for m in l])
\$\endgroup\$
0
3
\$\begingroup\$

///, 692 682 666 656 bytes

666 bytes lol.

/1/ know //+/ you//>/You//=/Never gonna //!/I just wanna tell+ how I'm feeling
Gotta make+ understand
//@/=give+ up
=let+ down
=run around and desert+
=make+ cry
=say goodbye
=tell a lie and hurt+
//#/We've1each other for so long
>r heart's been aching but
>'re too shy to say it
Inside we both1what's been going on
We1the game and we're gonna play it//%/(Ooh, give+ up)//&/(Ooh)//*/=give, never gonna give//-/(Give+ up)/We're no strangers to love
>1the rules and so do I
A full commitment's what I'm thinking of
> wouldn't get this from any other guy
!
@
#
And if+ ask me how I'm feeling
Don't tell me+'re too blind to see

@
@
%
%
&
*
-
&
*
-

#

!
@
@
@

-10 bytes thanks to Flp.Tkc/Erik the Outgolfer

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Could you try replacing 'know'? (It's used 4 times, I think) \$\endgroup\$
    – FlipTack
    Dec 23, 2016 at 10:42
  • \$\begingroup\$ Actually, you should be replacing " know ", not "know". \$\endgroup\$ Dec 23, 2016 at 14:37
  • \$\begingroup\$ I think it would save 2 bytes to replace o . \$\endgroup\$
    – sporkl
    Mar 24, 2017 at 21:23
3
\$\begingroup\$

Brainfuck, 7497 bytes

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

Try it online!

This is still barely golfed, but a good bit better captncraig's solution. Maybe I'll get back to this later.

\$\endgroup\$
2
\$\begingroup\$

Dart. 802b

Live Online App (press play)

http://try.dartlang.org/s/9mJD

My approach

Uses no compression libraries.

  1. The starting string is the lyrics with all duplicate words removed, then split by ' ' into a list.
  2. I create 3 strings (4 in the super optimized version), each char is an ascii lookup in the list.
  3. The final string injects the first two at various points, using string interpolation.
  4. The final string is converted into char codes and used to perform the look ups in the word list.

Verbose Code

void main() {
  var x="We're no strangers to love You know the rules and so do I A full commitment's what I'm thinking of wouldn't get this from any other guy just wanna tell you how feeling Gotta make understand Never gonna give up let down run around desert cry say goodbye a lie hurt We've known each for long Your heart's been aching but You're too shy it Inside we both what's going on We game we're play And if ask me Don't you're blind see (Ooh, up) (Ooh) give, never (Give".split(' ');
  var c="DEF>G~DEH>I~DEJK)L>~DEB>M~DENO~DE=PQ)R>~~";
  var d="STU9V*W~XYZ[\\~]^_#N`~abc&dZef~g&'h)iEj`~";
  var a=' !"#\$~%&\'()*+,~-./0123~%456789:~,;<=>?1@~AB>C~~$c${d}kl>mn?1@~o=np^q#r~~$c${c}sF>t~sF>t~u~DEvDEF~x>t~u~DEvDEF~x>t~~$d~,;<=>?1@~AB>C~~$c$c$c';
  var o='';
  a.charCodes().forEach((i) => o += i == 126 ? '\n' : '${x[i-32]} ');
  print(o);
}

Minimized Version

https://gist.github.com/2854180

\$\endgroup\$
0
2
\$\begingroup\$

C#, 816 803 741 737 703 chars

This is the entire class needed to print the lyrics to the console:

class r{static void Main(){new u(@"]^(Ooh,>-)|£^I just wanna:3%&Gotta 2u+ersta+^*|$(Ooh)!gi<, ne<r_gi<^(G-)^|*!g-!let% down!run1rou+{desert%!2cry!say>oodbye!t31 lie{hurt%^|3ell|2make% |#^We'<4n each o/r for s;long[r hear~1ch? but[.:o;shy:;s=Inside we both}wha~>o? on^We}/>ame{we._pl=|!^Ne<r_|& how I'm feel?^|_>onna |=ay it^|[^You|^
|-i<% up|% you|{1+ |}4 |4 know|~t's been|: t|;o |<ve|> g|?ing|/the|.'re|+nd|1 a");}class u{public u(string c){var a="We. n;strangers:;love[}/ rules{s;d;I^A full commitment's what I'm:hink? of[ wouldn't>et:his from1ny o/r>uy£#A+ if%1sk me&Don't:3 me%.:o;bli+:;see^**]]^$$#£**";foreach(var b in c.Split('|'))a=a.Replace(b[0]+"",b.Substring(1));System.Console.Write(a);}}}

And a more readable version:

class r
{
    static void Main()
    {
        new u(@"]^(Ooh,>-)|£^I just wanna:3%&Gotta 2u+ersta+^*|$(Ooh)!gi<, ne<r_gi<^(G-)^|*!g-!let% down!run1rou+{desert%!2cry!say>oodbye!t31 lie{hurt%^|3ell|2make% |#^We'<4n each o/r for s;long[r hear~1ch? but[.:o;shy:;s=Inside we both}wha~>o? on^We}/>ame{we._pl=|!^Ne<r_|& how I'm feel?^|_>onna |=ay it^|[^You|^
|-i<% up|% you|{1+ |}4 |4 know|~t's been|: t|;o |<ve|> g|?ing|/the|.'re|+nd|1 a");
    }

    class u
    {
        public u(string c)
        {
            var a = "We. n;strangers:;love[}/ rules{s;d;I^A full commitment's what I'm:hink? of[ wouldn't>et:his from1ny o/r>uy£#A+ if%1sk me&Don't:3 me%.:o;bli+:;see^**]]^$$#£**";

            foreach (var b in c.Split('|'))
                a = a.Replace(b[0] + "", b.Substring(1));

            System.Console.Write(a);
        }
    }
}

No more optimisation - I had to write myself a quick n dirty zip engine to get it this small!

\$\endgroup\$
2
  • \$\begingroup\$ You can actually inline c to the foreach loop and just take out the class to optimize further. I would link it on TIO but the URL is too long. Gets you down to at least 665 chars/668 bytes. Why are you using £ by the way? \$\endgroup\$
    – Stackstuck
    Mar 7, 2019 at 14:38
  • \$\begingroup\$ I'll submit an edit. \$\endgroup\$
    – Stackstuck
    Mar 7, 2019 at 14:43
2
\$\begingroup\$

PHP - 568 570 567 bytes / 552 characters

first: thank you for the competition, it was a nice challange even if I wount win with this solutions in this stage.

based on the PHP-ideas obove but even very efficient I think:

<?=str_replace(range('-',_),split(q,"
2=5letFdown5run arUndCdese@5:cry5sayVoodbye5Da liAhu@q

[e'SJn each<for sQlongLr hear;achO but\9shyGK
]nside we boTBwha;goEn
[e8gamAweM>plKq
] just wRna?H1Yotta :understRdq3)2, n4
(Yq howIfeelO
q
Z4q6Pq7giSq
Z7qiS=)qeSr>qBTe qUMNQqmakeFqt's been q oTer qFupqVonna q Dqrt HqeCqJ q Rd qtell qO oq H qN sqyUq I'm q knowqay itq\Uq'req toqingq
(Oohqo qanqveqthqouq gq
AqDqGqNqWq
YqI"),"[eM nQstrRgersN loSL8rulesCsQdQ]W full commitment's whatITinkEfL wUldn'tVet Tis from Ry<guy/-.Wnd ifFask me1Xon't?me y9blindGee--
P,V3,V006.
/---");

any hints?

\$\endgroup\$
5
  • \$\begingroup\$ I'm getting a count of < 500 bytes from your entry. You probably have code formatting mistakes with "<" and ">" \$\endgroup\$
    – Ed H.
    Jun 7, 2012 at 9:25
  • \$\begingroup\$ just fixed the code and tested it again: now it should work :) \$\endgroup\$ Jun 8, 2012 at 7:48
  • \$\begingroup\$ Underscores don't need quotes. range('-',_) will work just fine. Also the trailing ?> is not necessary, instead just use a semi-colon. Unfortunately, that still leaves you at 567 bytes, counting necessary newlines. \$\endgroup\$
    – primo
    Jun 8, 2012 at 7:59
  • \$\begingroup\$ I'd really like to see a PHP submission win ;) You should be able to extend your range back to range('%',_) which should give you ~4 more usable keys to switch (, ' and one of () would likely need to be replaced with itself). \$\endgroup\$
    – primo
    Jun 8, 2012 at 13:26
  • \$\begingroup\$ thank you for the ideas primo, I've tried this out in an earlier version but I dont need the more keys (they cost more space than they are eliminating). At the moment I'm playing with another algorithm of replacement (the actual one does not include the efficency of an replacement). The replacement of the capitals is actually very "expensive" - if someone has here a good idea I'll try this out. \$\endgroup\$ Jun 8, 2012 at 21:07
2
\$\begingroup\$

HTML, 1875 bytes

This has to be done.

<pre>We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of
You wouldn't get this from any other guy
I just wanna tell you how I'm feeling
Gotta make you understand

Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

We've known each other for so long
Your heart's been aching but
You're too shy to say it
Inside we both know what's been going on
We know the game and we're gonna play it
And if you ask me how I'm feeling
Don't tell me you're too blind to see

Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

(Ooh, give you up)
(Ooh, give you up)
(Ooh)
Never gonna give, never gonna give
(Give you up)
(Ooh)
Never gonna give, never gonna give
(Give you up)

We've know each other for so long
Your heart's been aching but
You're too shy to say it
Inside we both know what's been going on
We know the game and we're gonna play it

I just wanna tell you how I'm feeling
Gotta make you understand

Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you

\$\endgroup\$
5
  • \$\begingroup\$ Do you really need the pre tag? \$\endgroup\$
    – Beta Decay
    Oct 2, 2016 at 9:17
  • \$\begingroup\$ @BetaDecay Yes, because without pre the linebreaks get ignored. \$\endgroup\$
    – SE is dead
    Oct 3, 2016 at 2:41
  • 4
    \$\begingroup\$ this is low quality :| \$\endgroup\$
    – user63187
    Feb 14, 2018 at 3:27
  • \$\begingroup\$ @Christopher The term you are looking for is "not a serious contender", but HTML isn't really a programming language, so this does appear to be a serious contender (!) \$\endgroup\$ Jun 18, 2020 at 19:57
  • \$\begingroup\$ @user8397947 love how you golfed away the closing </pre> \$\endgroup\$ Dec 17, 2020 at 7:30
2
\$\begingroup\$

JavaScript 616 bytes

_="cCsole.log(\"We'r:n6strJgKs46lo950P:ruleLQs6d6I*A fuFcommitment'LwhatRPink< of5 wMldn'tEetPiLfrom Jy=guy&>n$A2if?ask me1DC't4eFme-@bli2t6see!!*7,E/)7,E++/)>$&!!\");!*%g/%let?down%run arM2QdesKt-%Hcry%sayEoodbye%teFa li:Qhurt-$ each=for s6lCg5r hear8ach< but5@shy46sBInsid:w:both0 wha8go< C*We0P:gam:Qwe're3plB%*NS&*I just wJna4ell-1Gotta HundKstJd!*\\n+/)7)%gi9, nSgi9*(G?yM/i9?up0 know1 howR feel<*2nd 3ECna 4 t5*YM6o 7*(Ooh8t'Lbeen 9ve:e <ing= othK >**We'90?- @'re4o6Bay it*ConE gFll Hmake?JanKerLs MouP4hQa2R I'mSe9r3";for(Y in $="SRQPMLKJHFECB@?>=<:9876543210/-+*&%$!")with(_.split($[Y]))_=join(pop());eval(_)

@tkazec, I tip my hat off to you... I don't think I could have brought it any lower...

\$\endgroup\$
1
2
\$\begingroup\$

Windows batch, 975 911 892 bytes

If I removed the four-space-code-indention, the result will look witty.


Just some replacement work here. For example, I set Never gonna to a variable, and replace the other Never gonna with the variable.

@echo off
set y= you 
set e=echo(
set n=ever gonna 
set g=Gotta make%y%understand
set o=(Ooh
set u=ive%y%up
set i=I just wanna tell%y%how I'm feeling
set c=call:
%e%We're no strangers to love
%e%You know the rules and so do I
%e%A full commitment's what I'm thinking of
%e%You wouldn't get this from any other guy
%e%%i%
%e%%g%
%e%
%c%n
%c%w
%e%And if%y%ask me%i:~21%
%e%Don't tell me you're too blind to see
%e%
%c%n
%c%n
%e%%o%, g%u%)
%e%%o%, g%u%)
%e%%o%)
%e%N%n% give, n%n%give
%e%(G%u%)
%e%%o%
%e%N%n% give, n%n%give
%e%(G%u%)
%e%
%c%w
%e%
%e%%i%
%e%%g%
%e%
%c%n
%c%n
%c%n 1
exit/b
:n
%e%N%n%G%u%
%e%N%n%let%y%down
%e%N%n%run around and desert you
%e%N%n%make%y%cry
%e%N%n%say goodbye
%e%N%n%tell a lie and hurt you
if %1.==. %e%
exit/b
:w
%e%Your heart's been aching but
%e%You're too shy to say it
%e%Inside we both know what's been going on
%e%We know the game and we're gonna play it
\$\endgroup\$
2
\$\begingroup\$

Knight, 700 699 bytes

O;O+"We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of
You wouldn't get this from any other guy"+=n++"
I just wanna tell you"=e" how I'm feeling
""Gotta make you understand
"+=r+=g+"
Never"=o" gonna "+=a"give you up"+g+"let you down"+g+"run around and desert you"+g+"make you cry"+g+"say goodbye"+g"tell a lie and hurt you
"+=i+"
We've known each other for so long
Your heart's been aching but
You're too shy to say it
Inside we both know what's been going on
We know the game and we're"+o"play it"+"
And if you ask me"+e+"Don't tell me you're too blind to see
"+r+r+*=y+=u"
(Ooh"+", "+a=v")"2+u+=p+v+GrF17+", n"Gr 2 15+=y+"
(G"+GaT10v+u+p y;Oi+n*r 3

Try it online!

Done blindly without checking the other answers. I'm sure that stealing adapting some other answer's tricks would shave off a few bytes, though.

This has two trailing newlines. I don't know if that is acceptable. LMK and I will attempt to fix that.

This isn't that interesting, it is just a lot of substitution. Multiple OUTPUT statements are used to get more newlines.

  • 1 byte: remove overzealous compression
\$\endgroup\$
1
\$\begingroup\$

Perl - 706 699 characters.

Completely safe to cut+paste :)

Did the encoding by eye, should be possible to get a better ratio if I get around to doing some statistical analysis.

$_=q{$_="Fn3strSgersMlovez1C P rules ~s3W IzTfull commitmentXwhatNthYkYg ofz1wouldn'UgeUthis from SyOguyDAn5~if 1askL8Wn'U%L9blYdMsee00z22==A5D00zz"V=Qz64, 64q4 1RVDzI jusUwSnT% 18gottTmakZ1understSd0V2Q, 4 1RVQqoohV0z04 1R0leU1Wwn0run aroun_~deserUJ0makZ1cry0say goodbye0% TliZ~hurUJV%tellV0z6V1J V4giveV5 eachOfor s3longzJr heart!achYg butz9shyMsBYsidZK both C what!goYg onzK C P gamZ~F7plBV~S_V6never 7V_d V7gonnTV!Xbeen VX's VWdoV8howNfeelYgzV9J'rZto3VAzzK'vZCVBay itzVCknowVFK'rZVJyouVKweVYinVL mZVM t3V3o VN I'm VO oPr VZe VPtheVRupVSanVTa VUt Eq([^zq])([^zq]+)/"\r\n(".H."$2)"Ez(\(?[^z]?)/"\r\n".HE(^.)/H;};s'H'uc($1)'g;s:V(.):;G$1/:g;s:E:;eG:g;s:(e?)G(.+?)/(.+?);:;s/$2/$3/g$1;:g;eval;print
\$\endgroup\$
1
\$\begingroup\$

PHP - 802 bytes and Python - 795 780 bytes

Below is a PHP script that downloads the lyrics, compresses them using a naive implementation of LZSS and then outputs the compressed string together with some decompression code (802 bytes).

$in = file_get_contents("http://pastebin.com/raw.php?i=wwvdjvEj");
$compressed_string = '';
$inc = true;

for ($i = 0; $i < strlen($in); $i++) {
    $offset = 0;
    $length = 0;

    for ($j = 1; $j < strlen($in) - $i + 1; $j++) {
        if (($os = strpos(substr($in, 0, $i), substr($in, $i, $j))) !== false) {
            $offset = $os;
            $length = $j;
        } elseif ($length > 0) {
            break;
        } else { 
            $length = 0;
            break;
        }
    }   

    if ($length > 0) {
        $rep = '';
        if (!$inc) {
            $rep = '>';
        } 

        $rep .= $offset . '|' . $length;

        if (strlen($rep) < $length) {
            $compressed_string .= $rep;
            $i += $length - 1;
            $inc = false;
            continue;
        }
    }

    $compressed_string .= substr($in, $i, 1);
    $inc = true;
}

echo '<?$f="' . $compressed_string . '";do$f=preg_replace_callback(\'/>?(\d+)\|(\d+)/\',create_function(\'$m\',\'global$f;return substr($f,$m[1],$m[2]);\'),$f,1,$c);while($c);echo$f;';

And this is the output:

<?$f="We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of26|6wouldn't get this from any other guy
I just wanna tell you how84|5feeling
Gotta make you understand

Never gonna giv192|7p210|14let you down210|14run around46|5desert you210|14>189|9cry210|14say goodbye210|14tell a lie46|5hu294|8
We've31|5n each132|7for so long26|5r heart's been aching but26|5're too shy to say it
Inside we both31|6wha437|9go94|5n
W396|6 the gam374|6w1|5gonna pl477|7And if you ask me165|18Don't156|6me y459|10blind to see208|184>212|180(Ooh,223|12)1002|20
(Ooh)210|18, n213|15
(G1031|58>1011|13>390|12>403|165>142|250>644|356";do$f=preg_replace_callback('/>?(\d+)\|(\d+)/',create_function('$m','global$f;return substr($f,$m[1],$m[2]);'),$f,1,$c);while($c);echo$f;

Based on the same idea, I also made this Python script, which is slightly smaller than the PHP version.

import re
p=0
s="""We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of26|5wouldn't get this from any other guy
I just wanna tell you how82|5feeling
Gotta make you understand

Never gonna giv187|7p204|13let you down204|13run around45|5desert you204|13>184|9cry204|13say goodbye204|13tell a lie45|5hu285|7
We've30|5n each129|7for so long
Your heart's been aching but
You2|4too shy to say it
Inside we both30|6wha422|9go92|5n
W382|6 the gam362|6w1|5gonna pl461|6And if you ask me161|17Don't152|6me y443|10blind to see203|175>205|173(Ooh,216|12)967|19
(Ooh)204|17, n206|15
(G994|55>975|12>377|11>389|160>139|239>622|345"""
while p!=s:p=s;s=re.sub('>?(\d+)\|(\d+)',lambda m:s[int(m.group(1)):int(m.group(1))+int(m.group(2))],s,1)
print s
\$\endgroup\$
1
\$\begingroup\$

C - 890 Characters

I haven't seen many C ones so I thought I'd do one. This is my first attempt and I know it's not the shortest but was interesting to do and works. This is basic word compression but trying not to have any delimiters in the dictionary to save space. A bit of recursion and a few macros just to mix it up a bit! Unfortunately I now know the lyrics by heart and can't get the tune out of my head!

char m[20];   char*t="aIAuptoitsoWeweonmeofnoifdoanyyouandsayrunlieletcryup)I'mtoothehowYoushyforbutseeguygetaskAndgivetellmakeknowhurtdownbeenYourplaylongjustgameeachboth(OohwhatthislovefullfromotherNevergonnaWe'vewe'rewannaneverGottagoing(Ooh)(GiveWe'rerulesNeverknownDon'tblinddesertaroundYou'rewhat'sInsideachingyou'regoodbyefeelingheart'swouldn'tthinkingstrangersunderstandcommitment's";
int l[]={0,3,12,22,20,17,7,3,2,1,1,0,1};
#define h "i^H3& i^83M i^6n4m3 i^J39 i^5t i^I#74L3"
#define v "_jT\\A)Q OvNrB o<@'5( q+UKpNd, *K=S4`^P("
#define n "$RaI3>;u cJ3z"
char*s="g/y'Y ?K=h4)1$ %Z{W;x. ?wEX[2\\D "n"  "h"  "v" G03F->;u kI-s<l'C  "h"  "h"  VH3: VH3: e ]^Hb^H f3: e ]^Hb^H f3:  "v"  "n"  "h"  "h"  "h" ";
char*w(int r,int c,int u,int o){m[c]=0;u+l[c]<=r?w(r,c+1,u+l[c],o+l[c]*c):strncpy(m,t+o+(r-u)*c,c);return m;}
void RA(){while(*s!=0){printf(*s==' '?"\n":"%s ",w(*s-35,1,0,0));s++;}}
\$\endgroup\$
1
  • \$\begingroup\$ Suggest u+l[c]>r?strncpy(m,t+o+(r-u)*c,c):w(r,c+1,u+l[c],o+l[c]*c) instead of u+l[c]<=r?w(r,c+1,u+l[c],o+l[c]*c):strncpy(m,t+o+(r-u)*c,c) and for(;*s;s++)printf(*s-32?"%s ":"\n",w(*s-35,1,0,0)); instead of while(*s!=0){printf(*s==' '?"\n":"%s ",w(*s-35,1,0,0));s++;}. Also you can combine string declarations to eliminate char several times. \$\endgroup\$
    – ceilingcat
    Sep 21, 2016 at 18:53
1
\$\begingroup\$

PHP 948 Bytes

$w=array("Never gonna ","Give","give","feeling","understand","goodbye","wanna","str_replace");$s=array("$w[0]$w[2]+up#$w[0]let+down#$w[0]run around@desert+#$w[0]make+cry#$w[0]say $w[5]#$w[0]tell a lie@hurt+","each other for so long#Your heart's been aching but#You're too shy to say it#Inside we both know what's been going on#We know the game@we're gonna play it","(Ooh, $w[2]+up)");$t="We're no strangers to love#You know the rules@so do I#A full commitment's what I'm thinking of#You wouldn't get this from any other guy#I just $w[6] tell+how I'm $w[3]#Gotta make+$w[4]*$s[0]*We've known $s[1]#And if+ask me how I'm $w[3]#Don't tell me+'re too blind to see*$s[0]*$s[0]*$s[2]#$s[2]#(Ooh)#$w[0]$w[2], $w[0]$w[2]#($w[1]+up)#(Ooh)#$w[0]$w[2], $w[0]$w[2]#($w[1]+up)*We've know $s[1]*I just $w[6] tell+how I'm $w[3]#Gotta make+$w[4]*$s[0]*$s[0]*$s[0]";echo nl2br($t=$w[7]("#","\n",$t=$w[7]("*","\n\n",$t=$w[7]("+"," you ",$t=$w[7]("@"," and ",$t)))));
\$\endgroup\$
1
\$\begingroup\$

626 Bytes, PHP (output as Pastebin link below)

<?=str_replace(str_split(LCB2Z34516789HJKPQRSTUVX),explode(M,"ever 6M
I just wanna J9Z
Gotta U9understand
BM279up2let 9down2run arouHaHdesert you2U9cry2say goodbye2Ja lie aHhurt youM
Never 6Mhow I'm feelXM
We'vePn eachRfor so longQr hearTachX butQ'reKshy to say it
Inside we bothP whaTgoX on
WePSgaVaHwe're 6play itM8, 79up)M8)
N1, n1
(Give 9up)Mever 6giveMgonna Mgive M
(OohMyou Mnd Mtell M too M knowM
YouM other M the Mt's been Mmake Mme Ming"),"We're no strangers to loveQPSrules aHso do I
A full commitment's what I'm thinkX ofQ wouldn't get this from anyRguyC
3
AHif 9ask VZ
Don't JVyou'reKbliHto see
B
B
4455
3
C
B
B");

To make this easier to verify, here's the output: http://pastebin.com/xzXsw3wQ

Here's the program that I used to write this program: http://pastebin.com/NGX1Qe0Z. It's pretty hacky, but it should be fairly clear how it works. There's a map array that's used to encode/decode, and the program above is written to program.php. It checks to make sure the output matches the lyrics file (lyrics.txt) and shows the byte count. You could probably do better than my byte count by writing a better map.

\$\endgroup\$
1
\$\begingroup\$

PHP:1002 Chars

Well this is my first CodeGolf, I'm sure I missed some things. It should echo out the lyrics with the line numbers.


I'll come back to this later, I'm a little sick of looking at these lyrics @.@ .

$o="Ooh";
$u="You";
$y="you";
$gi=" give";
$gu=ucfirst(trim($gi));
$n="Never gonna";
$yu=" $y up";
$g=" $gi $yu";
$l=" let $y down";
$r=" run around and desert $y";
$m=" make you cry";
$s=" say goodbye";
$t=" tell a lie and hurt $y";

$ch="
$n $g
$n $l
$n $r
$n $m
$n $s
$n $t";

$v1e1="I just wanna tell $y how I'm feeling
Gotta make $y understand";
$v1="We're no strangers to love
$u know the rules and so do I
A full commitment's what I'm $d thinkin' of
$u wouldn't get this from any other guy
$v1e1";
$v2="We've known each other for so long
$ur heart's been aching but 
$u're too shy to say it
Inside we both know what's been going on
We know the game and we're gonna play it";
$v2e1="And if $y ask me how I'm feeling
Don't tell me $y're to blind to see";

$br="
($o,$d$g)
($o,$d$g)
($o)
$n$gi $n$gi
($gu$yu)
($o)
$n$gi $n$gi
($gu$yu)
";

$a="$v1
$ch

$v2
$v2e1
$ch
$ch
$br
$v2

$v1e1
$ch
$ch
$ch";

$z=preg_split('/\\r\\n|\\r|\\n/',$a);

$num=0;
foreach($z as $ly){echo $num." ".$ly."<br/>";$num++;}
\$\endgroup\$
1
\$\begingroup\$

PHP - 737 719 Characters

<?$m="str_replace";$c="^g% ^let# down^run around and desert#^make# cry^say goodbye^tell a lie and hurt#@";$w="@We've known each other for so long@Your heart's been aching but@You're too shy to say it@Inside we both know what's been going on@We know the game and we're gonna play it@";$o="(Ooh,g%)@";$a="(Ooh)^give, never gonna give@(G%)@";$i="@I just wanna tell# how I'm feeling@Gotta make# understand@";echo$m("@","<br />",$m("#"," you",$m("%","ive# up",$m("^","@Never gonna ","We're no strangers to love@You know the rules and so do I@A full commitment's what I'm thinking of@You wouldn't get this from any other guy$i$c$w And if# ask me how I'm feeling@Don't tell me#'re too blind to see@$c$c@$o$o$a$a$w$i$c$c$c"))));

Whee for breaking all sorts of rules!

\$\endgroup\$
1
\$\begingroup\$

PHP, 1192 bytes:

<?=
'<pre>'.
(function ($compressed) {
preg_match_all("#(^.+?)\n(.+$)#us", $compressed, $matches, PREG_SET_ORDER);
list($schema, $compressed) = [ $matches[0][1] , $matches[0][2] ];
for ($ix = strlen($schema) - 1; $ix >= 0; $ix--) {
    $char = $schema[$ix];
    $charQuoted = preg_quote($char, '#');
    preg_match_all("#{$charQuoted}(.+?){$charQuoted}#mus", $compressed, $matches1, PREG_SET_ORDER);
    $fullQuoted = preg_quote($matches1[0][0], '#');
    $compressed = preg_replace("#{$fullQuoted}#mus", $matches1[0][1], $compressed);
    $compressed = str_replace($char, $matches1[0][1], $compressed);
}
return $compressed;
})(
'!"$%&*+-./0123456789:;<=>?@BCEFHJKLMPQRSTU
We9\'re9 n5o L5sLtrangSerSs2 t25lo<ve<4
YMouM4/ knowB/2heB rules0C aC>nd> 0s5d5I
AP fPull commitQmeQnt\'sE wEhatR I\'mR2hink:ingK: Kof4EMldn\'t6 g6et2hisPromCny= othS=6uy%
I justEanna2FellF1* 1yM*. howRPeel:
.Gotta Hmake1Hu>Ssta>!%
-
N$-e<r?6TonTna ?$g+Ji<J1up+-let1down-runCrM>0desSt*-Hcry-say6oodbye-tFC lie0hurt*!7

We\'</7n" each=Por s5lTg4r hear8t\'s been8CchKbut492oLhy2L@ay it
@InsideEe both/Eha86oKT
WeB6aQ0we9?pl@"A> if1ask Q.DT\'t2F Q*92o5bli>2LeeU!!U
3
(Ooh3,6;+);3,6&;3)-gJ, n$gJ
(G&&;7"%U'
).'</pre>';
?>

Live DEMO of arbitrary text (de-)compression

\$\endgroup\$
2
  • 3
    \$\begingroup\$ There's a lot of bytes to be saved by removing non-functional whitespace and shortening variable names. There's also no need for <pre> tags, as you can run PHP in the console. The trailing ?> can likewise be removed. \$\endgroup\$
    – Dennis
    Dec 30, 2017 at 14:25
  • \$\begingroup\$ That and replacing PREG_SET_ORDER with 2 brings your score down to 864. Try it online! \$\endgroup\$
    – Dennis
    Dec 30, 2017 at 14:31
1
\$\begingroup\$

Batch, 930 920 bytes

(Alternate method)

Thanks @Aacini for the skip such number of lines and show the rest of this file

@!! 2>nul||cmd/q/v/c%0&&exit/b
set l=^


set u= you 
set n=ever gonna 
set g=ive you up
set f= how I'm feeling
set w=I just wanna tell you
set c=N!n!g!g!!l!N!n!let!u!down!l!N!n!run around and desert you!l!N!n!make!u!cry!l!N!n!say goodbye!l!N!n!tell a lie and hurt you!l!
set u=Gotta make you understand!l!.!l!!c!
set k=We've know each other for so long!l!Your heart's been aching but!l!You're too shy to say it!l!Inside we both know what's been going on!l!We know the game and we're gonna play it
for /F "useback skip=15 delims=" %%a in ("%~0")do set v=%%a&echo(!v:.=!
exit/b
<
We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of
You wouldn't get this from any other guy
!w!!f!
!u!
!k!
.
And if you ask me!f!
Don't tell me you're too blind to see
.
!c!
!c!
(Ooh, g!g!)
(Ooh, g!g!)
(Ooh)
N!n!give, n!n!give
(G!g!)
(Ooh)
N!n!give, n!n!give
(G!g!)
.
!k!
.
!w!!f!
!u!
!c!
.
!c!
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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