Skip to content

Instantly share code, notes, and snippets.

View algorythmist's full-sized avatar

Dimitri Papaioannou algorythmist

View GitHub Profile
@algorythmist
algorythmist / Song.kt
Created February 5, 2020 17:41
Kotlin song
class Song(val filepath : String) {
var title: String? = null
var artist: String? = null
var genre: String? = null
var album: String? = null
var year: Int? = null
var duration: Double = 0.toDouble()
var mediaInfo = MediaInfo()
var lastModified: LocalDateTime? = null
var rating : Double? = null
@algorythmist
algorythmist / duplicates.kt
Created February 5, 2020 17:54
Find duplicates in Kotlin
data class EquivalenceClass(val size : Long, val title : String?)
fun findDuplicates(songs : List<Song>): Map<EquivalenceClass, List<Song>> {
return songs.groupBy { EquivalenceClass(it.mediaInfo.size, it.title) }
.filter { it.value.size > 1 }
}
Weapon Type Stats
Rebel SMG 6/6/9/3/7
87 SHOTGUN 2/10/1/5/6
Autocross BOW 6/6/6/6/6
Sixer REVOLVER 5/4/3/2/5
Mark IV REVOLVER 4/3/2/2/4
BigDecimal percentRate = (currentAmount.divide(previousAmount, RoundingMode.HALF_EVEN)
.subtract(BigDecimal.ONE))
.multiply(BigDecimal.valueOf(100));
val percentRate = (currentAmount/ previousAmount - 1)*100
class Complex(val real: Double, val img: Double) {
constructor(real: Number, img: Number) : this(real.toDouble(), img.toDouble())
operator fun unaryMinus() = Complex(-real, -img)
operator fun plus(c: Complex) = Complex(real + c.real, img + c.img)
operator fun plus(n: Number) = Complex(real + n.toDouble(), img)
val c1 = Complex(2.0, -3.1)
val c2 = Complex(-1.0, -2)
val c3 = Complex(4.5, 1.2)
val c4 = ((c1 + c2)*c2)/c4
/**
* Complex 0 = 0 + 0i
*/
val ZERO = Complex(0.0, 0.0)
/**
* Complex 1 = 1 + 0i
*/
val ONE = Complex(1.0, 0.0)
/**
* Complex unit = 0 + i
infix fun to(exponent: Int): Complex {
if (exponent == 0) {
return Complex(1.0, 0.0)
}
if (exponent == 1) {
return this
}
val half = to(exponent / 2)
return if (isEven(exponent)) {
half * half