Skip to main content
deleted 250 characters in body
Source Link

Python3.6, 707 bytes707 648bytes

import zlib,base64 as b
n='\n'
for x in zlib.decompress(bbase64.b64decodea85decode(b'eNpVUsuO2zAM"Gaqc3]9:o&%.*X%3&PS1qM!!^OgrLJETV#iKLs/BWuYSAXw79Qpz20uXQPTbFnJWIkNba40AOB+rEPohAPcrDb;W:q/Udym7TvVnkkJyHz55JiudE1qxD\nf6KFCxm6sElDfySX2BS6BLdXXj09zEpSC+kQj9M3plnkzpYAXFhXPN8+LEMPRA6!XiBX3dW2&SeG85%c)sW/UajvO+DfEnF1_-4Sdn>[gXq'&6f=p%0pg8M-`*4AOe$As#/22\nIZtgqUhrd29+JSvxUGiVSqnGTzrC3J4moDH0XwUs40quxrGb0DZr1gXtYHf2phwyZDgRS8GyGbu+\n+y4PmtllcpDoJEQ39Pq5cNMjN1JFL910jJay0ImSiTBBBd+SLJviof8McArOwxf2AVhlZ!cVRRnU15<$lom>r'mBomsom`o\\5+:Ju'Znh7rcNXMdK\"<@Xg`5NrGpH^]K)d!ZY5N%;FWa*pA0XB?@HKDjJmEla@$6nAMbB'd/WZw36tX\n8GmcTlFHYtuq7bOOwjolVRLzR2+3Crx1s6QVK14mDMDHB2cgQOPq9xOMxQzS9X3ofyjH4qUql9PB\n0q+6oKz0S6qYXFaa6/U+PhUpgi0yiDALeuBn2hQh+ZAzYtlU7DePLW4ktaetHj6zuSUu273]0'b=QcVOfP7ZQsl0#oXO5*8@^%Bc.>09/aZ8g_CX'mrZ[Cl4#91VbG!%q!ro@$UDS_0rLn_5D9673.5%X1$>8$L<pU8^&9ih(%pFc&u,/KI\nGvIX03h9WPca21HdeTHXO8YeUbWGTCG3Fkf71y1EXSjipxB1GaU5c+!7#(!0+&::G<P?8D!U0qk5!fQ`=:c#>;hsK!NfXWFBmNBs-(bpf+$p[`BT./WecOWdqf4IidqtJ4pUbZPwDdrft\noQ==\n'EhYWBiB]G6dCL!;mG4B[^_ILT!it?biY5$D\"mq4aWkQA?VKMQ@GP^87s4\"6>jiMV7+E22L\"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 the decode()
  • 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

Python3.6, 707 bytes

import zlib,base64 as b
for x in zlib.decompress(b.b64decode(b'eNpVUsuO2zAM/BWuYSAXw79Qpz20uXQPTbFnJWIkNba40AOB+/Udym7TvVnkkJyHz55JiudE1qxD\nf6KFCxm6sElDfySX2BS6BLdXXj09zEpSC+kQj9M3plnkzpYAXFhXPN8+LEMPRA6/UajvO+DfE/22\nIZtgqUhrd29+JSvxUGiVSqnGTzrC3J4moDH0XwUs40quxrGb0DZr1gXtYHf2phwyZDgRS8GyGbu+\n+y4PmtllcpDoJEQ39Pq5cNMjN1JFL910jJay0ImSiTBBBd+SLJviof8McArOwxf2AVhl/WZw36tX\n8GmcTlFHYtuq7bOOwjolVRLzR2+3Crx1s6QVK14mDMDHB2cgQOPq9xOMxQzS9X3ofyjH4qUql9PB\n0q+6oKz0S6qYXFaa6/U+PhUpgi0yiDALeuBn2hQh+ZAzYtlU7DePLW4ktaetHj6zuSUu273/a/KI\nGvIX03h9WPca21HdeTHXO8YeUbWGTCG3Fkf71y1EXSjipxB1/WecOWdqf4IidqtJ4pUbZPwDdrft\noQ==\n')).decode('ansi').split('@'):z=x.split('$');print(*(y+'\n'+y for y in z),'',*z,'',sep='\n')
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_s = begin_s.replace("','","$").replace('","',"$").replace("',\"","$").replace("\",'","$").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

b.b64encode(zlib.compress(new_s, level=9))

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

Python3.6, 707 648bytes

import zlib,base64
n='\n'
for x in zlib.decompress(base64.a85decode("Gaqc3]9:o&%.*X%3&PS1qM!!^OgrLJETV#iKLs/rEPohAPcrDb;W:q/!XiBX3dW2&SeG85%c)sW/nF1_-4Sdn>[gXq'&6f=p%0pg8M-`*4AOe$As#/Z!cVRRnU15<$lom>r'mBomsom`o\\5+:Ju'Znh7rcNXMdK\"<@Xg`5NrGpH^]K)d!ZY5N%;FWa*pA0XB?@HKDjJmEla@$6nAMbB'd//]0'b=QcVOfP7ZQsl0#oXO5*8@^%Bc.>09/Z8g_CX'mrZ[Cl4#91VbG!%q!ro@$UDS_0rLn_5D9673.5%X1$>8$L<pU8^&9ih(%pFc&u,/GaU5c+!7#(!0+&::G<P?8D!U0qk5!fQ`=:c#>;hsK!NfXWFBmNBs-(bpf+$p[`BT./EhYWBiB]G6dCL!;mG4B[^_ILT!it?biY5$D\"mq4aWkQA?VKMQ@GP^87s4\"6>jiMV7+E22L\"oiOm9d=6FeOV`6Ib\#ETWdjr<\A6XX8m+DNOB!%e&\J)")).decode().split('@'):print(*(y+n+y for y in x.split(n)),'',x,'',sep=n)

edit

  • Changed from base64 to base85
  • removed some unnecessary escapes in the compressed string
  • removed the ansi argument from the decode()
  • 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("'],[\"",'@')

then compress this with zlib

comp_s = base64.a85encode(zlib.compress(new_s.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

corrected length
Source Link

Python3.6, 709707 bytes

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

Python3.6, 709 bytes

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)

Python3.6, 707 bytes

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

Source Link

Python3.6, 709 bytes

First attempt at code-golf, adopting @uriel's answer to include compression of the string

import zlib,base64 as b
for x in zlib.decompress(b.b64decode(b'eNpVUsuO2zAM/BWuYSAXw79Qpz20uXQPTbFnJWIkNba40AOB+/Udym7TvVnkkJyHz55JiudE1qxD\nf6KFCxm6sElDfySX2BS6BLdXXj09zEpSC+kQj9M3plnkzpYAXFhXPN8+LEMPRA6/UajvO+DfE/22\nIZtgqUhrd29+JSvxUGiVSqnGTzrC3J4moDH0XwUs40quxrGb0DZr1gXtYHf2phwyZDgRS8GyGbu+\n+y4PmtllcpDoJEQ39Pq5cNMjN1JFL910jJay0ImSiTBBBd+SLJviof8McArOwxf2AVhl/WZw36tX\n8GmcTlFHYtuq7bOOwjolVRLzR2+3Crx1s6QVK14mDMDHB2cgQOPq9xOMxQzS9X3ofyjH4qUql9PB\n0q+6oKz0S6qYXFaa6/U+PhUpgi0yiDALeuBn2hQh+ZAzYtlU7DePLW4ktaetHj6zuSUu273/a/KI\nGvIX03h9WPca21HdeTHXO8YeUbWGTCG3Fkf71y1EXSjipxB1/WecOWdqf4IidqtJ4pUbZPwDdrft\noQ==\n')).decode('ansi').split('@'):z=x.split('$');print(*(y+'\n'+y for y in z),'',*z,'',sep='\n')

Compression

make one big bytes, seperating lines in a verse by $ and verses by @

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_s = begin_s.replace("','","$").replace('","',"$").replace("',\"","$").replace("\",'","$").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

b.b64encode(zlib.compress(new_s, level=9))

I tried other algorithms, but this seemed smallest

original 715
lzma     500 677
zlib     400 544
bz2      436 592

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)