Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges 99 Shortened Bottles of Beer

Scala, 242 bytes _=>99 to(1,-1)map{b=>s"${w(b)} on the wall, ${w(b)}. \n${if(b>1)"Take one down and pass it around"else "Go to the store and buy some more"}, ${w((b+97)%99+1)} on the w...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#2: Post edited by user avatar user‭ · 2021-08-05T22:07:33Z (over 3 years ago)
  • # [Scala], 244 bytes
  • <!-- language-all: lang-scala -->
  • _=>{def w(b:Int)=s"$b bottle${if(b>1)"s"else ""} of beer"
  • 99 to(1,-1)map{b=>s"${w(b)} on the wall, ${w(b)}.
  • ${if(b>1)"Take one down and pass it around"else
  • "Go to the store and buy some more"}, ${w((b+97)%99+1)} on the wall."}mkString "
  • "}
  • [Try it online!][TIO-krzgxxan]
  • [Scala]: http://www.scala-lang.org/
  • [TIO-krzgxxan]: https://tio.run/##VY/BasMwEETv/opBpCCRNNSn4oANOYUcemqPhiLF69SNvDKWUjcYf7sr3EDpcYeZ91h/0lbPznzSKeBFNwz6DsSVx77rMCZf2qLeYc835AVeQ9/wGfn8nhdjRTUGaXZHDir3YmVgXAiWVmNTS1OkSnhB1hOEmOBqGKJeJFmG4GS6eUxVq7vR5EWcjpGjYokRPgiDtnaDe7hFyX/EN32hWCNUbmBortBp79EE6N5duVqEiTi4KFlYPrielqK53uBdS2hjIqZfgTTr7Fk9ZNk6/e/fiqm93N8VJZcsprmLV5C1fFIqmeYf "Scala – Try It Online"
  • # [Scala], 242 bytes
  • <!-- language-all: lang-scala -->
  • _=>99 to(1,-1)map{b=>s"${w(b)} on the wall, ${w(b)}.
  • ${if(b>1)"Take one down and pass it around"else
  • "Go to the store and buy some more"}, ${w((b+97)%99+1)} on the wall."}mkString "
  • "
  • def w(b:Int)=s"$b bottle${if(b>1)"s"else ""} of beer"
  • [Try it online!][TIO-krzgz8kr]
  • [Scala]: http://www.scala-lang.org/
  • [TIO-krzgz8kr]: https://tio.run/##VY6xasMwFEV3f8VFpCCRNNRTccCGTCFDp3Y0FCl@Tt3IT8ZS6gbjb3eFGyhdL5dzjj9pq2dnPukU8KIbBn0H4spj33UYky9tUe@w5xvyAq@hb/iMfH7PiyxDcDLdPKaq1d1o8sKL1ThIoyY4RvggDNraDe7jFiWvxqaWpkiVeNMXijdC5QaG5gqd9h5NgO7dlStB1lMiDi5KFpYPrqflaK43eNcS2riI6VcgzTp7Vg9Ztk7/@7diai/3blFyySKpqEZM2h05qDxGGxgXgqW/Or/oIURE1TBEvZi7iAiylk9KJdP8Aw "Scala – Try It Online"
#1: Initial revision by user avatar user‭ · 2021-08-05T22:06:31Z (over 3 years ago)
# [Scala], 244 bytes

<!-- language-all: lang-scala -->

    _=>{def w(b:Int)=s"$b bottle${if(b>1)"s"else ""} of beer"
    99 to(1,-1)map{b=>s"${w(b)} on the wall, ${w(b)}. \n${if(b>1)"Take one down and pass it around"else
    "Go to the store and buy some more"}, ${w((b+97)%99+1)} on the wall."}mkString "\n\n"}

[Try it online!][TIO-krzgxxan]

[Scala]: http://www.scala-lang.org/
[TIO-krzgxxan]: https://tio.run/##VY/BasMwEETv/opBpCCRNNSn4oANOYUcemqPhiLF69SNvDKWUjcYf7sr3EDpcYeZ91h/0lbPznzSKeBFNwz6DsSVx77rMCZf2qLeYc835AVeQ9/wGfn8nhdjRTUGaXZHDir3YmVgXAiWVmNTS1OkSnhB1hOEmOBqGKJeJFmG4GS6eUxVq7vR5EWcjpGjYokRPgiDtnaDe7hFyX/EN32hWCNUbmBortBp79EE6N5duVqEiTi4KFlYPrielqK53uBdS2hjIqZfgTTr7Fk9ZNk6/e/fiqm93N8VJZcsprmLV5C1fFIqmeYf "Scala – Try It Online"