Zorothamya [she/her, he/him]

  • 0 Posts
  • 54 Comments
Joined 4 months ago
cake
Cake day: September 8th, 2024

help-circle





  • Zorothamya [she/her, he/him]toprogrammingAdvent of Code 2024 Day 2
    ·
    edit-2
    19 days ago

    This is my kotlin script for part 2

    import java.io.File
    import kotlin.math.abs
    
    fun safeP(increasing: Boolean, pair: Pair<Int, Int>): Boolean =
        (abs(pair.second - pair.first) in 1..3) && (increasing == pair.second - pair.first > 0)
    
    val lines: List<String> = File("day02-input").readLines().map { it.trim() }.filterNot { it == "" }
    val sequences: List<List<Int>> = lines.map { it.split(" ").map { it.toInt() } }
    
    fun getProgressions(seq: List<Int>) =
        generateSequence(-1) { if (it + 1 != seq.size) it + 1 else null }
            .map { progVariation: Int ->
                seq.filterIndexed { index, _ -> index != progVariation }
                    .let { alternateSeq: List<Int> ->
                        alternateSeq.mapIndexed { i: Int, level: Int ->
                            if (i != alternateSeq.lastIndex) level to alternateSeq[i + 1] else null
                        }
                    }
                    .filterNotNull()
            }
    
    val answer = sequences.count { sequence: List<Int> ->
        getProgressions(sequence).any { prog: List<Pair<Int, Int>> ->
            prog.all { safeP(true, it) } || prog.all { safeP(false, it) }
        }
    }
    
    println(answer)
    

    I'm still only learning kotlin. In my opinion it's pretty shitty code due to the long call chains. I imagine to make it better I should probably break up those chains, assigining the intermediate values to different variables, to make it more readable. Do you agree and is there other stuff that you think ought to be improved?


  • On Nov. 21, just five days before the crash, police chief Bob Hale and his five officers resigned from their post. Hale announced the decision in a Facebook post, and said he left because of “repeated acts of harassment” and “personal attacks” on his character by a town council member.

    Hale added that the council member cut the police’s funding upon assuming his position.

    “This lack of investment hampered our ability to operate at the standard the citizens of the Town of McColl rightfully expect and deserve,” he said in the post.














  • Ostalgie is indeed mostly about surviving or preventing the collapse of the socialist block (and Collapse: A Political Simulator is about the aftermath of the collapse), but in crisis of the kremlin, although very difficult, you can bring forth the collapse of the US. (I still don't really play it, because I find the game difficult to understand and some things seemingly make no sense, that's why I anxiously await the sequel). I still haven't looked at China's: Mao's Legacy (as I think I should study the subject some more before trying it), so I don't know how much you can kick the US in the balls with the DLC.

    But yeah none of those games are grand-strategy wargames.