Code Golf Asked by Lebster on October 27, 2021
The goal of this challenge is to print the following tongue twister:
She sells seashells by the seashore,
The shells she sells are seashells, I'm sure.
So if she sells seashells on the seashore,
Then I'm sure she sells seashore shells.
This is more complicated than just calling your language’s print
equivalent. Since there are a lot of repeated words and phrases, you can greatly decrease the size of your code by using other tactics.
Rules:
This is code-golf, so the shortest code wins!
Good luck!
I{ECA}H{ }G{re}F{HI'mCuG}E{he}D{HtEBoG,
TE}C{Hs}B{Ceash}A{ells}SIBAHbyDChACIHaGBA,F.
SoHifCIBAHonDnFCIBoGChA.
Answered by Axuary on October 27, 2021
iiissiici{ii}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cdddcddd{i}ccddd{i}c{{d{{i}}}}c{d{i{i}}}ciii{ii}ci{i{d}}c{iiii{iii}}cdd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cddd{i}ciiicddd{d}cd{{ii}}c{d{{i}}}cdsiiic{ii}cdddci{iii{d}}ciii{dd{i}}cd{d}cdddcddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ci{ii{iii}}cddd{ii}cddd{d}ci{iii{d}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cdddcddd{i}ccddd{i}cd{iii{d}}cdd{d}ci{iiii}c{d{{i}}}c{ddd{i}}cd{dd{ii}}ciii{dd{i}}ciicdddcddd{d}ci{{ii}}c{ii{ii}}cdsiicdd{iii}ci{ii{d}}ciii{ddd{i}}cdddc{iii{d}}ciii{dd{i}}cd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cdddcddd{i}ccddd{i}c{{d{{i}}}}cd{dd{i}}cdcii{ii{d}}c{iiii{iii}}cdd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cddd{i}ciiicddd{d}cd{{ii}}c{d{{i}}}cdsiiic{ii}cdddcd{i}cii{ii{d}}ci{iiii}c{d{{i}}}c{ddd{i}}cd{dd{ii}}ciii{dd{i}}ciicdddcddd{d}ci{iii{d}}ciii{dd{i}}cd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cddd{i}ciiicddd{d}ci{iii{d}}ciii{dd{i}}cd{d}cdddcddd{i}ccddd{i}ci{iii{d}}c
As long as I didn't mess anything up, this should be the shortest possible without ()
and printing in loops.
Answered by ovs on October 27, 2021
say"S5s0 10 by t513,
T5sh02are 10, 4.
So if210 on t513,
Then 4213 sh0."=~s/d/(ells,seash," she sells ",ore,"I'm sure","he ")[$&]/ger
Answered by Dom Hastings on October 27, 2021
O+S=q+=sS=v" shells"4F" se"=tSvT0"sea"F2"S"+" by"+=p" the seashore,
The"+v+s+" are"+t+=u" I'm sure.
So if"+q+S" onn"3Fp+GuF9+s+Gp 4 9+v"."
Fiiiiiiiine, I'll explain it
Sorry, the indentation is a little inconsistent...
OUTPUT
+
# substitute " s" with "S" for initial capitalization
SUBSTITUTE(
= _she_sells_seashells
+ = _she_sells
# inject " se" into "shells"
# to get "she sells"
SUBSTITUTE(
= _shells " shells"
4
0
" se"
)
# inject "sea" to get " seashells"
= _seashells
SUBSTITUTE(
_shells
1
0
"sea"
)
)
0
2
"S"
)
+ " by"
+ = _the_seashore_the " the seashore,nThe"
+ _shells
+ _she_sells
+ " are"
+ _seashells
+ = _im_sure_so_if " I'm sure.nSo if"
+ _she_sells_seashells
# shorter to inject than concatenate
# to get " on the seashore,nThen"
+ SUBSTITUTE(
" onn"
3
0
_the_seashore_the
)
# Extract "I'm sure"
+ GET(
_im_sure_so_if
0
9
)
+ _she_sells
# " seashore"
+ GET(
_the_seashore_the
4
9
)
+ _shells
: "."
Answered by EasyasPi on October 27, 2021
iiissiic{ii}icdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ddsddc{ii}iiic{ddddddddd}ic{dd}dsdddddc{d}ddcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{ddddddd}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}dcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{{iii}ii}ic{ii}dddc{d}dddc{ddddddd}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{ddddddd}dc{d}ddc{iiii}ic{ddd}ddddc{iiiiiii}c{dddddddd}iiic{dd}s{ddd}iciicdddc{d}dddc{{ii}}ic{{ii}ii}cdsiic{iii}ddc{dddddddd}ic{{iii}iii}dcdddc{ddddddd}c{dd}s{ddd}ic{d}dcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ds{d}cdc{dddddddd}iic{dd}dsdddddc{d}ddcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{i}dc{dddddddd}iic{iiii}ic{ddd}ddddc{iiiiiii}c{dddddddd}iiic{dd}s{ddd}iciicdddc{d}dddc{ddddddd}ic{dd}s{ddd}ic{d}dcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{ddddddd}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{ddddddd}ic
Answered by wasif on October 27, 2021
iiissiic{ii}icdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ddsddc{ii}iiic{{d}i}ic{dd}dsdddddc{d}ddcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{{d}iii}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}dcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{{iii}ii}ic{ii}dddc{d}dddc{{d}iii}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{d}iii}dc{d}ddc{iiii}ic{ddd}ddddc{{i}ddd}c{{d}ii}iiic{dd}s{ddd}iciicdddc{d}dddc{{ii}}ic{{ii}ii}cdsiic{iii}ddc{{d}ii}ic{{iii}iii}dcdddc{{d}iii}c{dd}s{ddd}ic{d}dcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ds{d}cdc{{d}ii}iic{dd}dsdddddc{d}ddcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{i}dc{{d}ii}iic{iiii}ic{ddd}ddddc{{i}ddd}c{{d}ii}iiic{dd}s{ddd}iciicdddc{d}dddc{{d}iii}ic{dd}s{ddd}ic{d}dcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{d}iii}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{{d}iii}ic
Deadfish, the ungolfing language.
Answered by emanresu A on October 27, 2021
console.log(`She ${a='sells'} sea${c='shells'} by the sea${e='shore'},
The ${c} she ${a} are sea${c}, ${d="I'm sure"}.
So if she ${a} sea${c} on the sea${e},
Then ${d} she ${a} sea${e} ${c}.`)
Simplest JavaScript answer possible. Simply defines commonly used words. Annoyingly, compression made it longer
Answered by user100690 on October 27, 2021
ΓJx'p¨½ΞĿ∫Ẏj5pż¦Sβyεḟ?ṡ,ḣŀḢ¦ṠεΞĿ∫äeŻaŀ`◄,İ'm ṡ→.¶ȮSÏf£2₅Φεḟ?ṡ,ḣnİ'm ṡ→⁸ρΘŀḢ¦.
Better than Bubblegum!
Husk's string compression is pretty good for this task, a straightforward compressed string would be 82 bytes long. Here, we apply just a single substitution to make it shorter. The compressed string we use here is
he sells seashpSpells by the seashore,
The shells she sells are seashells, I'm sure.
So if spells on the seashore,
Then I'm sure spore shells.
The structure of the code is:
ΓJx'p¨...
¨... The compressed string
x'p split on occurrences of the character 'p'
ΓJ and joined by interleaving the first substring between the rest
What this does in practice is replacing the character 'p' with "he sells seash" everywhere in the rest of the string. This substitution was the one that generated the shortest compressed string among the ones I've tried; multiple substitutions are possible but they didn't seem worth the longer payload. The letter 'p' was chosen because it generates words like "spell" and "spore" in the text that can be compressed very well by Husk.
Answered by Leo on October 27, 2021
<<Z
S${4=${2=he s${1=ells}}${3= seash}$1 }by${5= the$3ore,
The} sh$1 s$2 are$3$1,${6= I'm sure}.
So if s$4on$5n$6 s$2$3ore sh$1.
Answered by pxeger on October 27, 2021
printf("S%2$s by%1$s shells%3$sare seashells, I'm sure.nSo if s%2$s on%1$sn I'm sure%3$sshells."," the seashore,nThe","he sells seashells"," she sells ")
Answered by user on October 27, 2021
thanks @branboyer for the edit!
print"S{0}ells by{1} shells she sells are seashells, I'm sure.nSo if s{0}ells on{1}n I'm sure s{0}ore shells.".format("he sells seash"," the seashore,nThe")
Answered by Prachiti Prakash Prabhu on October 27, 2021
Trying a different way of compressing it, in a different language. Feedback is appreciated!
function s(){a="kdg by the dj,/nThe g care dg, I'm sure./nSo if cdg on the dj,/nThen I'm sure cdj g.".replace(/c|k/g,function(match){return(match=="c")?"she sells ":"She sells ";});c=a.replace(/d|g/g,function(match){return(match=="d")?"sea":"shells";});return (c.replace(/j/g,"shore"));}
Answered by Bardic Wizard on October 27, 2021
iS230 by41h012 are30,5.
So if1230 on4n5123ore1h0.Í5/ I'm1ure
Í4/ the3ore,rThe
Í3/1eash
Í2/he10
Í1/ s
Í0/ells
Port of @Neil's retina answer to V (vim)
Answered by Mukundan314 on October 27, 2021
-1 byte thanks @Titus
see similar by Nail and Arnauld
$d='S0by36h461 are54,2.
So if60on3n2615ore6h4.'
"154 #he64# I'm6ure# the5ore,
The#ells#6eash# s"-split'#'|%{$d=$d-replace$i++,$_}
$d
Answered by mazzy on October 27, 2021
Because if bash counts then why not...
$1="seash"
$5="ells"
$4="he s$5 "
$6=" I'm sure"
$2="$1$5"
$3="$1`ore"
"S$4$2 by the $3,`nThe $5 s$4`are $2,$6.`nSo if s$4$2 on the $3,`nThen$6 s$4$3 $5"
Answered by will.mcenaney on October 27, 2021
Hex dump:
00000000: 78 9c 0b ce 48 55 28 4e cd c9 29 06 92 89 c5 19 x...HU(N..).....
00000010: 60 56 52 a5 42 09 58 18 28 90 5f 94 aa c3 15 02 `VR.B.X.(._.....
00000020: e2 41 e4 8a e1 ea 13 8b 52 11 7a 74 14 3c d5 73 .A......R.zt.<.s
00000030: 15 8a 4b 8b 52 f5 b8 82 f3 15 32 d3 90 14 22 0c ..K.R.....2...".
00000040: ce cf c3 34 38 0f ae 13 5d 4b 7e 11 cc 56 3d 00 ...48...]K~..V=.
00000050: 3c 70 3a e6 <p:.
Raw hex:
789c0bce4855284ecdc929069289c519605652a54209581828905f94aac31502e241e48ae1ea138b52117a74143cd573158a4b8b52f5b882f31532d39014220ccecfc334380fae135d4b7e11cc563d003c703ae6
Or generate this file yourself:
openssl zlib < seashells.txt > seashells.zlib
You can decompress this file execute this program with:
openssl zlib -d < seashells.zlib
or, presumably, any of the answers here.
Answered by user253751 on October 27, 2021
<?=strtr("S2 s101 by t203,nT2414e s1 are01,5.nSo if4e s101 on t203,nT2n54e s10341.",[" seash",ells,he,ore," sh"," I'm sure"]);
Try it online. Use PHP < 7.2 to avoid warnings
Answered by Titus on October 27, 2021
i=" I'm sure"
h=" she"
k=lls
l=" seashe"$k
s=" seashore"
e=" se"$k
printf "She$e$l by the$s,
The$h$k$h$e are$l,$i.
So if$h$e$l on the$s,
Then$i$h$e$s$h$k."
An expert can probably save some more here.
Answered by AlexJ136 on October 27, 2021
removed trailing newline for -1 byte
The text in the tongue twister has many simple patterns. There are enough of them that even "normal" languages can save bytes. However, the only thing DEFLATE does is compressing simple patterns with little overhead...
00000000: 0bce 4855 284e cdc9 2906 9289 c519 6056 ..HU(N..).....`V
00000010: 52a5 4209 5018 2c90 5f94 aac3 1502 e441 R.B.P.,._......A
00000020: e58a e1ea 138b 5211 7a74 143c d573 158a ......R.zt.<.s..
00000030: 4b8b 52f5 b882 f315 32d3 800a 310d cecf K.R.....2...1...
00000040: c334 380f ae13 a105 a602 66ab 1e00 .48.......f...
After "writing" this answer, I finally decided to find a way to view the internal representation details of the string (to be specific, information on what characters are printed literally and what substrings are compressed as repetitions via LZ77). I modified kunzip
(which already had some useful logging capabilities) to log only the information I want to see. This is the result:
output 83 S
output 104 h
output 101 e
output 32
output 115 s
output 101 e
output 108 l
output 108 l
output 115 s
len: 3 dist: 6 ( se)
output 97 a
output 115 s
output 104 h
len: 5 dist: 10 (ells )
output 98 b
output 121 y
output 32
output 116 t
len: 3 dist: 23 (he )
len: 5 dist: 17 (seash)
output 111 o
output 114 r
output 101 e
output 44 ,
output 10
output 84 T
len: 3 dist: 14 (he )
len: 7 dist: 28 (shells )
output 115 s
len: 9 dist: 48 (he sells )
output 97 a
output 114 r
output 101 e
len: 10 dist: 52 ( seashells)
output 44 ,
output 32
output 73 I
output 39 '
output 109 m
output 32
output 115 s
output 117 u
output 114 r
output 101 e
output 46 .
output 10
output 83 S
output 111 o
output 32
output 105 i
output 102 f
len: 3 dist: 41 ( sh)
len: 18 dist: 89 (e sells seashells )
output 111 o
output 110 n
len: 18 dist: 89 ( the seashore,
The)
output 110 n
len: 9 dist: 58 ( I'm sure)
len: 10 dist: 51 ( she sells)
len: 8 dist: 34 ( seashor)
len: 8 dist: 118 (e shells)
output 46 .
I think might will be useful for "normal" language answers.
Answered by the default. on October 27, 2021
v->"".format("S%sells by%s shells she sells are seashells, I'm sure.nSo if s%1$sells on%2$sn I'm sure s%1$sore shells.","he sells seash"," the seashore,nThe")
Port of @IgbyLargeman's C# answer, so make sure to upvote him as well!
-9 bytes thanks to @branboyer.
(Simply returning as is would be 174 bytes.)
Explanation:
v-> // Method with empty unused parameter and String return-type
"".format( // Return the following formatted string:
"S%sells by%s
shells she sells are seashells, I'm sure.n
So if s%1$sells on%2$s
n I'm sure s%1$sore shells.",
"he sells seash",
// Where the first `%s` and all `%1$s` are replaced with "he sells seash"
" the seashore,nThe")
// and the second `%s` and all `%2$s` are replaced with " the seashore,n
The"
Answered by Kevin Cruijssen on October 27, 2021
Write(@"S{0}sea{1} by the {2},
The {1} s{0}are sea{1}, I'm sure.
So if s{0}sea{1} on the {2},
Then I'm sure s{0}{2} {1}.","he sells ","shells","seashore")
Answered by Igby Largeman on October 27, 2021
-1 byte thanks to Neil
a/S256 by43h632 are56,1.nSo if3256 on4n1325ore3h6.
m/1/ I'm3ure/2/he36/3/ s/4/ the5ore,nThe/5/ seash/6/ells/g
Port of JavaScript answer.
Answered by PkmnQ on October 27, 2021
-(i){|The shells|So if|Then I'm sure} {S|s}he sells {|are |}sea{|||shore }shells{& {on|by} the seashore,|{, I'm sure.|.->END}}
->i
// Thanks to all the new whitespace, this ungolfed code doesn't quite work as is
-(i) // A label
{|The shells|So if|Then I'm sure} // A sequence - the first time we get here we print nothing,
// the second time we print "The shells",
// the third time we print "So if", etc
{S|s} // Sequences keep outputting their last value once it's been reached
he sells // Plain text just gets printed
{|are |}
sea{|||shore }shells
{& {on|by} the seashore,|{, I'm sure.|.->END}}
// {& marks a repeating sequence.
// Instead of getting stuck on its last value, this it starts over.
// On the fourth pass we hit ->END and terminate the program
->i // On the other passes, we get here and go back to the start
Answered by Sara J on October 27, 2021
Saved 1 byte thanks to @Neil
_=>`246 / I'm5ure/he56/ the4ore,
The/5eash/ s/ells`.split`/`.reduce((s,p,i)=>s.split(i).join(p),`S0by35h652 are46,1.
So if50on3n1524ore5h6.`)
"ells" -> "6" (9 occurences, saved: 22 bytes)
She s6 seash6 by the seashore,
The sh6 she s6 are seash6, I'm sure.
So if she s6 seash6 on the seashore,
Then I'm sure she s6 seashore sh6.
" s" -> "5" (17 occurences, saved: 14 bytes)
She565eash6 by the5eashore,
The5h65he56 are5eash6, I'm5ure.
So if5he565eash6 on the5eashore,
Then I'm5ure5he565eashore5h6.
"5eash" -> "4" (6 occurences, saved: 18 bytes)
She5646 by the4ore,
The5h65he56 are46, I'm5ure.
So if5he5646 on the4ore,
Then I'm5ure5he564ore5h6.
" the4ore,nThe" -> "3" (2 occurences, saved: 10 bytes)
She5646 by35h65he56 are46, I'm5ure.
So if5he5646 on3n I'm5ure5he564ore5h6.
"he56" -> "2" (4 occurences, saved: 7 bytes)
S246 by35h652 are46, I'm5ure.
So if5246 on3n I'm5ure524ore5h6.
" I'm5ure" -> "1" (2 occurences, saved: 5 bytes)
S246 by35h652 are46,1.
So if5246 on3n1524ore5h6.
"246 " -> "0" (2 occurences, saved: 1 byte)
S0by35h652 are46,1.
So if50on3n1524ore5h6.
Answered by Arnauld on October 27, 2021
(prin(text"S@1 @2 by the @3,
The @5 s@1 are @2,@4.
So if s@1 @2 on the @3,
Then@4 s@1 @3 @5.""he sells"'seashells'seashore" I'm sure"'shells]
Using the template:
S1 by the 2,
The 5 s1 are 2,4.
So if s1 on the 3,
Then4 s1 3 5.
Where 1 is "he sells"
, 2 is "seashells"
, 3 is "seashore"
, and 4 is " I'm sure"
{ 14 imaginary interweb points for guessing which syntax highlighting I'm using without peeking }
(format t"S~a~a by the ~a,~%The shells s~3:*~Aare ~a, I'm sure.~%So if s~3:*~A~a on the ~a,~%Then I'm sure s~3:*~a~*~a shells.""he sells ""seashells""seashore")
Answered by Wezl programs redwolf on October 27, 2021
print"She sells seashells by the seashore,nThe shells she sells are seashells, I'm sure.nSo if she sells seashells on the seashore,nThen I'm sure she sells seashore shells."
Trivial algorithm, but nobody’s done it yet. I’m working on a better answer in a different language, but I don’t know if it should be posted in another answer or in this one. Shortening advice accepted, but I’m perfectly fine with just hard-coding it for now.
Answered by Bardic Wizard on October 27, 2021
ÇσGª☺Uë╠╤↑╡V╦⌐∞┐ü9B@♦1ÖFò╫◄«vâ¬♂ƒQn→↨¥p▬♂♥å↓hb½Z╫Éà½♣µ╩N>.▄┌bæ¼@3▲¡w8╣▐ù☼ve/h{≈ï░
Unpacked:
`...`'!/|J
`...` - compressed string "She sells..." with '!' where newlines should be
'! - a '!' character
/ - split the compressed string at '!' characters
|J - join with newline characters
Maybe making a manual compression using the words will be shorter?
Answered by Jonathan Allan on October 27, 2021
Saved a whopping 13 18 bytes thanks to ovs!!!
Saved 4 bytes thanks to user253751!!!
Saved a byte thanks to branboyer!!!
Saved 7 bytes thanks to dingledooper!!!
Note: There's lots of unprintables in the following code so please avert your eyes if you're sensitive to such things! :D
print("Sh by are,.nSo if onnore.".translate("| seash|ells|ore,nThe| sh|e s| I'm sure| the".split("|")))
Answered by Noodle9 on October 27, 2021
“SheÌç1€‹€€0,
The¬•s‚ÎÌ瀙1,2.
So€¬‚ÎÌç1€‰€€0,
Then2‚ÎÌç0¬•s.“2Ý…½š¬•s#'í™ì“I'mˆ•“ª1ú:
Explanation:
“SheÌç1€‹€€0,
The¬•s‚ÎÌ瀙1,2.
So€¬‚ÎÌç1€‰€€0,
Then2‚ÎÌç0¬•s.“ # Push dictionary string "She sells1 by the0,
# The shells she sells are1,2.
# So if she sells1 on the0,
# Then2 she sells0 shells."
2Ý # Push list [0,1,2]
…½š¬•s # Push dictionary string "shore shells"
# # Split it on spaces: ["shore","shells"]
'í™ì '# Prepend dictionary string "sea" in front of both:
# ["seashore","seashells"]
“I'mˆ•“ª '# Append dictionary string "I'm sure" to this list:
# ["seashore","seashells","I'm sure"]
1ú # Pad each string with a leading space:
# [" seashore"," seashells"," I'm sure"]
: # Replace all [0,1,2] with [" seashore"," seashells"," I'm sure"]
# (after which the result is output implicitly)
See this 05AB1E tips of mine (section How to use the dictionary?) to understand how the dictionary strings work.
Answered by Kevin Cruijssen on October 27, 2021
`S230 by41h012 e30,d.
So if1230 4123e1h0.`dd` I'm1¨e`4` e3e,
T`3`1Á`2`10`1" s"0`e¥s
Port of the retina answer to Japt.
S230 by41h012 e30,d.
So if1230 4123e1h0.
Decompress into the string literal:
S230 by41h012 are30,d.
So if1230 on4nd123ore1h0.
Then we do replacements with:
d
d` I'm1¨e` // "d" with " I'm1ure"
4` e3e,nT` // "4" with " the3ore,nThe"
3`1Á` // "3" with "1eash"
2`10` // "2" with "he10"
1" s" // "1" with " s"
0`e¥s // "0" with "ells"
Answered by Mukundan314 on October 27, 2021
string a=" she sells ",b="shells",c="seashore",d=a+"sea"+b;Write(@$"She{d[4..]} by the {c},
The {b}{a}are sea{b}, I'm sure.
So if{d} on the {c},
Then I'm sure{a}{c} {b}.")
The @
allows for line breaks inside string literals.
Answered by Netråm on October 27, 2021
S230 by41h012 are30,5.¶So if1230 on4n5123ore1h0.
5
I'm1ure
4
the3ore,¶The
3
1eash
2
he10
1
s
0
ells
Try it online! Explanation: In Retina, a substitution only makes sense if it's long enough l
for the number n
of repetitions. The substitution saves n(l-1)
bytes in the compressed text but costs l+3
bytes in the replacement stages. This gives the minimum length required to be useful as follows:
Edit: As @Arnauld pointed out, you can count repetitions from the substitution entries as well. This means that although there were only 5 repetitions of space+s in my previous encoded text, there are also 3 repetitions in the substitutions, thus allowing me to save 3 bytes overall. (@Arnauld himself had only spotted 2 of the 3 repetitions.)
Answered by Neil on October 27, 2021
Port of Neil's answer + accepting nph's suggestion.
/3/ I'm4ure//2/4eash//1/he40//0/ells//4/ s/S120 by the2ore,
The4h041 are20,3.
So if4120 on the2ore,
Then3412ore4h0.
Answered by user92069 on October 27, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP