Skip to content

Instantly share code, notes, and snippets.

@ToJans
Last active August 29, 2015 14:14
Show Gist options
  • Save ToJans/5e232437c4c64f8c5a25 to your computer and use it in GitHub Desktop.
Save ToJans/5e232437c4c64f8c5a25 to your computer and use it in GitHub Desktop.
99 bottles of beer as short as possible in ECMAScript 6 - currently 142 characters
x=""
b=r=>`${c||"No more"} bottle${c-1?"s":""} of beer${r&&c--||" on the wall"}
`
for(c=99;c;)x+=b()+b(1)+`Take one down, pass it around
`+b()
@ToJans
Copy link
Author

ToJans commented Feb 2, 2015

Tested in an ES6 VM over at http://benvie.github.io/continuum/

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

No need for var?

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

Indeed! Good remark! down to 167!

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

q=" of beer",o=q+" on the wall",b=c=>`${c?c:"No more"} bottle${c-1?"s":""}`
for(i=99;i>0;){x+=`${b(i)+o}
${b(i)+q}
Take one down, pass it around
${b(--i)+o}`}
x

Down to 155.

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

And down to 164... maybe I might be able to fit it in a tweet? 😃

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

Hmm, one small mistake.

q=" of beer",o=q+" on the wall",b=c=>`${c?c:"No more"} bottle${c-1?"s":""}`,x=''
for(i=99;i>0;)x+=`${b(i)+o}
${b(i)+q}
Take one down, pass it around
${b(--i)+o}
`
x

EDIT: fixed it here, no overall gain.

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

it doesn't seem to work when I try in http://benvie.github.io/continuum/ ?

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

If fixed my version, but it's not better then yours with the mistakes fixed. I think a different approach is needed to shave more of...

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

160 chars

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

159:

b=(c,r)=>`${c||"No more"} bottle${c-1?"s":""} of beer${r?"":" on the wall"}`,v=c=>!c||`${b(c)}
${b(c,1)}
Take one down, pass it around
${b(--c)}
${v(c)}`
v(99)

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

154:

x=""
for(c=99;c;){
b=r=>`${c||"No more"} bottle${c-1?"s":""} of beer${r?c--||"":" on the wall"}`
x+=b()+`
${b(c)}
Take one down, pass it around
${b()}
`}x

@abdullin
Copy link

abdullin commented Feb 3, 2015

Do you even need to declare x=""?

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

@abdullin yeah, ReferenceError

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

152:

b=r=>`${c||"No more"} bottle${c-1?"s":""} of beer${r?c--||"":" on the wall"}`,x=""
for(c=99;c;)x+=b()+`
${b(1)}
Take one down, pass it around
${b()}
`
x

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

150 (don't need the x at the end to print)

b=r=>`${c||"No more"} bottle${c-1?"s":""} of beer${r?c--||"":" on the wall"}`,x=""
for(c=99;c;)x+=b()+`
${b(1)}
Take one down, pass it around
${b()}
`

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

148 (forgot an easy one)

b=r=>`${c|"No more"} bottle${c-1?"s":""} of beer${r?c--|"":" on the wall"}`,x=""
for(c=99;c;)x+=b()+`
${b(1)}
Take one down, pass it around
${b()}
`

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

147 - almost tweetable!

x=""
for(c=99;c;)
b=r=>`${c||"No more"} bottle${c-1?"s":""} of beer${r?c--||"":" on the wall"}
`,x+=b()+b(1)+`Take one down, pass it around
`+b()
x

@tcoopman
Copy link

tcoopman commented Feb 3, 2015

@ToJans don't forget to change || by |

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

142 chars!

x=""
b=r=>`${c|"No more"} bottle${c-1?"s":""} of beer${r?c--|"":" on the wall"}
`
for(c=99;c;)x+=b()+b(1)+`Take one down, pass it around
`+b()

@ToJans
Copy link
Author

ToJans commented Feb 3, 2015

You can't change || by |, or the last sentence is wrong; so back to 143 chars...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment