Skip to content

Instantly share code, notes, and snippets.

View ngsw-taro's full-sized avatar

Taro Nagasawa ngsw-taro

View GitHub Profile
fun main(args : Array<String>) {
for(i in 1..100) {
i.jojo()
}
}
private fun Int.jojo() {
val s = if(this.isPrime()) "JOJO!" else "$this"
println(s)
}
import javafx.application.Application
import javafx.event.ActionEvent
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.stage.Stage
import kotlinfx.*
import java.util.LinkedList
import java.util.List
fun rpn(expression : String) : Double {
val expressionElements = expression.split(' ').toLinkedList()
val result = foldl(rpn, Stack<Double>(), expressionElements)
return result.pop()
}
private fun foldl<T, U>(f : (T, U) -> T, a : T, l : List<U>) : T {
class Foo<out T>() {
var value : T? = null
}
fun main(args : Array<String>) {
val a : Foo<Int> = Foo<Int>()
a.value = 5
val b : Foo<Number> = a
b.value = 2.0
@ngsw-taro
ngsw-taro / gist:2730038
Created May 19, 2012 08:10
Kotlin's Bug?
fun main(args : Array<String>) {
val a = arrayList(1)
val b = a + a // OK
val c = a + arrayList(1) // Compilation error
}
@ngsw-taro
ngsw-taro / gist:2606595
Created May 6, 2012 00:38
Kotlin 関数定義の方法に悩む…
// 拡張関数で定義。
// たぶん一番Kotlinらしい書き方
// kotlin friendly
fun String.isFourCharacters() = this.size == 4
// static関数として定義。
// Javaっぽい書き方?
// like java?
//fun isFourCharacters(str : String) = str.isFourCharacters()
@ngsw-taro
ngsw-taro / gist:1274669
Created October 10, 2011 05:09
FizzBuzz
for(i in 1..100)println(((a=i%3)?"":"Fizz")+(i%5?(a?i:""):"Buzz"))