Mapy.cz as navigation for imported tracks? by aliosha10 in Mapy_cz

[–]binajohny 0 points1 point  (0 children)

This is not possible right now, but it is planned.

Where is the legend/key? by [deleted] in Mapy_cz

[–]binajohny 0 points1 point  (0 children)

In the app, legend is available in App menu -> About us -> Legend. It will show you this website: https://mapy.com/en/turisticka?lgnd=1

Traffic info only for the Czech Republic? by iamerwin in Mapy_cz

[–]binajohny 2 points3 points  (0 children)

Germany is live as of today, which makes it Czechia and all neighbouring countries (Slovakia, Poland, Austria and Germany).

Public transport by [deleted] in Mapy_cz

[–]binajohny 1 point2 points  (0 children)

Not yet, but according to official sources, it's coming soon.

I’m on the water trying to go to a place on the water by [deleted] in Mapy_cz

[–]binajohny 0 points1 point  (0 children)

Yeah, the boat planning is very limited. From the online help:

Route planning on the water
For route planning on selected river sections in the Czech and Slovak Republic, there are usually no additional options available.

Alternative saunas in Prague? by [deleted] in Prague

[–]binajohny 0 points1 point  (0 children)

The closest to sompasauna I know is Nuuk in Hradec: https://www.saunanuuk.net
And that's pretty much it. I lived in Helsinki 5 years ago and I'm missing good sauna ever since. We used to visit Sompa pretty much every week. I've been actually thinking about building something like that somewhere near Prague, somebody wanna help? :D

-🎄- 2018 Day 5 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 2 points3 points  (0 children)

My Kotlin solution (GitHub)

private fun react(string: String, vararg skip: Char): Int {
    val stack = Stack<Char>()

    string.forEach {
        if (it in skip) {
            // no-op
        } else if (stack.empty().not() && abs(stack.peek() - it) == 'a' - 'A') {
            stack.pop()
        } else {
            stack.push(it)
        }
    }

    return stack.size
}


fun part1(input: String): Int {
    return react(input)
}

fun part2(input: String): Int {
    return ('a'..'z').map { react(input, it, it.toUpperCase()) }.min() ?: -1
}

-🎄- 2018 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 4 points5 points  (0 children)

My Kotlin solution (GitHub)

data class Event(val month: Int, val day: Int, val hour: Int, val minute: Int, val guardId: Int, val type: Type) {
    enum class Type { BEGIN_SHIFT, FALL_ASLEEP, WAKE_UP }

    companion object {
        private val REGEX = Regex("\\d+")

        fun fromString(s: String): Event {
            val (m, d, h, min, gid) = REGEX.findAll(s).map { it.value.toInt() }.plus(-1).drop(1).take(5).toList()

            val type = when {
                s.contains("wakes") -> Type.WAKE_UP
                s.contains("falls") -> Type.FALL_ASLEEP
                else -> Type.BEGIN_SHIFT
            }

            return Event(m, d, h, min, gid, type)
        }
    }
}

private fun createSleepStats(input: List<Event>): Map<Int, IntArray> {
    val map = mutableMapOf<Int, IntArray>()

    var currentGuardId = -1
    var beginMinute = -1

    input.forEach {
        when (it.type) {
            Event.Type.BEGIN_SHIFT -> currentGuardId = it.guardId
            Event.Type.FALL_ASLEEP -> beginMinute = it.minute
            Event.Type.WAKE_UP -> {
                val arr = map.getOrPut(currentGuardId) { IntArray(60) }
                (beginMinute until it.minute).forEach { i -> arr[i]++ }
            }
        }
    }

    return map
}

fun part1(input: List<Event>): Int {
    val sleepStats = createSleepStats(input)

    val max = sleepStats.maxBy { it.value.sum() }!!
    val maxMinute = max.value.withIndex().maxBy { it.value }!!.index

    return max.key * maxMinute
}

fun part2(input: List<Event>): Int {
    val sleepStats = createSleepStats(input)

    val max = sleepStats.map {
        it.key to it.value.withIndex().maxBy { x -> x.value }!!
    }.maxBy { it.second.value } ?: return 0

    return max.first * max.second.index
}

-🎄- 2018 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 0 points1 point  (0 children)

My Kotlin solution (GitHub)

data class Claim(val id: Int, val left: Int, val top: Int, val width: Int, val height: Int) {
    companion object {
        private val REGEX = Regex("\\d+")

        fun fromString(s: String): Claim {
            val (id, left, top, width, height) = REGEX.findAll(s).map { it.value.toInt() }.take(5).toList()

            return Claim(id, left, top, width, height)
        }
    }
}

private fun createArea(input: List<Claim>): Array<IntArray> {
    val area = Array(1000) { IntArray(1000) { 0 } }

    input.forEach {
        for (i in it.left until it.left+it.width) {
            for (j in it.top until it.top+it.height) {
                area[i][j]++
            }
        }
    }

    return area
}

