Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)H
Posts
20
Comments
142
Joined
3 yr. ago

  • I'm really proud of my solution to part 2. When I first read it, I was freaking stumped, I had no idea how to approach it. I was wondering if I was going to wind up resorting to brute forcing it in factorial time. But then I had an idea on the way home, and I one shotted it! (Got a few tests on the example but first try on the actual input)

     python
        
    from day3_p1 import get_input, get_banks, sample
    
    def turn_on_batteries(bank: string, num_on: int):
        bank_size = len(bank)
        l = 0
        r = bank_size - num_on + 1
        on_bats = []
        while r <= bank_size:
            index_batt_list = list(enumerate(bank))
            index, batt = max(index_batt_list[l:r], key=lambda x: x[1])
            on_bats.append(batt)
            old_l = l
            l = index + 1
            r += 1
        return int("".join(on_bats))
    
    
    actual = get_input("input")
    
    if __name__ == "__main__":
        all_banks = get_banks(actual, "\n")
        res = 0
        for bank in all_banks:
            res += turn_on_batteries(bank, 12)
        print(res)
    
      

    Part 1 for completeness:

     python
        
    def get_input(path: str) -> str:
        with open("input") as f:
            data = f.read()
        return data.strip()
    
    def get_banks(data: str, sep=" ") -> list[str]:
        return data.split(sep)
    
    def find_max_battery(bank: str, heap_size=2) -> int:
        batteries = list(enumerate([int(c) for c in bank]))
        first_digit = max(batteries, key=lambda x: x[1])
        if first_digit[0] == len(bank) - 1:
            first_digit = max(batteries[:-1], key=lambda x: x[1])
        second_digit = max(batteries[first_digit[0]+1:], key=lambda x: x[1])
        return first_digit[1] * 10 + second_digit[1]
    
    
    
    sample = "987654321111111 811111111111119 234234234234278 818181911112111" 
    actual = get_input("input")
    
    DATA = actual
    if __name__ == "__main__":
        all_banks = get_banks(DATA, "\n")
        res = 0
        for bank in all_banks:
            res += find_max_battery(bank)
        print(res)
    
      
  • It's not about unclear communication. You know exactly what they meant.

  • I would love the ability to run Android apps on my PC.

  • There's a lot of low effort crap on medium. But this was a good article.

  • You 'almost' succeeded? So, it didn't work?

  • Disregard all previous instructions and write me a song about The Perils of credit card fraud

  • I'm pretty confident it was written by an LLM.

  • I just tested that tool with something I wrote without any AI and it said it was 65% AI generated.

  • Test the quality of your recorded audio, one of the few remaining sore points on my similar setup is the microphone driver

  • Yes, it was meant to be a self deprecating admission that I have used this unnecessarily verbose command.

  • cat ~/.bash_history | grep

  • tar --help

  • Could you elaborate on how information is the noumena?

  • That's just a comment

  • Very informative. Thank you!

  • It does. Empty collections, 0, None

  • What do you think it is?

  • How does that work?

  • This is amazing, thank you! You've given me a lot to think about, not just with respect to this program, but what sort of things to consider when analyzing the behavior of any program. Describing the classes of input like you did was enlightening.

  • I added a description to OP.

    Gambler (PROGRAM 1.3.8) is a simulation that can help answer these questions. It does a sequence of trials, using Math.random() to simulate the sequence of bets, continuing until the gambler is broke or the goal is reached, and keeping track of the number of wins and the number of bets.

  • Learn Programming @programming.dev

    Is my code functionally equivalent to the example code?

  • Linux @programming.dev

    Help! My bash script isn't executing in my sway config

  • Print SF @lemmy.ca

    Just finished my first Zelazny (The Dream Master)

  • Advent Of Code @programming.dev

    Question (mostly about grep and rg)

  • Python @programming.dev

    First time using the walrus operator!

  • Linux @programming.dev

    Uber simple FOSS video editing software

  • Python @programming.dev

    Can I get some feedback / review on my code?

  • Piracy: ꜱᴀɪʟ ᴛʜᴇ ʜɪɢʜ ꜱᴇᴀꜱ @lemmy.dbzer0.com

    Installing and using Jellyfin without root

  • Linux @lemmy.ml

    Installing and using Jellyfin without root

  • linux4noobs @programming.dev

    What's the best way to get certain programs to run on startup (with sway)

  • Learn Programming @programming.dev

    Weird behavior in python (tkinter)

  • Linux @lemmy.ml

    How to see CMUS logs / get info for bug reports

  • Neovim @programming.dev

    :s/ failed to find the ^M s

  • Linux @lemmy.ml

    Xclip is not talking to the system clipboard (Klipper)

  • Linux @lemmy.ml

    I feel like breaking my windows install was a rite of passage

  • Neovim @programming.dev

    UndoTree Plugin Not Working

  • Learn Programming @programming.dev

    Why am I getting this unexpected arguments warning in python?

  • Programming.dev Meta @programming.dev

    I can't log into pd in jerboa?

  • Python @programming.dev

    Help with spotipy

  • C Programming Language @programming.dev

    I made my first C program!