11
\$\begingroup\$

Task

Your task is to write a program that will take input, and then output the lyrics to We Are Number One, changing specific words. The input will contain both the words to be changed, and the replacement word.

Input

The input will be in the following format:

one, two\n
net, villain\n

(\n is a newline, it's not actually visible.) The input is assured to be this format, and the first word will always be a word the lyrics contains. But you can take input in whatever format you prefer the most.

Output

Your output will be the entire We Are Number One lyrics, but with the words that are given in the input swapped.

Original lyrics:

Hey!
We are Number One
Hey!
We are Number One

Now listen closely Here's a little lesson in trickery This is going down in history If you wanna be a Villain Number One You have to chase a superhero on the run Just follow my moves, and sneak around Be careful not to make a sound (Shh) (CRUNCH) (No, don't touch that!)

We are Number One Hey! We are Number One We are Number One

Ha ha ha Now look at this net, that I just found When I say go, be ready to throw Go! (Throw it on him, not me!) (Ugh, let's try something else) Now watch and learn, here's the deal He'll slip and slide on this banana peel! (Ha ha ha, gasp! what are you doing!?)

Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number One Hey! Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number One Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number One Hey! Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number One Hey! Hey!

Source

Rules

  • The first word per input is assured to be in the lyrics.
  • Your code must be case-insensitve (one as input will replace One)
  • Trailing newlines are allowed.
  • The input may be lower and uppercase, and the resulting output must have the same casing as the provided input.
  • The input can try to replace e.g. one with one. If you replace it or not, is your choice.
  • "Words" are sequences of characters seperated by space or commas, not by anything else (e.g. Hyphens), therefore Ba is not a valid input, but Ba-ba-biddly-ba-ba-ba-ba is.

Example case

Input:

one, three
net, villain

Output:

Hey!
We are Number three
Hey!
We are Number three

Now listen closely Here's a little lesson in trickery This is going down in history If you wanna be a Villain Number three You have to chase a superhero on the run Just follow my moves, and sneak around Be careful not to make a sound (Shh) (CRUNCH) (No, don't touch that!)

We are Number three Hey! We are Number three We are Number three

Ha ha ha Now look at this villain, that I just found When I say go, be ready to throw Go! (Throw it on him, not me!) (Ugh, let's try something else) Now watch and learn, here's the deal He'll slip and slide on this banana peel! (Ha ha ha, gasp! what are you doing!?)

Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number three Hey! Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number three Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number three Hey! Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba We are Number three Hey! Hey!

Winner

This is , so the author of the shortest code in bytes wins!

\$\endgroup\$
16
  • 7
    \$\begingroup\$ Gotta love memes, do I get a bonus if I output a noise for the branch scene? ;) \$\endgroup\$ Dec 21, 2016 at 9:26
  • 1
    \$\begingroup\$ also related - looks like all the memes are coming to PPCG! \$\endgroup\$
    – FlipTack
    Dec 21, 2016 at 10:08
  • 4
    \$\begingroup\$ Is there a reasonable way to do this other than producing the lyrics kolmogorov-complexity-style, then using your language's string replacement methods on the results? This seems like the concatenation of two separate challenges. \$\endgroup\$
    – xnor
    Dec 21, 2016 at 10:28
  • 5
    \$\begingroup\$ Does "here's" need to be handled as a word? Is "Ba-ba-biddly-ba-ba-ba-ba" a word, or is each part a word? Can a word be replaced by another word that is itself a word to be replaced, and if so, do the replacements happen in sequence? Should the replacements preserve the capitalization of the original? Are the input words guaranteed to be lowercase? Are you guaranteed the song contains both words? \$\endgroup\$
    – xnor
    Dec 21, 2016 at 10:34
  • 2
    \$\begingroup\$ In at least 2 answers below, the input was restricted to exactly two word, word pairs. The question doesn't seem to be clear on the range of the input. Should programs be able to handle an arbitrary amound of word, word\n pairs? \$\endgroup\$
    – TidB
    Dec 22, 2016 at 9:53

5 Answers 5

12
\$\begingroup\$

PHP, 666 bytes

I suppose this is a rather appropriate code size for a song about Villains...

<?$s=gzinflate(base64_decode("zVLNitswEL4b/A6TUxLwPkNh99BkDynsT5ceJ9YkUjPWBEle47fvjJVCoWyh0EPRYMme8cz3ox3Nq7Z5I8BEcBiHIyX4Eqltdh8l6jrIBBxyoQg9Syae7ZdE6wyoiVKYgClniRAilBT6CyWtefEhg8ZZQjyDk2nJ68cilt6fYJYRJowR4ajD4WtgRi35FcI3LfH4TlAEeo/Z6vJ4peQpCejI4gnSGNvmccwFTsKscIcZBnmn3AFGBzkSXpScjNG1zT1Br0RPI0OUYn0HvCxta37z7P1Wt4en18PDzk4H6RR+XFvx2HsdiWW1reL8jZwfKLxDZahxU1pEseooUy9S6ZZxsIfvld+C8c2rGXvIOKu6namXCN1sZIpPMrXNZ1EMmxd7gVBMKB+GbmE8kIHfvJ59p74VtbGkWdkPpDPVKeJM2wpmwqJ8TUMmTLEDX3030R0hG9k1M2QO1yo1B0fVFoV/xKgLrkRsaH4S7eCM+bqCyYiZInYPnN2S1aebrPd4d9QIzvG8nG6hXPHut/iDDf+g0f+EpTay5w8="));foreach($argv as$a){@list($a,$b)=explode(",",$a);$s=str_ireplace($a,$b,$s);}echo $s;

Usage: php numberOne.php one,three net,villain

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

PHP, 661 652 bytes

for($s=base64_decode(gzuncompress("eJy1ks1u2zAQhO98itXJNqA8Q4DkULsHF2jzgx7X4tpkvSINkorAt+9QaoECyaE9VNoDQa44M99qL7Uzr0KchI7TeJJEX4KY/cfbeI5xJvW5SKBBYxataE6yycTYL0WFVHKOgXygkvxwlVTNk/OZUJfow4VsnJdjbJaI08OZapxo5hCYTlClF6/K6PhD+zs6HL8JlUiD49za8nST5CRFgl5xQmkK5vOUC52jKpyOlcb4JrknDpZyEL4iU5yCNQ9CA+KdJ6UQS7t15Oty6XK8/ebczmwfvz4fH/dYHGMP32HTOqfBQY1LtwOQv4b3Ec49IxNqxRoj3EGgwQpS+kWEDvRjTdRsvTqAP1DmCpZ9g5WEbW32i0txNp9iZ7ZPbUm+NCzOj/2ScBT43T5fXI8JFQyspIqwo0APQxHNslt8zFwQsAFT4RR6cuuAG2ArrAi4UaWs/rZiVW9lnQCMnzjgpZuIwsnvgD1dON86mluihqEN3La/obtvFB/47oTy1mpdVr8KEfnuXZnuXz94D/9/K3bLf/AT6bEYSw"));$t=fgetcsv(STDIN);)$s=preg_replace("#\b$t[0]\b#i",$t[1],$s);echo$s;

gzinflate is 3 bytes shorter than gzuncompress, but gzcompress has the shorter output.

And: The other PHP answer replaces substrings, not words. I´d save 8 more bytes with that.

breakdown

for($s="text";                              // init text
    $t=fgetcsv(STDIN);)                     // loop through STDIN lines
    $s=preg_replace("#\b$t[0]\b#i",$t[1],$s);   // replace pairs
echo$s;                                     // output
\$\endgroup\$
1
\$\begingroup\$

Python 2.6, 695 bytes

import re 
import zlib,base64

