99 Bottles of Beer/Scala: Difference between revisions

Previous version failed with line spacing
(ParRange)
(Previous version failed with line spacing)
Line 2:
The trivial solution to it would be this:
 
<lang scala>99 to 1 by -1 foreach { n =>
println("""|%d bottles of beer on the wall
|f"$n%d bottles of beer on the wall\n" +
f"$n%d bottles of beer\n" +
|f"Take one down, pass it around\n" +
f"${n - |1}%d bottles of beer on the wall\n""".stripMargin format (n, n, n -1))}</lang>
}</lang>
 
The above running in paralellparallel using a ParRange, fast but shuffles the output.
 
<lang scala>(99 to 1 by -1).par foreach { n =>
println("""|%d bottles of beer on the wall
|f"$n%d bottles of beer on the wall\n" +
f"$n%d bottles of beer\n" +
|f"Take one down, pass it around\n" +
f"${n - |1}%d bottles of beer on the wall\n""".stripMargin format (n, n, n -1))}</lang>
}</lang>
 
A Regex solution:
Anonymous user