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 (
oneas input will replaceOne) - 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.
onewithone. 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
Bais not a valid input, butBa-ba-biddly-ba-ba-ba-bais.
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 code-golf, so the author of the shortest code in bytes wins!
5 Answers 5
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
-
6\$\begingroup\$ upvote for the combination of villains + 666 + php \$\endgroup\$manonthemat– manonthemat2016年12月22日 07:20:56 +00:00Commented Dec 22, 2016 at 7:20
-
\$\begingroup\$ php.net/manual/en/function.bzcompress.php should save some bytes and replace
echo $s;withecho$s;\$\endgroup\$Jörg Hülsermann– Jörg Hülsermann2017年04月29日 15:05:26 +00:00Commented Apr 29, 2017 at 15:05
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
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!
-
\$\begingroup\$ The
word-to-replace, wordarguments should be dynamic. At the moment, you hardcoded it to have exactly 2 arguments with the to-be-replaced words always beingOneandnet. Also, there's a lot of golfing potential there. You can disregardinputentirely 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, replacere.Iandre.Xwith their numerical values. Additionally, this doesn't even run asword1andword2aren't defined (you probably meantw1andw2. \$\endgroup\$TidB– TidB2016年12月22日 09:19:38 +00:00Commented Dec 22, 2016 at 9:19 -
\$\begingroup\$ edited my code... \$\endgroup\$Falcon– Falcon2016年12月22日 10:59:47 +00:00Commented Dec 22, 2016 at 10:59
05AB1E, 842 bytes
•®_Ç2îü!úïæ2|ˆ9¶iˆtˆEC}#©ÿ®cÖ:|®\÷K*œÒÅ5œ1‚Âl×ばつÍÐý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\°1⁄4:—jth€ƒWÆaâþ=—vJ†ÀJûy6Áv\TÈÞåšöQë£Âb„ˆ@Ò6^#ˆL*ÁöaAWçàˆÌä£#«ùÁ°è;sq ̄ ̧GšìááЩ–ob3⁄4§m^1+ò"-Å£‘u·ãÿ?ù÷7Á^)8GÑ<oßÝ7Åjœq–[—'XuDÔÈìïÃ÷áÓ ́‚ñ)©TMà$ÝS¢¦(ð8M'§›¬§3N(En"H#«Ÿß1⁄2μ`Å ́1⁄2axxq\òÝP@HÓ‘š£m—‹váøÃGàhTTMËUc·€ô~\CEw6G\Âã"ú3⁄4&oTMe,"AÂy±2ÅÜÚMâ2qtBaaa.^`òÍ–Ú$¦~z¢PÇR2"6â#"1⁄2Ì0ÂVêž]oɦs ̄Ž1⁄2Ç ̃ûRGTM ̧§I?TMμ¦1⁄2ÀÓþæ8i‚%‘L#]ÒXÓ†A"r*Å;E%c3⁄40H;ø<1⁄2yÎ=^ù_í<ÃòõŽŸq!ùßN÷wP0q11‰~Õ¿ ́zÿgI, ̧$ž¬...ÃÊGÖ¢e ̧ŒHFMcw,Î()×ばつ–r{&h·q2¬5¡ýWÑÈú¬«ñÚRóD›<üŽ‹Nê*1f¦›þÆYÓ–hýÂ}§l<Ñò<Ýù†ïÓi#‹k€ö#[ûlù_=¡ç·FÜØ]¢n©l›ÜÍ,ɈØrôN5Ô ̧1NGúoÝ][{1⁄2ãÚ;S*ÌåÙC€\À=k1⁄2;qU,pT$Ÿ5uÕœ1⁄4§/›KàôTMeéù‚.Úæ·vx3⁄4Xugvš–ûî?øc}|/žr¡¶μt...’öà,2;ˆ«=ÆF5£ØÓ ̄~À|ýÝÓß]nLÔ<ëïÂåkQ`μ3DxБ! ́‚Ù7AÏmi¦nvgã...ñ•121B"012345678"¶" ()!,-'?"«‡1',¡vyN2',¡è.:}
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.
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.
-
\$\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 functionimport 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 withWe are Number three, which is an example output in the question above. \$\endgroup\$TidB– TidB2016年12月22日 09:34:59 +00:00Commented 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– Carra2016年12月22日 09:50:44 +00:00Commented Dec 22, 2016 at 9:50
Explore related questions
See similar questions with these tags.
word, wordpairs. The question doesn't seem to be clear on the range of the input. Should programs be able to handle an arbitrary amound ofword, word\npairs? \$\endgroup\$