kari's recent activity

  1. Comment on Day 1: Trebuchet?! in ~comp.advent_of_code

    kari
    Link
    Here's my code in Rust. It's not particularly elegant (or fast, or good, or idiomatic, or...), but it gets the job done. I'm going on a work trip/vacation for the next 8 days so I probably won't...

    Here's my code in Rust. It's not particularly elegant (or fast, or good, or idiomatic, or...), but it gets the job done. I'm going on a work trip/vacation for the next 8 days so I probably won't be able to keep up but can't wait to come check out these threads after the fact.

    2 votes
  2. Comment on Independent bookstores are thriving in Texas, and not just in big cities—in suburbs and in small towns, new shops are serving up classics, cocktails, and community in ~books

    kari
    Link
    I'm from Austin and I knew First Light Books would be on this list. I didn't even know about the one near UT, though

    I'm from Austin and I knew First Light Books would be on this list. I didn't even know about the one near UT, though

    2 votes
  3. Comment on Day 7: No Space Left On Device in ~comp

    kari
    Link
    This one was a pain in my butt (I just finished it last night), but I think that was mostly down to the fact that I'm just learning nim and I wasn't understanding refs correctly at first. nim...

    This one was a pain in my butt (I just finished it last night), but I think that was mostly down to the fact that I'm just learning nim and I wasn't understanding refs correctly at first.

    nim (both parts)
    import std/[heapqueue, strutils, tables]
    
    type
      MyFile = ref object
        name: string
        parentDir: MyFile
        case isDir: bool
        of true: files: TableRef[string, MyFile]
        of false: size: int
    
    proc len(file: MyFile): int =
      if not file.isDir:
        return file.size
      var size = 0
      for subFile in file.files.values:
        size += subFile.len()
      return size
    
    proc part1(file: MyFile): int =
      if not file.isDir:
        return file.size
    
      var size = 0
      for subFile in file.files.values:
        if subFile.isDir:
          if subFile.len <= 100000:
            size += subFile.len
          size += subFile.part1()
      return size
    
    proc part2Rec(file: MyFile): (int, HeapQueue[int]) =
      var
        size = 0
        heap: HeapQueue[int]
      for subFile in file.files.values:
        if subFile.isDir:
          var (subDirSize, subDirHeap) = part2Rec(subFile)
          while subDirHeap.len > 0:
            heap.push(subDirHeap.pop())
          size += subDirSize
        else:
          size += subFile.size
      heap.push(size)
      return (size, heap)
    
    proc part2(root: MyFile, capacity, goalFree: int): int =
      let outerSize = root.len
      var (_, heap) = root.part2Rec()
      while heap.len > 0:
        let size = heap.pop()
        if capacity - outerSize + size > goalFree:
          return size
    
      return -1
    
    proc day07*() =
      var
        root: MyFile
        curDir: MyFile
    
      # Assumes the first input line is to root
      # `cd ..` from root is ignored
      for line in lines("inputs/day07.in"):
        let split = line.splitWhitespace()
        if split[0] == "$":
          if split[1] == "cd":
            let name = split[2]
            if name == "..":
              if curDir.parentDir != nil:
                curDir = curDir.parentDir
            else:
              if curDir == nil:
                # Create root
                root = MyFile(name: name, isDir: true)
                curDir = root
                continue # Done w/the rest of this if
              if curDir.files == nil:
                new curDir.files
              var dir = curDir.files.getOrDefault(name)
              if dir == nil:
                # This shouldn't happen but we can handle it just in case
                dir = MyFile(name: name, parentDir: curDir, isDir: true)
                curDir.files[name] = dir
              curDir = dir
          # We can ignore ls lines (at least for now)
          # elif split[1] == "ls":
          #   # Do other stuff
        else:
          let name = split[1]
          if curDir.files == nil:
            new curDir.files
    
          if split[0] == "dir":
            let newDir = MyFile(name: name, parentDir: curDir, isDir: true)
            curDir.files[name] = newDir
          else:
            curDir.files[name] = MyFile(name: name, parentDir: curDir, isDir: false,
                size: parseInt(split[0]))
    
      echo "Part 1: " & $(root.part1)
      echo "Part 2: " & $(root.part2(70_000_000, 30_000_000))
    
    1 vote
  4. Comment on Day 10: Cathode-Ray Tube in ~comp

    kari
    Link
    I just finished day 7 last night and figured I'd do 10 before 8 and 9 since it seemed fairly easy. Well, part 1 was, but part 2's logic was confusing me for a bit... anyways. nim (both parts)...

    I just finished day 7 last night and figured I'd do 10 before 8 and 9 since it seemed fairly easy.

    Well, part 1 was, but part 2's logic was confusing me for a bit... anyways.

    nim (both parts)
    import std/strutils
    
    proc checkSignalStrength(cycle, regX: int): int {.inline.} =
      if (cycle - 20) mod 40 == 0:
        return cycle * regX
      return 0
    
    proc checkIfVisible(cycle, width, regX: int): char {.inline.} =
      if ((cycle - 1) mod width) in regX-1 .. regX+1:
        return '#'
      else:
        return '.'
    
    proc getRowCol(cycle, width: int): (int, int) {.inline.} =
      let row = (cycle - 1) div width
      let col = (cycle - 1) mod width
      return (row, col)
    
    proc day10*() =
      let
        height = 6
        width = 40
      var
        sumSignalStrengths = 0
        curCycle = 0
        regX = 1
        display: array[6, array[40, char]]
        row, col: int
    
      # Need to initialize the display
      for i in 0 ..< height:
        for j in 0 ..< width:
          display[i][j] = '.'
    
      for line in lines("inputs/day10.in"):
        let splitLine = line.splitWhitespace()
    
        # Invalid instructions are ignored
        # Assumes addx's 1st param is always an int (so it won't crash)
        # I could probably make more procs to make this nicer, but I'm lazy
        case splitLine[0]:
          of "noop":
            # 1st cycle
            curCycle += 1
    
            sumSignalStrengths += checkSignalStrength(curCycle, regX)
    
            (row, col) = getRowCol(curCycle, width)
            display[row][col] = checkIfVisible(curCycle, width, regX)
    
          of "addx":
            # 1st cycle
            curCycle += 1
    
            sumSignalStrengths += checkSignalStrength(curCycle, regX)
    
            (row, col) = getRowCol(curCycle, width)
            display[row][col] = checkIfVisible(curCycle, width, regX)
    
            # 2nd cycle
            curCycle += 1
    
            sumSignalStrengths += checkSignalStrength(curCycle, regX)
    
            (row, col) = getRowCol(curCycle, width)
            display[row][col] = checkIfVisible(curCycle, width, regX)
    
            # Operation
            regX += parseInt(splitLine[1])
          else:
            break
    
      echo "Part 1: " & $sumSignalStrengths
      echo "Part 2:"
      for row in display:
        var rowStr: string
        for col in row:
          rowStr &= col
        echo rowStr
    
    2 votes
  5. Comment on Day 6: Tuning Trouble in ~comp

    kari
    Link
    Today was much easier than I expected :) nim (both parts) import std/[sets, sequtils] proc day06*() = let f = open("inputs/day06.in") defer: f.close() let chars = f.readLine().toSeq() var...

    Today was much easier than I expected :)

    nim (both parts)
    import std/[sets, sequtils]
    
    proc day06*() =
      let f = open("inputs/day06.in")
      defer: f.close()
    
      let chars = f.readLine().toSeq()
      var
        startOfPktIdx = -1
        startOfMsgIdx = -1
        curIdx = 0
        pktSet: HashSet[char]
        msgSet: HashSet[char]
    
      while startOfPktIdx == -1 or startOfMsgIdx == -1:
        # Part 1
        if startOfPktIdx == -1:
          pktSet = chars[curIdx .. curIdx + 3].toHashSet()
          if pktSet.len == 4:
            startOfPktIdx = curIdx + 4
        # Part 2
        if startOfMsgIdx == -1:
          msgSet = chars[curIdx .. curIdx + 13].toHashSet()
          if msgSet.len == 14:
            startOfMsgIdx = curIdx + 14
        curIdx += 1
    
      echo "Part 1: " & $startOfPktIdx
      echo "Part 2: " & $startOfMsgIdx
    
    2 votes
  6. Comment on Day 5: Supply Stacks in ~comp

    kari
    Link
    I think as I learn more nim I'll be able to come back to this one and clean it up a bit, but anyways, it works for now :P nim (both parts) import std/[deques, strutils] proc day05*() = let f =...

    I think as I learn more nim I'll be able to come back to this one and clean it up a bit, but anyways, it works for now :P

    nim (both parts)
    import std/[deques, strutils]
    
    proc day05*() =
      let f = open("inputs/day05.in")
      defer: f.close()
    
      var 
        line = f.readLine()
        stacksP1: seq[Deque[char]]
        crateIdx: int
        topWordP1: string
        topWordP2: string
    
      # Get all of the stacks
      while line != "":
        crateIdx = line.find('[', 0)
        while crateIdx != -1:
          # Make sure stacks is long enough
          while stacksP1.len <= int(crateIdx / 4):
            var deque: Deque[char]
            stacksP1.add(deque)
          stacksP1[int(crateIdx / 4)].addFirst(line[crateIdx + 1])
          crateIdx = line.find('[', crateIdx + 1)
    
        line = f.readLine()
      var stacksP2 = deepCopy(stacksP1)
    
      # Move the crates between stacks
      while (f.readLine(line)):
        let splitLine = line.splitWhitespace()
        let
          count = parseInt(splitLine[1])
          srcStack = parseInt(splitLine[3]) - 1 # My stacks are zero-indexed
          dstStack = parseInt(splitLine[5]) - 1 # but these aren't
        var tmpStack: Deque[char]
    
        for i in 0..<count:
          # CrateMover 9000
          stacksP1[dstStack].addLast(stacksP1[srcStack].popLast())
          # CrateMover 9001
          tmpStack.addFirst(stacksP2[srcStack].popLast())
        while tmpStack.len > 0:
          stacksP2[dstStack].addLast(tmpStack.popFirst)
    
      for stack in stacksP1:
        topWordP1.add(stack.peekLast())
      for stack in stacksP2:
        topWordP2.add(stack.peekLast())
      echo "Part 1: " & topWordP1
      echo "Part 2: " & topWordP2
    
    1 vote
  7. Comment on Day 4: Camp Cleanup in ~comp

  8. Comment on Day 4: Camp Cleanup in ~comp

    kari
    Link
    I struggled with trying to convert each elf's assignment to a set. Nim is confusing... Nim (both parts) import std/[sets, sequtils, strutils, sugar] proc assignmentToSet(assignment: string):...

    I struggled with trying to convert each elf's assignment to a set. Nim is confusing...

    Nim (both parts)
    import std/[sets, sequtils, strutils, sugar]
    
    proc assignmentToSet(assignment: string): HashSet[int] =
      # This is janky as hell... I'm so sorry, nim.
      let assignmentSet = collect:
        let intEnds = collect:
          for a in assignment.split('-'):
            parseInt(a)
        (intEnds[0]..intEnds[1]).toSeq().toHashSet()
      result = assignmentSet[0]
    
    proc day04*() =
      var 
        numProperSubsets = 0 
        numAnySubsets = 0
    
      for line in lines("inputs/day04.in"):
        let pairAssignments = line.split(',')
        let assignment1 = assignmentToSet(pairAssignments[0])
        let assignment2 = assignmentToSet(pairAssignments[1])
    
        let intersection = assignment1 * assignment2
    
        # Part 1
        if intersection == assignment1 or intersection == assignment2:
          numProperSubsets += 1
    
        # Part 2
        if intersection.len > 0:
          numAnySubsets += 1
    
      echo "Part 1: " & $numProperSubsets
      echo "Part 2: " & $numAnySubsets
    
    2 votes
  9. Comment on Day 3: Rucksack Reorganization in ~comp

    kari
    Link
    I enjoyed today! Nim (both parts) I think there's a better way for me to get the single item left after the intersections than popping, but I can't figure it out import std/[sets, sequtils,...

    I enjoyed today!

    Nim (both parts)

    I think there's a better way for me to get the single item left after the intersections than popping, but I can't figure it out

    import std/[sets, sequtils, strutils]
    
    proc getPriority(item: char): int =
      # We want a-z to be 1-26
      # and A-Z to be 27-52
      if item.isLowerAscii():
        return ord(item) - 96 # ord('a') == 97
      else:
        return ord(item) - 38 # ord('A') == 65
    
      # Just in case, but everything *should* be upper or lowercase letters
      return 0
    
    proc day03*() =
      var
        prioritySumP1 = 0
        prioritySumP2 = 0
    
      var rucksacks = lines("inputs/day03.in").toSeq()
      for line in rucksacks:
        let midPoint = int(line.len / 2)
        let compartmentOne = line[0 ..< midPoint].toHashSet()
        let compartmentTwo = line[midPoint .. ^1].toHashSet()
        # easy way to get the one mismatched item
        var itemSet = (compartmentOne * compartmentTwo)
        let item = itemSet.pop()
    
        prioritySumP1 += getPriority(item)
    
      while rucksacks.len() > 0:
        let rucksackOne = rucksacks.pop().toHashSet()
        let rucksackTwo = rucksacks.pop().toHashSet()
        let rucksackThree = rucksacks.pop().toHashSet()
    
        var itemSet = (rucksackOne * rucksackTwo * rucksackThree)
        let item = itemSet.pop()
    
        prioritySumP2 += getPriority(item)
    
      echo "Part 1: " & $prioritySumP1
      echo "Part 2: " & $prioritySumP2
    
    2 votes
  10. Comment on Day 3: Rucksack Reorganization in ~comp

    kari
    Link Parent
    Wow, Swift seems a lot like Rust

    Wow, Swift seems a lot like Rust

    2 votes
  11. Comment on Day 1: Calorie Counting in ~comp

    kari
    Link Parent
    Thank you!! That's super helpful :) I admittedly didn't see this until after I finished day 2, but I'll keep all of that in mind for the rest of the challenges (and if I ever do any non-aoc nim...

    Thank you!! That's super helpful :) I admittedly didn't see this until after I finished day 2, but I'll keep all of that in mind for the rest of the challenges (and if I ever do any non-aoc nim programming)

    1 vote
  12. Comment on Day 2: Rock Paper Scissors in ~comp

    kari
    Link
    I'm a big dumb dumb, so I just did it in the first way I thought of which is uh... not exactly elegant. Nim (both parts) import std/strutils type RockPaperScissorsMove = enum rpsmInvalid = 0,...

    I'm a big dumb dumb, so I just did it in the first way I thought of which is uh... not exactly elegant.

    Nim (both parts)
    import std/strutils
    
    type
      RockPaperScissorsMove = enum
        rpsmInvalid = 0, rpsmRock = 1, rpsmPaper = 2, rpsmScissors = 3
      RockPaperScissorsOutcome = enum
        rpsoLoss = 0, rpsoDraw = 3, rpsoWin = 6, rpsoInvalid
    
    proc calcScoreP1(myMove, theirMove: RockPaperScissorsMove): int {.inline.} = 
      if myMove == rpsmRock:
        if theirMove == rpsmRock:
          return int(rpsoDraw) + int(myMove)
        if theirMove == rpsmScissors:
          return int(rpsoWin) + int(myMove)
        if theirMove == rpsmPaper:
          return int(rpsoLoss) + int(myMove)
    
      if myMove == rpsmPaper:
        if theirMove == rpsmPaper:
          return int(rpsoDraw) + int(myMove)
        if theirMove == rpsmRock:
          return int(rpsoWin) + int(myMove)
        if theirMove == rpsmScissors:
          return int(rpsoLoss) + int(myMove)
    
      if myMove == rpsmScissors:
        if theirMove == rpsmScissors:
          return int(rpsoDraw) + int(myMove)
        if theirMove == rpsmPaper:
          return int(rpsoWin) + int(myMove)
        if theirMove == rpsmRock:
          return int(rpsoLoss) + int(myMove)
    
      return 0
    
    proc calcScoreP2(theirMove: RockPaperScissorsMove, desiredOutcome: RockPaperScissorsOutcome): int {.inline.} =
      if desiredOutcome == rpsoLoss:
        if theirMove == rpsmRock:
          return int(rpsoLoss) + int(rpsmScissors)
        if theirMove == rpsmPaper:
          return int(rpsoLoss) + int(rpsmRock)
        if theirMove == rpsmScissors:
          return int(rpsoLoss) + int(rpsmPaper)
    
      if desiredOutcome == rpsoDraw:
        if theirMove == rpsmRock:
          return int(rpsoDraw) + int(rpsmRock)
        if theirMove == rpsmPaper:
          return int(rpsoDraw) + int(rpsmPaper)
        if theirMove == rpsmScissors:
          return int(rpsoDraw) + int(rpsmScissors)
    
      if desiredOutcome == rpsoWin:
        if theirMove == rpsmRock:
          return int(rpsoWin) + int(rpsmPaper)
        if theirMove == rpsmPaper:
          return int(rpsoWin) + int(rpsmScissors)
        if theirMove == rpsmScissors:
          return int(rpsoWin) + int(rpsmRock)
    
      return 0
    
    proc day02*() = 
      var 
        scoreP1 = 0
        scoreP2 = 0
    
      # Assumes the input is in the correct format
      for line in lines("inputs/day02.in"):
        let moves = line.splitWhitespace()
        let theirMove: RockPaperScissorsMove = case moves[0]:
          of "A":
            rpsmRock
          of "B":
            rpsmPaper
          of "C":
            rpsmScissors
          else:
            rpsmInvalid
    
        let myMove: RockPaperScissorsMove = case moves[1]:
          of "X":
            rpsmRock
          of "Y":
            rpsmPaper
          of "Z":
            rpsmScissors
          else:
            rpsmInvalid
    
        let desiredOutcome: RockPaperScissorsOutcome = case moves[1]:
          of "X":
            rpsoLoss
          of "Y":
            rpsoDraw
          of "Z":
            rpsoWin
          else:
            rpsoInvalid
        
        scoreP1 += calcScoreP1(myMove, theirMove)
        scoreP2 += calcScoreP2(theirMove, desiredOutcome)
      
      echo("Part 1: " & $scoreP1)
      echo("Part 2: " & $scoreP2)
    
    2 votes
  13. Comment on Day 1: Calorie Counting in ~comp

    kari
    Link
    Decided to try out nim literally minutes before I started (I've done like half of nim by example before and no other nim) so it was actually a bit of a struggle. My solution kinda sucks, though....

    Decided to try out nim literally minutes before I started (I've done like half of nim by example before and no other nim) so it was actually a bit of a struggle. My solution kinda sucks, though.

    Both parts
    import std/strutils
    import std/sequtils
    
    proc day1*() = 
      var 
        elves = newSeq[int]()
        currentElf = 0
        topThreeSum = 0 
    
      for line in lines("inputs/day1.in"):
        if line != "":
          currentElf += parseInt(line)
        else:
          elves.add(currentElf)
          currentElf = 0
    
      for _ in countup(1,3):
        let idx = elves.maxIndex()
        topThreeSum += elves[idx]
        elves.delete(idx)
    
      echo(topThreeSum)
    
    2 votes
  14. Comment on Signal messenger introduces stories in ~tech

    kari
    Link Parent
    I’m 23. I post maybe 1 or 2 Instagram stories a month of things like a picture of a concert or my girlfriend and me on a date. A lot of my friends post more often and it’s things like collages...

    I’m 23. I post maybe 1 or 2 Instagram stories a month of things like a picture of a concert or my girlfriend and me on a date. A lot of my friends post more often and it’s things like collages with happy birthday messages, pictures of stuff they’re doing, pets being cute, that sort of stuff. Signal seems like a weird place to have them, though.

    8 votes
  15. Does anybody have advice for getting better at racing sims? (Both circuit and rally)

    I’ve always enjoyed rally games but only recently decided to buy a wheel (just a used Logitech G29) and also decided to give F1 22 a shot. I feel like I’m okay-ish at DiRT Rally 2.0 and WRC 10 but...

    I’ve always enjoyed rally games but only recently decided to buy a wheel (just a used Logitech G29) and also decided to give F1 22 a shot. I feel like I’m okay-ish at DiRT Rally 2.0 and WRC 10 but atrocious at F1 22. How do I actually learn to be better instead of constantly making mistakes?

    9 votes
  16. Comment on Is it possible to expand my Windows EFI partition? in ~tech

    kari
    Link Parent
    Thanks! I’ll give it a shot with GParted then, probably. I already had to reinstall Windows last week while troubleshooting a different issue so no big deal if I end up breaking something and...

    Thanks! I’ll give it a shot with GParted then, probably. I already had to reinstall Windows last week while troubleshooting a different issue so no big deal if I end up breaking something and having to re-install.

    2 votes
  17. Is it possible to expand my Windows EFI partition?

    I currently dual-boot Arch and Windows and just use the Windows EFI partition in Arch as well, however I only have about 13 MB of space left on it. I’d like to try installing Gentoo on an extra...

    I currently dual-boot Arch and Windows and just use the Windows EFI partition in Arch as well, however I only have about 13 MB of space left on it.

    I’d like to try installing Gentoo on an extra SSD I have with nothing on it, but don’t really want to have a second EFI partition if I can avoid it.

    So my question is, can I shrink the Windows main partition towards the right and expand the the Windows EFI partition into the newly freed space?

    6 votes
  18. Comment on What games have you been playing, and what's your opinion on them? in ~games

    kari
    Link
    I’ve been replaying Borderlands 3 and really enjoy it. I don’t think the humour’s quite up to par with BL2 but it still a fun looter shooter.

    I’ve been replaying Borderlands 3 and really enjoy it. I don’t think the humour’s quite up to par with BL2 but it still a fun looter shooter.

    4 votes
  19. Comment on Having been on Android for over a decade, I just got my first iPhone! What should I know? in ~tech

    kari
    Link Parent
    Ha, I love my Siri widget just because it'll tell me to pull up the Maps route to places I've only been to a few times but at roughly the same time and day of the week. For example, I got Cabo...

    Ha, I love my Siri widget just because it'll tell me to pull up the Maps route to places I've only been to a few times but at roughly the same time and day of the week. For example, I got Cabo Bob's (kind of like an Austin-based Chipotle) for dinner two or three Monday's in a row, and Siri was suggesting it as a location to go to.

    3 votes
  20. Comment on Having been on Android for over a decade, I just got my first iPhone! What should I know? in ~tech

    kari
    Link Parent
    I use Apple Maps for Austin to and from DFW pretty often and it's decent. I generally just use it because I don't like Google, but I think it's generally on par with Google Maps. Reroutes for...

    I use Apple Maps for Austin to and from DFW pretty often and it's decent. I generally just use it because I don't like Google, but I think it's generally on par with Google Maps.

    Reroutes for traffic are okay, but a little delayed IMO. For example, some times it won't notify me that taking Loop 340 in Waco will be faster than 35, but if I pull up the full-route view in the CarPlay app it'll show it as a faster option. I do get less info about stuff on the road, but I think maybe that's because Google can use Waze's data where people tend to be pretty active about reports compared to Apple Maps, where people presumably aren't.

    My favorite thing by far is that Apple Maps will show/tell you, like you said, information about lights, stop signs, etc. which can be really helpful when trying to find where to turn in a place you've never been before.

    1 vote