kari's recent activity

  1. Comment on Day 2: Fulminating Farmland in ~comp.advent_of_code

    kari
    (edited )
    Link
    Both parts in Gleam! Part 1 It doesn't feel super idiomatic maybe? I dunno, functional programming is fun but I think I don't do it enough so I always make unreadable code lol. const ring_size = 6...

    I'm still working on part 2 but figured I'd share my part 1:

    Both parts in Gleam!

    Part 1

    It doesn't feel super idiomatic maybe? I dunno, functional programming is fun but I think I don't do it enough so I always make unreadable code lol.

    const ring_size = 6
    
    /// Given a color in ROYGBV, return its position in the waypoitn loop.
    fn waypoint(color: String) -> Result(Int, Nil) {
      case color {
        "r" -> Ok(0)
        "o" -> Ok(1)
        "y" -> Ok(2)
        "g" -> Ok(3)
        "b" -> Ok(4)
        "v" -> Ok(5)
        // Shouldn't really hit this
        _ -> Error(Nil)
      }
    }
    
    type Status {
      Status(current_position: Int, total_distance_moved: Int)
    }
    
    fn input_to_program(input: String) -> Result(List(Int), Nil) {
      string.split(input, on: "")
      |> list.filter(fn(wp) {
        wp |> string.trim() |> string.is_empty() |> bool.negate()
      })
      |> list.try_map(waypoint)
    }
    
    /// Part 1?
    pub fn part1(input: String) -> Int {
      // Convert the input into a program of waypoints
      // Now that we have the program, calculate our steps through
      let assert Ok(program) =
        input
        |> input_to_program()
    
      program
      |> list.fold(Status(0, 0), fn(acc, next_wp) {
        // We just fold with an accumulator keeping our current_pos and total_pos as we go through
        Status(
          current_position: next_wp,
          total_distance_moved: acc.total_distance_moved
            + case int.compare(next_wp, acc.current_position) {
            order.Lt | order.Eq -> ring_size - acc.current_position + next_wp
            order.Gt -> next_wp - acc.current_position
          },
        )
      })
      |> fn(status) { status.total_distance_moved }
    }
    
    Part 2

    consume_sorted() is actually a noop right now because I got kinda stuck with looping in gleam :P butttt I realized if I just get the counts of the waypoints it's trivial to do the rest.

    e.g. [#(0, 2), #(2, 2), #(4, 2)] from one of the examples (where 0 is "r", 1 is "o", etc. and the second value is the count of that waypoint in the program), we can do 26 because we start at r so that's the longest, then the next longest is to 4 so 26+4 and we've got [#(2, 2), #(4, 1] left, so 26+4+16 then repeat for the 2 26+4+16+4+1*6. Works the same for the large input so I just did that in a calculator and got the answer. I still can't wrap my head around how to implement the algorithm without loops! Not used to this stuff.

    pub fn part2(input: String) -> Int {
      let assert Ok(program) =
        input
        |> input_to_program()
    
      // We want a count of each letter in the program
      // sorted
      let counts =
        program
        |> list.fold(dict.new(), fn(acc, next_wp) {
          let count = case dict.get(acc, next_wp) {
            Ok(n) -> n + 1
            _ -> 1
          }
    
          dict.insert(acc, next_wp, count)
        })
        |> dict.to_list()
        |> list.sort(fn(a, b) { int.compare(a.0, b.0) })
        |> echo
    
      counts |> consume_sorted(Status(0, 0))
    }
    

    I actually didn't even finish my program for part 2 because I'm so bad at gleam but I figured out it's pretty easy to get the answer (more in the details).

  2. Comment on Day 1: Dusty Shed in ~comp.advent_of_code

    kari
    Link
    Pretty short but, because I love to learn a new language for AoC, took me a bit to get started. Gleam seems fun so far :) Both parts import gleam/dict.{type Dict} import gleam/int import...

    Pretty short but, because I love to learn a new language for AoC, took me a bit to get started. Gleam seems fun so far :)

    Both parts
    import gleam/dict.{type Dict}
    import gleam/int
    import gleam/list
    import gleam/order.{type Order}
    import gleam/string
    
    fn counts(input: String) -> Dict(Int, Int) {
      let assert Ok(ids) =
        input
        |> string.split("\n")
        |> list.map(string.trim)
        |> list.filter(fn(line) { !string.is_empty(line) })
        |> list.try_map(int.parse)
    
      ids
      |> list.fold(dict.new(), fn(counts, id) {
        let count = case dict.get(counts, id) {
          Ok(n) -> n + 1
          _ -> 1
        }
    
        dict.insert(counts, id, count)
      })
    }
    
    fn top_three_product(
      input: String,
      compare_counts: fn(Int, Int) -> Order,
    ) -> Int {
      counts(input)
      |> dict.to_list()
      |> list.sort(by: fn(a, b) {
        let #(_, count_a) = a
        let #(_, count_b) = b
        compare_counts(count_a, count_b)
      })
      |> list.take(3)
      |> list.map(fn(pair) {
        let #(id, _count) = pair
        id
      })
      |> list.fold(1, int.multiply)
    }
    
    /// Takes a list of line-separated container-ID numbers.
    /// Returns the product of the three most-common IDs.
    pub fn part1(input: String) -> Int {
      top_three_product(input, fn(a, b) { int.compare(b, a) })
    }
    
    /// Takes a list of line-separated container-ID numbers.
    /// Returns the product of the three least-common IDs.
    pub fn part2(input: String) -> Int {
      top_three_product(input, fn(a, b) { int.compare(a, b) })
    }
    

    I'm not 100% sure how idiomatic it is but I tried to be functional?

    2 votes
  3. Comment on US Federal Aviation Administration issues nationwide ground stop for all flights citing "due to extraordinary circumstances and for reasons of safety" in ~transport

    kari
    Link Parent
    Hey, I watched it too! It was actually the first time I'd ever seen it.

    Hey, I watched it too! It was actually the first time I'd ever seen it.

    4 votes
  4. Comment on US Federal Aviation Administration issues nationwide ground stop for all flights citing "due to extraordinary circumstances and for reasons of safety" in ~transport

  5. Comment on What programming/technical projects have you been working on? in ~comp

    kari
    Link
    I spent a bit of time working on my window manager for the first time in a while to update it for Zig 0.17 and fix a few bugs. I also learned about the Idris language and I'm tempted to try create...

    I spent a bit of time working on my window manager for the first time in a while to update it for Zig 0.17 and fix a few bugs. I also learned about the Idris language and I'm tempted to try create a River tinyrwm with some weird Wayland bindings for Idris as a way of learning.

    4 votes
  6. Comment on How often do you talk to strangers? And do you have a preference for the stranger’s gender? in ~life

    kari
    Link
    I personally don't start up conversations but for whatever reason it feels like people will talk to me, and I always enjoy chatting back.

    I personally don't start up conversations but for whatever reason it feels like people will talk to me, and I always enjoy chatting back.

    6 votes
  7. Comment on Tesla to wind down Cybertruck production in Texas next year in ~transport

    kari
    Link Parent
    Yeah sorry I was mostly agreeing just saying it does sound skewed is all

    Yeah sorry I was mostly agreeing just saying it does sound skewed is all

  8. Comment on Tesla to wind down Cybertruck production in Texas next year in ~transport

    kari
    Link Parent
    While I'm assuming you're right overall, it does seen like it's probably skewed some considering here, where it's definitely skewed the other way, I almost never see Rivians.

    Decent number of Rivians (skewed by being in central IL). Cybertrucks did not compete successfully.

    While I'm assuming you're right overall, it does seen like it's probably skewed some considering here, where it's definitely skewed the other way, I almost never see Rivians.

    1 vote
  9. Comment on US Federal Aviation Administration says it will phase out floppy disks from air traffic control by 2028 in ~tech

    kari
    Link Parent
    If it makes you feel better, I personally wouldn't worry much about that specific situation. There are tons of untowered airports in the world and, while they're usually not seeing commercial...

    This makes me afraid that now every airport in the country is going to shut down catastrophically all at once.

    If it makes you feel better, I personally wouldn't worry much about that specific situation. There are tons of untowered airports in the world and, while they're usually not seeing commercial service, pilots will have flown in/out of them during various stages of getting their license(s) and ratings. In other words, there are standard procedures for operating in uncontrolled airspace.

    Idk, besides the fact that it would effectively shutdown our airspace for who knows how long, I wouldn't be too worried about the safety aspect (though, obviously, it's not great, just it could be a lot worse).

    2 votes
  10. Comment on Details for the Motorola Signature 27 with GrapheneOS support in ~tech

    kari
    Link
    Seems cool and I probably would've liked one even with the price tag if I hadn't just bought a phone in August. I was trying to wait for this, but my iPhone broke (mostly my fault, had to get the...

    Seems cool and I probably would've liked one even with the price tag if I hadn't just bought a phone in August. I was trying to wait for this, but my iPhone broke (mostly my fault, had to get the battery replaced last year and then I took it to a water park and it got wet, I guess the battery replacement destroyed the water proofing, but I digress) back in August so I just went ahead and got a Pixel 10 Pro for Graphene. I will say, I'm loving Graphene a lot and the Pixel 10 Pro feels amazing in my hands and with the case I have on it.

    1 vote
  11. Comment on Tesla to wind down Cybertruck production in Texas next year in ~transport

    kari
    Link
    I'm honestly a little surprised considering how many of these I see around Austin, but maybe it's just the fact that they're made here and we've got so many tech bros.

    I'm honestly a little surprised considering how many of these I see around Austin, but maybe it's just the fact that they're made here and we've got so many tech bros.

    8 votes
  12. Comment on 2026 United States midterm elections megathread in ~society

    kari
    Link Parent
    Here in Texas, a bunch of the attack ads against Hinajosa were saying how she wants a state income tax... which we already banned in our constitution a couple years ago... Regardless, I'm glad...

    We already had a law requiring it (I had to show my ID at the poll), why does it also need to be in the constitution.

    Here in Texas, a bunch of the attack ads against Hinajosa were saying how she wants a state income tax... which we already banned in our constitution a couple years ago...

    Regardless, I'm glad y'all also had good results for the most part :)

    5 votes
  13. Comment on 2026 United States midterm elections megathread in ~society

    kari
    Link Parent
    I think this is the big thing. I saw some people shitting on Florida, for example, but even the races that progressive Democrats lost were much closer than they had any right to be and are a good...

    Callie Barr came within shouting distance of winning where there's usually a 70% Republican electorate.

    I think this is the big thing. I saw some people shitting on Florida, for example, but even the races that progressive Democrats lost were much closer than they had any right to be and are a good sign, I think.

    13 votes
  14. Comment on 2026 United States midterm elections megathread in ~society

    kari
    Link
    I'm genuinely still in shock that we're about to have a blue Texas in my lifetime. The fact that Collin, Tarrant, and Williamson counties all voted blue is insane. I'm still going to ride the high...

    I'm genuinely still in shock that we're about to have a blue Texas in my lifetime. The fact that Collin, Tarrant, and Williamson counties all voted blue is insane. I'm still going to ride the high for a few days, but come January, there are absolutely no excuses left. If Trump doesn't need to get his veto pen ready, I worry for 2028, but for now, I'm ecstatic.

    11 votes
  15. Comment on Setting up own email FQDN (and maybe service?) in ~tech

    kari
    Link Parent
    You absolutely can reply from any email address with Mailbox, at least. I'm admittedly too lazy to send a redacted screenshot of this, but I just emailed myself from...

    but you can't reply from these made up addresses.

    You absolutely can reply from any email address with Mailbox, at least. I'm admittedly too lazy to send a redacted screenshot of this, but I just emailed myself from rodrigofromtildes@<mydomain>.email and it went through fine even to my gmail account that I still keep around. Now, depending on the email client you're using, it can be a pain to set that up, but Thunderbird on desktop you can just do "customize from address" and it's super easy. Regardless, I've forgotten to do that a few times and never had issues with companies getting annoyed/confused at me replying from a different address than the one they sent to.

    3 votes
  16. Comment on 2026 United States midterm elections megathread in ~society

    kari
    Link
    Lolllllll fuck Paxton and Abbott

    Lolllllll fuck Paxton and Abbott

    22 votes
  17. Comment on 2026 United States midterm elections megathread in ~society

  18. Comment on 2026 United States midterm elections megathread in ~society

    kari
    Link Parent
    Ah, still neat. Hadn't heard of things like that. I think here, the positions are by district or at-large, but for at-large ones, you still have to run/vote for the specific place.

    Ah, still neat. Hadn't heard of things like that. I think here, the positions are by district or at-large, but for at-large ones, you still have to run/vote for the specific place.

    4 votes
  19. Comment on 2026 United States midterm elections megathread in ~society

    kari
    Link Parent
    I had 64! Probably a similar percentage were uncontested.

    I was [...] had 35 things to vote on

    I had 64! Probably a similar percentage were uncontested.

    2 votes
  20. Comment on 2026 United States midterm elections megathread in ~society

    kari
    Link Parent
    Ranked-choice voting? Must be nice. Signed, A voter in a state where anything aside from first-past-the-post is literally illegal :(

    or have "select up to 3"

    Ranked-choice voting? Must be nice.

    Signed,
    A voter in a state where anything aside from first-past-the-post is literally illegal :(

    8 votes