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"oiOm9d=6FeOV`6Ib\#ETWdjr<\A6XX8m+DNOB!%e&\J)")).decode('ansi').split('@'):z=x.split('$');printprint(*(y+'\n'+yy+n+y for y in zx.split(n)),'',*zx,'',sep='\n'sep=n)
edit
- Changed from base64 to base85
- removed some unnecessary escapes in the compressed string
- removed the
ansi
argument from thedecode()
- changed from
$
between verses to\n
(from @alexis' answer)
So this has become a hybrid of my orignal submission, @uriel's and @alexis's
begin_s = """The other day,','I met a bear,','A great big bear,','Oh way out there.'],['He looked at me,','I looked at him,','He sized up me,','I sized up him.'],['He said to me,','"Why don\'t you run?',"I see you ain't,",'Got any gun."'],['I says to him,','"That\'s a good idea."','"Now legs get going,','get me out of here!"'],['And so I ran,','Away from there,','But right behind me,','Was that bear.'],['In front of me,','There was a tree,','A great big tree,','Oh glory be!'],['The lowest branch,','Was ten feet up,',"So I thought I'd jump,",'And trust my luck.'],['And so I jumped,','Into the air,','But I missed that branch,','A way up there.'],["Now don't you fret,","And don't you frown,",'I Caught that branch,','On the way back down!'],['This is the end,','There aint no more,','Unless I see,','That bear once more."""
new_line = '\n'
new_s = begin_s.replace("','","$"new_line).replace('","',"$"new_line).replace("',\"","$"new_line).replace("\",'","$"new_line).replace("'],['",'@').replace("\"],['",'@').replace("'],[\"",'@').encode('ansi')
gives
b'The other day,$I met a bear,$A great big bear,$Oh way out there.@He looked at me,$I looked at him,$He sized up me,$I sized up him.@He said to me,$"Why don\'t you run?$I see you ain\'t,$Got any gun."@I says to him,$"That\'s a good idea."$"Now legs get going,$get me out of here!"@And so I ran,$Away from there,$But right behind me,$Was that bear.@In front of me,$There was a tree,$A great big tree,$Oh glory be!@The lowest branch,$Was ten feet up,$So I thought I\'d jump,$And trust my luck.@And so I jumped,$Into the air,$But I missed that branch,$A way up there.@Now don\'t you fret,$And don\'t you frown,$I Caught that branch,$On the way back down!@This is the end,$There aint no more,$Unless I see,$That bear once more.'
then compress this with zlib
bcomp_s = base64.b64encodea85encode(zlib.compress(new_s, level=9.encode())).decode()
Afterwards checked which characters needed escaping. There were 4"
and 6 '
in the string so I used a "
string.
base64 vs base85
Base64 gives these lengths
Base85
original 715
lzma 500 625
zlib 400 500
bz2 436 545
lists the len
of the resulting bytes
after compression and then after conversion to base64
answer's length
I find 2 conflicting lengths
when I do len
on a string of this code in python, I get 698, but notepad++ says 708 (+1 newline)
confusion solved thanks to @jonathan-allan