99 Bottles of Beer/Scala: Difference between revisions
m
Fixed syntax highlighting.
m (Fixed syntax highlighting.) |
|||
(One intermediate revision by one other user not shown) | |||
Line 1:
{{collection|99 Bottles of Beer}}
<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:
<
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")
}</
===Running in parallel===
The above n parallel using a ParRange, fast but shuffles the output.
<
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")
}</
===Regex solution===
<
val verse = """|99 bottles of beer on the wall
|99 bottles of beer
Line 41 ⟶ 43:
changeLine(line)
}
}</
===A preferred ☺
<
object Song {
import scala.actors._
Line 136 ⟶ 139:
Patrons ! SingSong(Beer)
}
}</
|