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,12 @@
fun fizzBuzz() {
for (number in 1..100) {
println(
when {
number % 15 == 0 -> "FizzBuzz"
number % 3 == 0 -> "Fizz"
number % 5 == 0 -> "Buzz"
else -> number
}
)
}
}

View file

@ -0,0 +1,7 @@
fun fizzBuzz1() {
fun fizzBuzz(x: Int) = if (x % 15 == 0) "FizzBuzz" else x.toString()
fun fizz(x: Any) = if (x is Int && x % 3 == 0) "Buzz" else x
fun buzz(x: Any) = if (x is Int && x.toInt() % 5 == 0) "Fizz" else x
(1..100).map { fizzBuzz(it) }.map { fizz(it) }.map { buzz(it) }.forEach { println(it) }
}

View file

@ -0,0 +1,11 @@
fun fizzBuzz2() {
fun fizz(x: Pair<Int, StringBuilder>) = if(x.first % 3 == 0) x.apply { second.append("Fizz") } else x
fun buzz(x: Pair<Int, StringBuilder>) = if(x.first % 5 == 0) x.apply { second.append("Buzz") } else x
fun none(x: Pair<Int, StringBuilder>) = if(x.second.isBlank()) x.second.apply { append(x.first) } else x.second
(1..100).map { Pair(it, StringBuilder()) }
.map { fizz(it) }
.map { buzz(it) }
.map { none(it) }
.forEach { println(it) }
}

View file

@ -0,0 +1,3 @@
fun fizzBuzz() {
(1..100).forEach { println(mapOf(0 to it, it % 3 to "Fizz", it % 5 to "Buzz", it % 15 to "FizzBuzz")[0]) }
}