Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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)
}
}

View 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)
}

View 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)