• 1 Post
  • 21 Comments
Joined 1 year ago
cake
Cake day: June 20th, 2023

help-circle

  • Odin

    When I read the problem description I expected the input to also be 2 digit numbers. When I looked at it I just had to say “huh.”

    Second part I think you definitely have to do in reverse (edit: if you are doing a linear search for the answer), as that allows you to nope out as soon as you find a match, whereas with doing it forward you have to keep checking just in case.

    Formatted code

    package day5
    
    import "core:fmt"
    import "core:strings"
    import "core:slice"
    import "core:strconv"
    
    Range :: struct {
        dest: int,
        src: int,
        range: int,
    }
    
    Mapper :: struct {
        ranges: []Range,
    }
    
    parse_range :: proc(s: string) -> (ret: Range) {
        rest := s
    
        parseLen := -1
    
        destOk: bool
        ret.dest, destOk = strconv.parse_int(rest, 10, &parseLen)
        rest = strings.trim_left_space(rest[parseLen:])
    
        srcOk: bool
        ret.src, srcOk = strconv.parse_int(rest, 10, &parseLen)
        rest = strings.trim_left_space(rest[parseLen:])
    
        rangeOk: bool
        ret.range, rangeOk = strconv.parse_int(rest, 10, &parseLen)
    
        return
    }
    
    parse_mapper :: proc(ss: []string) -> (ret: Mapper) {
        ret.ranges = make([]Range, len(ss)-1)
        for s, i in ss[1:] {
            ret.ranges[i] = parse_range(s)
        }
    
        return
    }
    
    parse_mappers :: proc(ss: []string) -> []Mapper {
        mapsStr := make([dynamic][]string)
        defer delete(mapsStr)
    
        restOfLines := ss
        isLineEmpty :: proc(s: string)->bool {return len(s)==0}
    
        for i, found := slice.linear_search_proc(restOfLines, isLineEmpty); 
            found; 
            i, found  = slice.linear_search_proc(restOfLines, isLineEmpty) {
            
            append(&mapsStr, restOfLines[:i])
            restOfLines = restOfLines[i+1:]
        }
        append(&mapsStr, restOfLines[:])
    
        return slice.mapper(mapsStr[1:], parse_mapper)
    }
    
    apply_mapper :: proc(mapper: Mapper, num: int) -> int {
        for r in mapper.ranges {
            if num >= r.src && num - r.src < r.range do return num - r.src + r.dest
        }
    
        return num
    }
    
    p1 :: proc(input: []string) {
        maps := parse_mappers(input)
        defer {
            for m in maps do delete(m.ranges)
            delete(maps)
        }
    
        restSeeds := input[0][len("seeds: "):]
        min := 0x7fffffff
    
        for len(restSeeds) > 0 {
            seedLen := -1
            seed, seedOk := strconv.parse_int(restSeeds, 10, &seedLen)
            restSeeds = strings.trim_left_space(restSeeds[seedLen:])
    
            fmt.print(seed)
            for m in maps {
                seed = apply_mapper(m, seed)
                fmt.print(" ->", seed)
            }
            fmt.println()
    
            if seed < min do min = seed
        }
    
        fmt.println(min)
    }
    
    apply_mapper_reverse :: proc(mapper: Mapper, num: int) -> int {
        for r in mapper.ranges {
            if num >= r.dest && num - r.dest < r.range do return num - r.dest + r.src
        }
    
        return num
    }
    
    p2 :: proc(input: []string) {
        SeedRange :: struct {
            start: int,
            len: int,
        }
    
        seeds := make([dynamic]SeedRange)
        restSeeds := input[0][len("seeds: "):]
    
        for len(restSeeds) > 0 {
            seedLen := -1
            seedS, seedSOk := strconv.parse_int(restSeeds, 10, &seedLen)
            restSeeds = strings.trim_left_space(restSeeds[seedLen:])
    
            seedL, seedLOk := strconv.parse_int(restSeeds, 10, &seedLen)
            restSeeds = strings.trim_left_space(restSeeds[seedLen:])
    
            append(&seeds, SeedRange{seedS, seedL})
        }
    
        maps := parse_mappers(input)
        defer {
            for m in maps do delete(m.ranges)
            delete(maps)
        }
    
        for i := 0; true; i += 1 {
            rseed := i
            #reverse for m in maps {
                rseed = apply_mapper_reverse(m, rseed)
            }
    
            found := false
            for sr in seeds {
                if rseed >= sr.start && rseed < sr.start + sr.len {
                    found = true
                    break
                }
            }
            if found {
                fmt.println(i)
                break
            }
        }
    }
    



  • Did this in Odin

    Here’s a tip: if you are using a language / standard library that doesn’t have a set, you can mimic it with a map from your key to a nullary (in this case an empty struct)

    formatted code

    package day3
    
    import "core:fmt"
    import "core:strings"
    import "core:unicode"
    import "core:strconv"
    
    flood_get_num :: proc(s: string, i: int) -> (parsed: int, pos: int) {
        if !unicode.is_digit(rune(s[i])) do return -99999, -1
    
        pos = strings.last_index_proc(s[:i+1], proc(r:rune)->bool{return !unicode.is_digit(r)})
        pos += 1
    
        ok: bool
        parsed, ok = strconv.parse_int(s[pos:])
    
        return parsed, pos
    }
    
    p1 :: proc(input: []string) {
        // wow what a gnarly type
        foundNumSet := make(map[[2]int]struct{})
        defer delete(foundNumSet)
    
        total := 0
    
        for y in 0..

  • Did mine in Odin. Found this day’s to be super easy, most of the challenge was just parsing.

    package day2
    
    import "core:fmt"
    import "core:strings"
    import "core:strconv"
    import "core:unicode"
    
    Round :: struct {
        red: int,
        green: int,
        blue: int,
    }
    
    parse_round :: proc(s: string) -> Round {
        ret: Round
    
        rest := s
        for {
            nextNumAt := strings.index_proc(rest, unicode.is_digit)
            if nextNumAt == -1 do break
            rest = rest[nextNumAt:]
    
            numlen: int
            num, ok := strconv.parse_int(rest, 10, &numlen)
            rest = rest[numlen+len(" "):]
    
            if rest[:3] == "red" {
                ret.red = num
            } else if rest[:4] == "blue" {
                ret.blue = num
            } else if rest[:5] == "green" {
                ret.green = num
            }
        }
    
        return ret
    }
    
    Game :: struct {
        id: int,
        rounds: [dynamic]Round,
    }
    
    parse_game :: proc(s: string) -> Game {
        ret: Game
    
        rest := s[len("Game "):]
    
        idOk: bool
        idLen: int
        ret.id, idOk = strconv.parse_int(rest, 10, &idLen)
        rest = rest[idLen+len(": "):]
    
        for len(rest) > 0 {
            endOfRound := strings.index_rune(rest, ';')
            if endOfRound == -1 do endOfRound = len(rest)
    
            append(&ret.rounds, parse_round(rest[:endOfRound]))
            rest = rest[min(endOfRound+1, len(rest)):]
        }
    
        return ret
    }
    
    is_game_possible :: proc(game: Game) -> bool {
        for round in game.rounds {
            if round.red   > 12 ||
               round.green > 13 ||
               round.blue  > 14 {
                return false
            }
        }
        return true
    }
    
    p1 :: proc(input: []string) {
        totalIds := 0
    
        for line in input {
            game := parse_game(line)
            defer delete(game.rounds)
    
            if is_game_possible(game) do totalIds += game.id
        }
    
        fmt.println(totalIds)
    }
    
    p2 :: proc(input: []string) {
        totalPower := 0
    
        for line in input {
            game := parse_game(line)
            defer delete(game.rounds)
    
            minRed   := 0
            minGreen := 0
            minBlue  := 0
            for round in game.rounds {
                minRed   = max(minRed  , round.red  )
                minGreen = max(minGreen, round.green)
                minBlue  = max(minBlue , round.blue )
            }
    
            totalPower += minRed * minGreen * minBlue
        }
    
        fmt.println(totalPower)
    }
    

  • I don’t think this can really be answered until after the fact. Anything that I (and I suspect most) people could say about an artstyle are going to be particular to an instance of that artsyle. If I’d give advice as someone who is neither an artist nor a game designer, what attracts me more than anything is a unique artstyle, which, if I’m gonna give a brutal opinion, starting from a vague category like ‘pixel’, ‘hand drawn’ or ‘3D’ probably won’t get you there.

    I feel like I even struggle to answer your question at face value because it doesn’t align well at all with how I conceptualize game art. For example, Cruelty Squad is a game that I don’t think I’d have gotten if not for it’s artsyle. Like, sure, it’s 3D, but it’s a lot more like a PilotRedSun animation than it is a game like TF2. Or take a game like Factorio: most of the assets of that game are pre-rendered 3D sprites, so despite being artisticly unique in a way that interests me it doesn’t fit into the categories you’ve asked about. The best I can say is “I dunno”, and I don’t think anyone else can answer it further than that.


  • There is the Anno series of games, which are technically RTS games but if I’m honest I find them the most fun when I go out of my way to avoid combat/micromanagement. I’ve only played 1404, 2070, and 2205, 2070 being the best in my opinion, but it has a bad history with DRM so I’d suggest 1404 (known as “Dawn of Discovery” in the US because us americans are afraid of numbers apparently).

    Edit: looking at the steam page it looks like they decided to take 1404 down and made a new page where the game is (mostly) unchanged besides requiring you to jump through all the BS hoops that 2070 did, so I’d say if you’re gonna spend money get 1404 on GOG, or if you are willing to do unspeakable things go with 2070.







  • Moving the cursor will confuse bash and you can get the same effect by just omitting the last \n.

    When I was testing it I did not get the same effect. Instead it would only put the background behind what I had typed and not the whole line. Doing it now it seems to be working with the omission. I would assume it’s a terminal emulator bug because I believe I have changed emulators since I wrote it. I’ve now removed it, thanks for fixing a bug.

    Avoid doing external commands in subshells when there’s a perfectly good prompt-expansion string that works.

    I wanted my home directory to not get shortened to ~, and if there is some way to do that with \w it isn’t easy to find out how.

    Also, what’s the reasoning for avoiding it (besides it being idiomatic)? I’m sure there is one, but I don’t think I’ve run into it yet.

    You seem to be generating several unnecessary blank lines

    I just like the look of it, and I have the screen space to do it.


  • I have this in my laptop’s .bashrc

    PS1='\e[0m\n\e[40m[\e[32m\u\e[37m] [\e[31m\A \d\e[31m] [\e[33m`pwd`\e[37m]\e[K\n\e[K\n\e[1A'
    PS0='\e[0m\n'
    
    hint

    some of the escape sequences move the cursor

    full explanation

    generates the prompt:

    
    [username] [00:01 Thu Jan 1] [/home/username]

    with a slightly brighter/darker background (depending on terminal colors), while also resetting it to not effect the appearance of command outputs

    • \e[0m\n: new blank line
    • \e[40m: sets the background color for the prompt
    • [: literal text
    • \e[32m\u\e37m: username in green, reset color for brackets
    • ] [: literal text
    • \e[31m\A \d\e[31m: time/date in red, reset color
    • ] [: literal text
    • \e[33mpwd\e[37m: calls pwd, prints it in orange
    • ]: literal text
    • \e[K\n: fill the rest of the prompt line with the background
    • \e[K\n: fill the line where commands are typed with the background
    • \e[1A: move the cursor up so that it’s in the background-filled area

    I am colorblind so I may have gotten colors wrong, but that’s hardly where the interesting bit is.



  • One of the reasons I really disliked Reddit and stopped using it years ago was this way of using the voting system. If I make a post, and it gets voted something like +4-10, and a reply that is some rewording of “that’s a dumb statement”, what am I to think? I’m certainly not going to change my mind, no one gave me a good reason to.

    If one is voting because they feel they can’t stand behind their opinion if they expanded it in text… I don’t know what to tell ya.

    I’m inclined to believe a lot of people do this. This is not to say they are terrible for doing this, it’s that it’s human nature. Replying to someone with a well thought out post takes effort and, from my experience, makes the me realize i don’t know shit about the subject. Point is, this way of using the voting system breeds half-thought opinions which is a host of a lot of other problems.



  • I think wikis have already gotten there, at least for games. All of the game wikis have gotten consolidated into fandom/Wikia, which, from my experience, has enshittification levels that makes viewing Reddit from a phone browser feel likea slick experience. You can’t avoid it either. Wikis that used to be very good (at least compared to fandom, like gamepedia), have somehow gotten all pulled into the enshittification vacuum.

    A few days ago I was on the Minecraft wiki, but I was playing b1.7.3 so I was viewing it on wayback. And holy shit, before fandom bought out gamepedia (albeit I was looking at the pre-gamepedia wiki), the wiki was actually usable.


  • I’m not super familiar with the details of either (as I’ve gotten so used to the AUR having everything I might want), but I can say with some confidence that snap was rolled out in a way that doesn’t do it any favors.

    I have an old laptop that I occasionally boot into to do some stuff, but not super often. After an update, it appeared as though Firefox had forgotten everything; I wasn’t logged in, default start page, all settings reset, etc. I was super confused and mildly annoyed, but I set everything back up anyways. Then a bit later I ran Firefox again and it opened to what it was before the update??? Then I realized there were two installs, one apt and the other snap, and the latter was installed without my permission (or knowledge, maybe apt said in one of its 10k lines it spits out that ‘btw here’s a snap package’ that I was somehow supposed to notice).

    I find containerized packages really nice for things that are very dependant on how the system is setup but are unlikely to get updated if that system changes (either by me not updating it or it just going unmaintained). Firefox is not that though.