99 Bottles of Beer/Scala: Difference between revisions

no edit summary
(Previous version failed with line spacing)
No edit summary
Line 1:
{{collection|99 Bottles of Beer}}
[[Category:Scala Implementations]]
The trivial solution to it would be this:
{{libheader|Scala}}
 
==The trivial solution==
The trivial solution to it would be this:
<lang scala>99 to 1 by -1 foreach { n =>
println(
Line 9 ⟶ 12:
f"${n - 1}%d bottles of beer on the wall\n")
}</lang>
===Running in parallel===
 
The above running inn parallel using a ParRange, fast but shuffles the output.
<lang scalaScala>(99 to 1 by -1).par foreach { n =>
 
<lang scala>(99 to 1 by -1).par foreach { n =>
println(
f"$n%d bottles of beer on the wall\n" +
Line 19 ⟶ 21:
f"${n - 1}%d bottles of beer on the wall\n")
}</lang>
A ==Regex solution:==
 
<lang scalaScala>object NinetyNineBottlesOfBeer {
A Regex solution:
 
<lang scala>object NinetyNineBottlesOfBeer {
val verse = """|99 bottles of beer on the wall
|99 bottles of beer
Line 43:
}
}</lang>
==A preferred ☺ sollution ==
 
<lang scalaScala>object Song {
However, I much prefer the following:
 
<lang scala>object Song {
import scala.actors._
import scala.actors.Actor._
Anonymous user