a=input().split(', ')
t = zlib.decompress(base64.b64decode(b'eJzNks+KGzEMxu9+Cs0pCcw+w8LuoUkPKbT7hx6VsRK70VjB9uzgt68000KhWyj0UiKCsYW+7/tp9tQ690qAmeA4jSfK8CmR279/7dxRZuBYKiUYWApx095MmwKo97UyAVMpkiAmqDkOV8rNPYVYQOsiMV3Ay7w862UVfT2cockEM6aEcFJReInMqB2/SH/VjoBvBFVgCFisrUw3yoGygOrVQJCn5D5OpcJZmNXp2GCUNyo9YPJQEuFVI8mUvHsgGDTdeWJIUm3qiNdl6PK8/RLCzm0fPz8fH/d6OEqvvtPGOqchqBrWbqdA/prdezT3qJm0Vqwi6k4FDFai2i8icIBvayKz9RoU/AEKNmXZG6xM6JvZryHL7D5I57ZPdoRYDUuIY78kHEn9bp8vodcNVV1YzU3DjqR6uhTiQrvFx4xVAxowJsyph7Au2AB7QtaAG2YoHG8rVo6e1g2o8RMm/cGNiNXJz4A9XLDcOpgtkWGwhXv7Grp7o/iAdyet6D235fSjNCLe/VZ/gv7PU/4TG8sU+/sO/HItbg==')).decode('utf8')
for i in xrange(0,len(a),2):
    t = t.replace(a[i],a[i+1])
print t

Output

Hey! We are Number three Hey! We are Number three

Now listen closely
Here's a little lesson in trickery
This is going down in history
If you wanna be a Villain Number three
You have to chase a superhero on the run
Just follow my moves, and sneak around
Be careful not to make a sound
(Shh)
(CRUNCH)
(No, don't touch that!)


We are Number three
Hey!
We are Number three
We are Number three


Ha ha ha
Now look at this villian, that I just found
When I say go, be ready to throw
Go!
(Throw it on him, not me!)
(Ugh, let's try something else)
Now watch and learn, here's the deal
He'll slip and slide on this banana peel!
(Ha ha ha, gasp! what are you doing!?)


Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba
We are Number three
Hey!
Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba
We are Number three
Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba
We are Number three
Hey!
Ba-ba-biddly-ba-ba-ba-ba, ba-ba-ba-ba-ba-ba-ba
We are Number three
Hey!
Hey!
\$\endgroup\$
2
  • \$\begingroup\$ The word-to-replace, word arguments should be dynamic. At the moment, you hardcoded it to have exactly 2 arguments with the to-be-replaced words always being One and net. Also, there's a lot of golfing potential there. You can disregard input entirely and take the string as a function argument, write everything in one line, compress the text (substitution, zlib come to mind), use shorter variable names, replace re.I and re.X with their numerical values. Additionally, this doesn't even run as word1 and word2 aren't defined (you probably meant w1 and w2. \$\endgroup\$
    – TidB
    Dec 22, 2016 at 9:19
  • \$\begingroup\$ edited my code... \$\endgroup\$
    – Falcon
    Dec 22, 2016 at 10:59
1
\$\begingroup\$

05AB1E, 842 bytes

•®_Dzîü!úïæ²|ˆ9¶iˆtˆEC}#©ÿ®cÖ:|®¥÷K*œÒÅ5œ1‚ÂlÊΤNç·’±Ðá×ÍÐý5WÝ㢮ìÖ$hVbPGwηM;9O|‰¶ÉèëøËöç¡QÒµ5‚aC}.*gbJǦ>);&f€ZÛ}íóÉh\„Ú;Ts§ÞT¿QZëDò©®#ÑSHžûd¦Óéó”ó\ê§ø5|PšÍÖcyÐÁ:hŒ02¨ÄùSûíi¯—àR›ÿR{3Í)Ú×E<u¥°¼:—jth€ƒWƪâþ=—vJ†ÀJûy6Áv\TÈÞåšöQë£Âb„ˆ@Ò6^#ˆL*ÁöªAWçàˆÌä£#«ùÁ°è;sq¯¸GšìááЩ–ob¾§m^¹+ò"-Å£‘u·ãÿ?ù÷7Á^)8GÑ<oßÝ7Åjœq–[—'XuDÔÈìïÃ÷áÓ´‚ñ)©™à$ÝS¢¦(ð8M'§›¬§³N(En"H#«Ÿß½µ`Å´½axxq\òÝP@HÓ‘š£m—‹váøÃGàhT™ËUc·€ô~¥CEw6G¥Âã”ú¾&º™e,"AÂy±²ÅÜÚMâ2qtBaaª.^`òÍ–Ú$¦~z¢PÇR²”6â#”½Ì0ÂVêž]oɦs¯Ž½Ç˜ûRG™¸§I?™µ¦½ÀÓþæ8i‚%‘L#]ÒXÓ†A“r*Å;E%c¾0H;ø<½yÎ=^ù_í<ÃòõŽŸq!ùßN÷wP0q1¹‰~Õ¿´zÿgI,¸$ž¬…ÃÊGÖ¢e¸ŒHFMcw,Î()¼ü»T×–r{&h·q²¬5¡ýWÑÈú¬«ñÚRóD›<üŽ‹Nê*¹f¦›þÆYÓ–hýÂ}§l<Ñò<Ýù†ïÓi#‹k€ö#[ûlù_=¡ç·FÜØ]¢n©l›ÜÍ,ɈØrôN5Ô¸¹NGúoÝ][{½ãÚ;S*ÌåÙC€\À=k½;qU,pT$Ÿ5uÕœ¼§/›Kàô™eéù‚.Úæ·vx¾Xugvš–ûî?øc}|/žr¡¶µt…’öà,2;ˆ«=ÆF5£ØÓ¯~À|ýÝÓß]nLÔ<ëïÂåkQ`µ3DxБ!´‚Ù7AÏmi¦nvgã…ñ•121B"012345678"¶" ()!,-'?"«‡¹',¡vyN²',¡è.:}

Try it online!

Simplistic approach, didn't do anything but replace symbols with integers, convert from base-121 to base-214. Then I decompress it, re-replace the characters and perform replacement on the words. For testing I suggest replacing pronouns with other pronouns.

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

Python 3.4, 666 bytes

import zlib,base64,sys,re;s=zlib.decompress(base64.b85decode(b'c%03W&uSwv494$%3e71AOrN399-8!!!fyYtM`f(UZZuY~Jste^D|@=Iuw5whQX+z}g}(3mX|_~4^Fn};U_XrqitrG~Y(Ks>W-l|aPniM?EQz>iZ=_WM)cc&7fGH&j-~;67hcm@u9-U91brK&=U}bL4dYMIEcSk5P!Hgjw98?sZJu_;@U(&y{!{Hl278o3++LopZMMqIU^|B*~Q!w{a%5W5BbvhOp<&9Dg7%Zefc-BZV1#4~y22FRI7=q+Fb;NTU+Md@xo!gl8?T@GZ?N$$a>D6~w)y`>fs)o7SD3H&?`v|AmqNdVXz>26pm8iG^<-W<l4qlf`)!2(u^gBpclxAOXMM7I@fb62o=1w}Zeym6Exq@+i>|4f>)baZ1<a*sv)|KU0H10^Mr)wcjv}rzO%o?#GW5O7EaLbA-VoS)HaK#LX{bd2m-qNxIHGaULKe!OFI{6c@hZCkt2XjqSIn<Tg`aN{ljpGeo9kjf)T-xcqG$UU9Q~$&M<tg99Mw?RqegpM6EsO')).decode('utf8');
for a in sys.argv[1:]:x,y=a.split(', ');s=re.sub(x,y,s,99,2);
print(s)

Edits:

  • Used regex replace instead of replace so that it works case insensitive.
  • Used command line to get the parameters instead of input.
\$\endgroup\$
2
  • \$\begingroup\$ Your solution appears to accept only two text pairs. Also, you have to split at , , not just ,. You can golf this down by converting it into a function import zlib,base64 def h(a,b):return "string".decode('utf8').replace(*a.split(", ")).replace(*b.split(", ")). Note that this will be still incorrect as the number of args is limited to 2. It also seems that you have compressed the wrong lyrics; when I decompressed your string I got the version with We are Number three, which is an example output in the question above. \$\endgroup\$
    – TidB
    Dec 22, 2016 at 9:34
  • \$\begingroup\$ Changed it to the correct text & split at ', ', question didn't mention that there could be more than 2 inputs. Also noted that it's case sensitive so some rework to be done it seems. \$\endgroup\$
    – Carra
    Dec 22, 2016 at 9:50

Your Answer

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

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