99 Bottles of Beer/Scala: Difference between revisions

m
Fixed syntax highlighting.
m (Avoid miscounting task entries twice)
m (Fixed syntax highlighting.)
 
Line 2:
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[Scala]]</span><hr>
 
===The trivial solution===
The trivial solution to it would be this:
<langsyntaxhighlight lang="scala">99 to 1 by -1 foreach { n =>
println(
f"$n%d bottles of beer on the wall\n" +
Line 10:
f"Take one down, pass it around\n" +
f"${n - 1}%d bottles of beer on the wall\n")
}</langsyntaxhighlight>
 
===Running in parallel===
The above n parallel using a ParRange, fast but shuffles the output.
<langsyntaxhighlight Scalalang="scala">(99 to 1 by -1).par foreach { n =>
println(
f"$n%d bottles of beer on the wall\n" +
Line 19 ⟶ 20:
f"Take one down, pass it around\n" +
f"${n - 1}%d bottles of beer on the wall\n")
}</langsyntaxhighlight>
 
===Regex solution===
<langsyntaxhighlight Scalalang="scala">object NinetyNineBottlesOfBeer {
val verse = """|99 bottles of beer on the wall
|99 bottles of beer
Line 41 ⟶ 43:
changeLine(line)
}
}</langsyntaxhighlight>
 
===A preferred ☺ sollution solution===
<langsyntaxhighlight Scalalang="scala">// Note - As Of Scala 2.11.0 The 'Scala Actors' Library Has Been Deprecated In Favor Of Akka.
object Song {
import scala.actors._
Line 136 ⟶ 139:
Patrons ! SingSong(Beer)
}
}</langsyntaxhighlight>
9,476

edits