Skip to content

Instantly share code, notes, and snippets.

View gzoritchak's full-sized avatar

Gaetan Zoritchak gzoritchak

View GitHub Profile
@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)
}
@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 / 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
}
package org.gzk.marslander
data class Time(val sec:Double)
val Double.sec: Time
get() = Time(this)
/**
* Speed is internally using a vector, allowing to compose it. speed12 = speed1 + speed2
*/
package org.gzk.marslander
import java.lang.Math.*
/**
* A point in a 2 dimensions cartesian system.
* Point + Vector -> Point
* Point - Point -> Vector
*/
data class Point(val x:Double, val y: Double) {
package org.gzk.marslander
import java.lang.Math.random
val log = true
val elitism = true
val generationsCount = 10
val populationSize = 20
val genomeSize = 1200
package org.gzk.marslander
import java.io.StringReader
import java.util.*
fun main(args: Array<String>) {
val bestChimp = findBestChimp(::createMarsLander1FromGenome, ::marsLander1Fitness)
println(
bestChimp.result.trajectory.drop(1).joinToString (transform = { state -> "${state.angle}, ${state.power}" })
)
@gzoritchak
gzoritchak / Lander.kt
Last active June 8, 2016 14:14
A Genetic Algorithm implementation of CodingGame MarsLander1 puzzle.
package org.gzk.marslander
val GRAVITY = acceleration(0.0, -3.711)
val maxX = 6999
val minX = 0
/**
* power : 0, 1, 2, 3, 4
* angle : -90, -75, ... , 0, +15, +30, ..., +75, +90
*/
// runs the code in the background thread pool
fun asyncOverlay() = async(CommonPool) {
// start two async operations
val original = asyncLoadImage("original")
val overlay = asyncLoadImage("overlay")
// and then apply overlay to both results
applyOverlay(original.await(), overlay.await())
}
// launches new coroutine in UI context
package jug.dsl
val kotlinSurveyDef = createNewSurveyDef("Évaluation du kotlin user group") {
introduction = "Merci de prendre 20 secondes pour répondre à quelques questions."
val appreciation = intQuestion("Quelle est votre appréciation de la dernière session ?"){
min = 1
max = 5
}