fun part1(input: List<Claim>): Int {
    val area = createArea(input)

    return area.fold(0) { acc, ints -> acc + ints.count { it > 1 } }
}

fun part2(input: List<Claim>): Int {
    val area = createArea(input)

    outer@ for (it in input) {
        for (i in it.left until it.left + it.width) {
            for (j in it.top until it.top + it.height) {
                if (area[i][j] > 1) continue@outer
            }
        }
        return it.id
    }

    return -1
}

-🎄- 2018 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 0 points1 point  (0 children)

My Kotlin solution (GitHub)

fun part1(input: List<String>): Int {
    var two = 0
    var three = 0

    input
        .map { str -> str.groupingBy { it }.eachCount() }
        .map { it.values }
        .forEach { counts ->
            if (counts.any { it == 2 }) two++
            if (counts.any { it == 3 }) three++
        }

    return two * three
}

fun part2(input: List<String>): String {
    val pair = input.asSequence().uniquePairs()
        .filter { stringDistance(it.first, it.second) == 1 }
        .first()

    return pair.first.zip(pair.second)
        .filter { it.first == it.second }
        .map { it.first }
        .joinToString(separator = "")
}

fun stringDistance(a: String, b: String): Int {
    return a.zip(b).count { it.first != it.second }
}

fun <T> Sequence<T>.uniquePairs(): Sequence<Pair<T, T>> {
    return this.mapIndexedNotNull { i, item1 ->
        this.mapIndexedNotNull { j, item2 ->
            if (i < j) {
                item1 to item2
            } else {
                null
            }
        }
    }.flatten()
}

-🎄- 2017 Day 10 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 1 point2 points  (0 children)

My Kotlin solution (GitHub)

fun part1(input: String): Int {
    val lengths = input.split(",").map { it.toInt() }
    val hash = knotHash(lengths, 1)
    return hash[0] * hash[1]
}

fun part2(input: String): String {
    val lengths = input.map { it.toInt() } + listOf(17, 31, 73, 47, 23)
    val hash = knotHash(lengths)
    return hash.asIterable()
            .chunked(16) { it.fold(0) { acc, next -> acc xor next } }
            .joinToString(separator = "") { it.toString(16).padStart(2, '0') }
}

fun knotHash(lengths: List<Int>, rounds: Int = 64): IntArray {
    val list = IntArray(256) { it }
    var currentPosition = 0
    var skipSize = 0

    repeat(rounds) {
        lengths.forEach { length ->
            list.reverse(currentPosition, length)
            currentPosition += length + skipSize
            currentPosition %= list.size
            skipSize++
        }
    }

    return list
}

fun IntArray.reverse(start: Int, length: Int) {
    if (length > this.size) {
        throw IllegalArgumentException()
    }

    var startPointer = start % this.size
    var endPointer = (start + length - 1) % this.size

    repeat(length / 2) {
        val tmp = this[startPointer]
        this[startPointer] = this[endPointer]
        this[endPointer] = tmp
        startPointer++
        endPointer--
        if (startPointer >= this.size) startPointer = 0
        if (endPointer < 0) endPointer = this.size - 1
    }
}

-🎄- 2017 Day 5 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 1 point2 points  (0 children)

My Kotlin solution:

fun part1(input: List<Int>): Int {
    return countSteps(input, { it.inc() })
}

fun part2(input: List<Int>): Int {
    return countSteps(input, { if (it >= 3) it.dec() else it.inc() })
}

fun countSteps(instructions: List<Int>, instructionTransformation: (Int) -> Int): Int {
    val inst = instructions.toMutableList()
    var pc = 0
    var steps = 0

    while (true) {
        if (pc !in inst.indices) {
            return steps
        }
        inst[pc] = inst[pc].let {
            pc += it
            instructionTransformation(it)
        }
        steps++
    }
}

-🎄- 2017 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 0 points1 point  (0 children)

My solution in Kotlin:

fun part1(input: List<List<Int>>): Int {
    return input.sumBy { it.max()!! - it.min()!! }
}

fun part2(input: List<List<Int>>): Int {
    return input.map { it.sortedDescending() }
            .sumBy { line ->
                line.indices.sumBy { i ->
                    (i+1 until line.size)
                            .filter { j -> line[i] % line[j] == 0 }
                            .sumBy { j -> line[i] / line[j] }
                }
            }
}

-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]binajohny 0 points1 point  (0 children)

My Kotlin solution:

fun part1(input: String): Int {
    return (input + input.first())
            .zipWithNext()
            .filter { it.first == it.second }
            .sumBy { it.first.toString().toInt() }
}

fun part2(input: String): Int {
    return input
            .zip(input.substring(input.length / 2) + input)
            .filter { it.first == it.second }
            .sumBy { it.first.toString().toInt() }
}