Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/General-FizzBuzz/Scala/general-fizzbuzz-1.scala
Normal file
14
Task/General-FizzBuzz/Scala/general-fizzbuzz-1.scala
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import scala.io.{Source, StdIn}
|
||||
|
||||
object GeneralFizzBuzz extends App {
|
||||
val max = StdIn.readInt()
|
||||
val factors = Source.stdin.getLines().toSeq
|
||||
.map(_.split(" ", 2))
|
||||
.map(f => f(0).toInt -> f(1))
|
||||
.sorted
|
||||
|
||||
(1 to max).foreach { i =>
|
||||
val words = factors.collect { case (k, v) if i % k == 0 => v }
|
||||
println(if (words.nonEmpty) words.mkString else i)
|
||||
}
|
||||
}
|
||||
18
Task/General-FizzBuzz/Scala/general-fizzbuzz-2.scala
Normal file
18
Task/General-FizzBuzz/Scala/general-fizzbuzz-2.scala
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import scala.io.{Source, StdIn}
|
||||
|
||||
object GeneralFizzBuzz extends App {
|
||||
def fizzBuzzTerm(n: Int, factors: Seq[(Int, String)]): String = {
|
||||
val words = factors.collect { case (k, v) if n % k == 0 => v }
|
||||
if (words.nonEmpty) words.mkString else n.toString
|
||||
}
|
||||
|
||||
def fizzBuzz(factors: Seq[(Int, String)]): LazyList[String] =
|
||||
LazyList.from(1).map(fizzBuzzTerm(_, factors))
|
||||
|
||||
val max = StdIn.readInt()
|
||||
val factors = Source.stdin.getLines().toSeq
|
||||
.map(_.split(" ", 2))
|
||||
.map { case Array(k, v) => k.toInt -> v }
|
||||
.sorted
|
||||
fizzBuzz(factors).take(max).foreach(println)
|
||||
}
|
||||
16
Task/General-FizzBuzz/Scala/general-fizzbuzz-3.scala
Normal file
16
Task/General-FizzBuzz/Scala/general-fizzbuzz-3.scala
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import scala.io.{Source, StdIn}
|
||||
|
||||
def fizzBuzzTerm(n: Int, factors: Seq[(Int, String)]): String | Int =
|
||||
val words = factors.collect { case (k, v) if n % k == 0 => v }
|
||||
if words.nonEmpty then words.mkString else n
|
||||
|
||||
def fizzBuzz(factors: Seq[(Int, String)]): LazyList[String | Int] =
|
||||
LazyList.from(1).map(i => fizzBuzzTerm(i, factors))
|
||||
|
||||
@main def run(): Unit =
|
||||
val max = StdIn.readInt()
|
||||
val factors: Seq[(Int, String)] = Source.stdin.getLines().toSeq
|
||||
.map(_.split(" ", 2))
|
||||
.map { case Array(k, v) => k.toInt -> v }
|
||||
.sorted
|
||||
fizzBuzz(factors).take(max).foreach(println)
|
||||
Loading…
Add table
Add a link
Reference in a new issue