Skip to content

Instantly share code, notes, and snippets.

View gzoritchak's full-sized avatar

Gaetan Zoritchak gzoritchak

View GitHub Profile
@gzoritchak
gzoritchak / Josephus.kt
Last active March 7, 2016 19:54
Josephus problem in Kotlin
data class Soldier(val position: Int, var state:State = State.Living) {
fun suicide() {
state = State.Dead
}
fun isAlive() = state == State.Living
}
enum class State {
Living, Dead
}
@gzoritchak
gzoritchak / gist:4739607
Last active April 8, 2018 16:13
Parsing expressions arithmétiques en kotlin.
package codestory2013.gzoritchak
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.Locale
import java.util.StringTokenizer
import kotlin.math.*
@gzoritchak
gzoritchak / gist:4687828
Last active December 12, 2015 00:59
Solution en kotlin au dernier exercice de codestory 2012
package codestory2013.gzoritchak.jajascript
class Flight(val id: String, val startHour: Int, val duration: Int, val price: Int){
val endHour = startHour + duration
}
class Planning(val gain: Int = 0, val flights: List<Flight> = listOf()) {
fun plus(flight: Flight) = Planning(gain + flight.price, flights + flight) //Planning + Flight = Planning
}
@gzoritchak
gzoritchak / codestory 2013 : scalaskel-kotlin
Last active December 11, 2015 23:28
Une solution non optimisée mais j'ai fait le choix de la lisibilité sachant que la valeur max recherchée était de 100.
import codestory2013.gzoritchak.scalaskel.Coin.*
import java.util.*
enum class Coin(val value: Int) {
foo : Coin(1)
bar : Coin(7)
qix : Coin(11)
baz : Coin(21)
}