2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,4 +1,4 @@
public fun fizzBuzz() {
fun fizzBuzz() {
for (i in 1..100) {
when {
i % 15 == 0 -> println("FizzBuzz")

View file

@ -0,0 +1,7 @@
fun fizzBuzz() {
fun fizzbuzz(x: Int) = if(x % 15 == 0) "FizzBuzz" else x
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 fizzBuzz() {
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) }
}