2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,4 +1,4 @@
|
|||
public fun fizzBuzz() {
|
||||
fun fizzBuzz() {
|
||||
for (i in 1..100) {
|
||||
when {
|
||||
i % 15 == 0 -> println("FizzBuzz")
|
||||
7
Task/FizzBuzz/Kotlin/fizzbuzz-2.kotlin
Normal file
7
Task/FizzBuzz/Kotlin/fizzbuzz-2.kotlin
Normal 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) }
|
||||
}
|
||||
11
Task/FizzBuzz/Kotlin/fizzbuzz-3.kotlin
Normal file
11
Task/FizzBuzz/Kotlin/fizzbuzz-3.kotlin
Normal 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) }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue