Crestwave's recent activity

  1. Comment on Day 6: Universal Orbit Map in ~comp.advent_of_code

    Crestwave
    Link Parent
    Well, it depends how you look at it! I didn't pay any mind to the leaderboard for most of the challenges, especially since I started on day 3. I just tried to get a decent place for once today....

    Well, it depends how you look at it! I didn't pay any mind to the leaderboard for most of the challenges, especially since I started on day 3. I just tried to get a decent place for once today.

    EDIT: Also, it isn't really fair, anyway, since it opens at the same time which would be midnight and such in other timezones, so I wouldn't really sweat it.

    2 votes
  2. Comment on Day 6: Universal Orbit Map in ~comp.advent_of_code

    Crestwave
    (edited )
    Link
    Well, today's challenge seemed pretty easy. Unfortunately, I got stuck for a bit because I put my parsing on the iteration block instead of END and made a typo on my answer. Here are my very hacky...

    Well, today's challenge seemed pretty easy. Unfortunately, I got stuck for a bit because I put my parsing on the iteration block instead of END and made a typo on my answer. Here are my very hacky solutions which I will clean up later:

    Part 1
    #!/usr/bin/awk -f
    {
        split($0, map, ")")
        orbits[map[2]] = map[1]
    }
    
    END {
        for (i in orbits)
            for (;;)
                if (orbits[i]) {
                    i = orbits[i]
                    total += 1
                } else {
                    break
                }
    
        print total
    }
    
    Part 2
    #!/usr/bin/awk -f
    {
        split($0, map, ")")
        orbits[map[2]] = map[1]
    }
    
    END {
        i = orbits["SAN"]
        for (j = 0; j < 2; ++j) {
            for (;;)
                if (orbits[i]) {
                    i = orbits[i]
                    total += 1
    
                    if (transfers[i]) {
                        total += transfers[i]
                        break
                    } else {
                        transfers[i] += total
                    }
                } else {
                    break
                }
    
            if (! j) {
                total = 0
                i = orbits["YOU"]
            }
        }
    
        print total
    }
    

    EDIT: Cleaned up a bit, but part 2 is probably still pretty hacky. Too bad AWK can't break through multiple loops like Bash.

    EDIT 2: Settled for a less fancy but more readable solution.

    2 votes
  3. Comment on Day 5: Sunny with a Chance of Asteroids in ~comp.advent_of_code

    Crestwave
    (edited )
    Link
    This language is looking more and more like Brainfuck. I got stuck for a bit because I had the order of the modes reversed, then tried to solve it cleanly. Then I got impatient and just reversed...

    This language is looking more and more like Brainfuck. I got stuck for a bit because I had the order of the modes reversed, then tried to solve it cleanly. Then I got impatient and just reversed the string; I'll try to clean it up later.

    Part 1
    #!/usr/bin/awk -f
    { prog = prog $0 }
    
    END {
        split(prog, init, ",")
        for (i = 1; i <= length(init); ++i)
            mem[i-1] = init[i]
    
        for (ptr = 0; ptr < length(mem);) {
            split(substr(mem[ptr], 1, length(mem[ptr])-2), modes, "")
            c = int(substr(mem[ptr], length(mem[ptr])-1))
    
            for (i = 1; i <= 2; ++i)
                params[i] = modes[length(modes)-i+1] ? \
                    mem[ptr+i] : \
                    mem[mem[ptr+i]]
    
            if (c == 1) {
                mem[mem[ptr+3]] = params[1] + params[2]
                ptr += 4
            } else if (c == 2) {
                mem[mem[ptr+3]] = params[1] * params[2]
                ptr += 4
            } else if (c == 3) {
                getline input < "-"
                mem[mem[ptr+1]] = int(input)
                ptr += 2
            } else if (c == 4) {
                print params[1]
                ptr += 2
            } else if (c == 99) {
                break
            } else {
                exit(1)
            }
        }
    }
    
    Part 2
    #!/usr/bin/awk -f
    { prog = prog $0 }
    
    END {
        split(prog, init, ",")
        for (i = 1; i <= length(init); ++i)
            mem[i-1] = init[i]
    
        for (ptr = 0; ptr < length(mem);) {
            split(substr(mem[ptr], 1, length(mem[ptr])-2), modes, "")
            c = int(substr(mem[ptr], length(mem[ptr])-1))
    
            for (i = 1; i <= 2; ++i)
                params[i] = modes[length(modes)-i+1] ? \
                    mem[ptr+i] : \
                    mem[mem[ptr+i]]
    
            if (c == 1) {
                mem[mem[ptr+3]] = params[1] + params[2]
                ptr += 4
            } else if (c == 2) {
                mem[mem[ptr+3]] = params[1] * params[2]
                ptr += 4
            } else if (c == 3) {
                getline input < "-"
                mem[mem[ptr+1]] = int(input)
                ptr += 2
            } else if (c == 4) {
                print params[1]
                ptr += 2
            } else if (c == 5) {
                ptr = params[1] ? params[2] : ptr+3
            } else if (c == 6) {
                ptr = params[1] ? ptr+3 : params[2]
            } else if (c == 7) {
                mem[mem[ptr+3]] = params[1] < params[2]
                ptr += 4
            } else if (c == 8) {
                mem[mem[ptr+3]] = params[1] == params[2]
                ptr += 4
            } else if (c == 99) {
                break
            } else {
                exit(1)
            }
        }
    }
    

    EDIT: Okay, cleaned up; it's amazing what a short water break can do. I'm not sure if the method to read a line of input is POSIX, but it's compatible with gawk, lok, mawk, and nawk, so I think it's fine even if it isn't.

    2 votes
  4. Comment on Day 1: The Tyranny of the Rocket Equation in ~comp.advent_of_code

    Crestwave
    Link Parent
    I think you need an empty line between the summary and the code block

    I think you need an empty line between the summary and the code block

    1 vote
  5. Comment on Day 3: Crossed Wires in ~comp.advent_of_code

    Crestwave
    Link
    Okay, this was easier than I thought, although I got stuck for quite a bit because I forgot not to count a wire crossing with itself. It also took me a few minutes to figure out that it was only...

    Okay, this was easier than I thought, although I got stuck for quite a bit because I forgot not to count a wire crossing with itself. It also took me a few minutes to figure out that it was only interpreting the first digit of the direction because I didn't convert it into an integer; I'll have to look more into that. awk solutions:

    Part 1
    #!/usr/bin/awk -f
    {
        split($0, path, ",")
        wire += 1
        x = 0
        y = 0
    
        for (i = 1; i <= length(path); ++i) {
            c = substr(path[i], 1, 1)
            j = int(substr(path[i], 2))
            for (k = 0; k < j; ++k) {
                if (c == "U")
                    y += 1
                else if (c == "D")
                    y -= 1
                else if (c == "L")
                    x -= 1
                else if (c == "R")
                    x += 1
    
                if (grid[x","y] == wire-1)
                    grid[x","y] = wire
            }
        }
    }
    
    END {
        nearest = 0
        for (i in grid) {
            if (grid[i] == 2) {
                split(i, coordinates, ",")
                for (j = 1; j <= 2; ++j)
                    sub(/^-/, "", coordinates[j])
    
                distance = int(coordinates[1]) + int(coordinates[2])
                if (distance < nearest || nearest == 0)
                    nearest = distance
            }
        }
    
        print nearest
    }
    
    Part 2
    #!/usr/bin/awk -f
    {
        split($0, path, ",")
        wire += 1
        step = 0
        x = 0
        y = 0
    
        for (i = 1; i <= length(path); ++i) {
            c = substr(path[i], 1, 1)
            j = int(substr(path[i], 2))
            for (k = 0; k < j; ++k) {
                step += 1
                if (c == "U")
                    y += 1
                else if (c == "D")
                    y -= 1
                else if (c == "L")
                    x -= 1
                else if (c == "R")
                    x += 1
    
                if (grid[x","y] == wire-1) {
                    grid[x","y] = wire
                    steps[x","y] += step
                }
            }
        }
    }
    
    END {
        nearest = 0
        for (i in grid)
            if (grid[i] == 2)
                if (steps[i] < nearest || nearest == 0)
                    nearest = steps[i]
    
        print nearest
    }
    
    1 vote
  6. Comment on Day 4: Secure Container in ~comp.advent_of_code

    Crestwave
    Link
    Whew, I thought it was almost getting too hard for me with yesterday's challenge, but this one seems much easier. Here's a quick and dirty awk implementation; might clean it up a bit later. Part 1...

    Whew, I thought it was almost getting too hard for me with yesterday's challenge, but this one seems much easier. Here's a quick and dirty awk implementation; might clean it up a bit later.

    Part 1
    #!/usr/bin/awk -f
    {
        split($0, range, "-")
        for (i = range[1]; i < range[2]; ++i) {
            for (j = 1; j < length(i); ++j) {
                if (substr(i, j, 1) == substr(i, j+1, 1))
                    double = 1
    
                if (substr(i, j, 1) > substr(i, j+1, 1)) {
                    double = 0
                    break
                }
            }
    
            unique += double
            double = 0
        }
    
        print unique
    }
    
    Part 2

    The same as part 1, except with line 6 extended to this:

    if (substr(i, j, 1) == substr(i, j+1, 1) && substr(i, j+2, 1) != substr(i, j, 1) && (j == 1 || substr(i, j-1, 1) != substr(i, j, 1)))
    

    Yes, I meant it when I said quick and dirty.

    2 votes
  7. Comment on Day 2: 1202 Program Alarm in ~comp.advent_of_code

    Crestwave
    (edited )
    Link
    Using awk again. Part 2 #!/usr/bin/awk -f { prog = prog $0 } END { split(prog, init, ",") for (i = 0; i < 100; ++i) { for (j = 0; j < 100; ++j) { for (k = 1; k <= length(init); ++k) mem[k-1] =...

    Using awk again.

    Part 2
    #!/usr/bin/awk -f
    { prog = prog $0 }
    
    END {
        split(prog, init, ",")
        for (i = 0; i < 100; ++i) {
            for (j = 0; j < 100; ++j) {
                for (k = 1; k <= length(init); ++k)
                    mem[k-1] = init[k]
    
                mem[1] = i
                mem[2] = j
    
                for (ptr = 0; ptr < length(mem); ptr += 4) {
                    if (mem[ptr] == 1) {
                        mem[mem[ptr+3]] = mem[mem[ptr+1]] + mem[mem[ptr+2]]
                    } else if (mem[ptr] == 2) {
                        mem[mem[ptr+3]] = mem[mem[ptr+1]] * mem[mem[ptr+2]]
                    } else if (mem[ptr] == 99) {
                        break
                    } else {
                        exit(1)
                    }
                }
    
                if (mem[0] == 19690720) {
                    print 100 * i + j
                    exit
                }
            }
        }
    }
    
    3 votes
  8. Comment on Day 1: The Tyranny of the Rocket Equation in ~comp.advent_of_code

    Crestwave
    Link
    Quick awk solution. Part 1 #!/usr/bin/awk -f { sum += int($0/3) - 2 } END { print sum } Part 2 #!/usr/bin/awk -f { mass = $0 for (;;) { mass = int(mass/3) - 2 if (mass < 0) break sum += mass } }...

    Quick awk solution.

    Part 1
    #!/usr/bin/awk -f
    { sum += int($0/3) - 2 }
    END { print sum }
    
    Part 2
    #!/usr/bin/awk -f
    {
        mass = $0
        for (;;) {
            mass = int(mass/3) - 2
            if (mass < 0)
                break
            sum += mass
        }
    }
    
    END { print sum }
    
    2 votes
  9. Comment on Day 2: 1202 Program Alarm in ~comp.advent_of_code

    Crestwave
    Link Parent
    Befunge is an esolang that was designed to be as difficult to compile as possible: https://esolangs.org/wiki/Befunge

    Befunge is an esolang that was designed to be as difficult to compile as possible: https://esolangs.org/wiki/Befunge

    1 vote
  10. Comment on Redox OS: Real hardware breakthroughs, and focusing on rustc in ~comp

    Crestwave
    Link Parent
    I'm not entirely sure what you mean by that. They have a Mattermost instance where you can easily join and chat on concepts and such, and Ion (the shell) and OrbTk (the UI toolkit) run on numerous...

    I'm not entirely sure what you mean by that. They have a Mattermost instance where you can easily join and chat on concepts and such, and Ion (the shell) and OrbTk (the UI toolkit) run on numerous platforms.

    2 votes
  11. Comment on The Sad Saga of Purism and the Librem 5 (Part 1) in ~tech

    Crestwave
    Link Parent
    Well, there's also the PinePhone, which looks more promising at this point.

    Well, there's also the PinePhone, which looks more promising at this point.

    2 votes
  12. Comment on I want to learn programming. What language should i pick to write cli apps for linux? in ~comp

    Crestwave
    Link Parent
    Bash has arrays and associative arrays. You can use them then store them in a file and source it.

    Bash has arrays and associative arrays. You can use them then store them in a file and source it.

    1 vote
  13. Comment on The Open Book - An open source device for reading in ~comp

    Crestwave
    Link Parent
    They're aiming for an alternative to e-readers or maybe iPads used for reading; laptops aren't exactly comfortable to read books with IMO, and the RPI doesn't even come with a screen. Also, the...

    I mean I don't disagree, but there's no lack of open hardware that can read ePubs. There are open source phones, open source laptops, raspberry pi's, hell you can probably find a riscv-based computers. The bar isn't very high.

    They're aiming for an alternative to e-readers or maybe iPads used for reading; laptops aren't exactly comfortable to read books with IMO, and the RPI doesn't even come with a screen. Also, the RPI isn't open hardware, and I don't know of any open phone that's really available right now.

    6 votes
  14. Comment on Adblocking for Android Smart Phone? in ~comp

    Crestwave
    Link Parent
    Pi-hole cannot effectively block YouTube ads because they serve them from the same domain as the videos.

    Pi-hole cannot effectively block YouTube ads because they serve them from the same domain as the videos.

  15. Comment on Please recommend me a Linux distribution that is super-stable and never make me install again, but at the same time allows me to have some newer packages with ease (xpost /r/FindMeADistro) in ~comp

    Crestwave
    Link
    Late to the party, but most of the answers don't really seem to be addressing your specific concern. If I'm understanding correctly and you want a system that is mostly stable as in frozen, but...

    Late to the party, but most of the answers don't really seem to be addressing your specific concern. If I'm understanding correctly and you want a system that is mostly stable as in frozen, but with the ability to get newer packages, Debian Stable with backports or another branch fits the bill perfectly. I myself got i3wm from Testing on a Stable system back when I used it, although I heard that mixing releases (not backports) may cause instability.

    Flatpak can work for some things, but it's sandboxed, so I don't think i3wm and such will run on it. Another option is the Nix package manager; you mentioned above that you don't want to learn the Nix language for NixOS, but you don't have to learn it for this as far as I know. You can install it on a stable distribution and get up-to-date packages from it.

    Another option is Bedrock Linux. It allows you to run multiple distributions at once, (nearly) seamlessly integrated, so you can use most of your tools from a stable distribution and get new packages from an unstable one.

    However, note that it hasn't reached 1.0 yet, so while it's perfectly usable right now (I use it on my main system), it's possible that there will be a breaking update where you'd have to reinstall to migrate to it. But you can still use your outdated system if you don't mind missing out on the new features; I ran the previous major release for a few months before migrating, because there wasn't any update mechanism at all back then.

    2 votes
  16. Comment on Intimate documentary on Mekorama creator highlights the joys and frustrations of mobile game development in ~games.game_design

    Crestwave
    Link
    I love Mekorama and Fancade and would hate to see the latter fail monetarily, too. Unfortunately, the trends in profitable mobile games right now are loot boxes and such. Any ideas for a better...

    I love Mekorama and Fancade and would hate to see the latter fail monetarily, too. Unfortunately, the trends in profitable mobile games right now are loot boxes and such. Any ideas for a better balance between that and Pay What You Want?

  17. Comment on Linux Distro for an old PC in ~comp

    Crestwave
    Link
    Late to this, but in case you're still working on it, Tiny Core, the most minimal distribution I know (that's still in development) doesn't seem to have been mentioned in this thread. The...

    Late to this, but in case you're still working on it, Tiny Core, the most minimal distribution I know (that's still in development) doesn't seem to have been mentioned in this thread. The graphical image is just 16 MB, and it loads into RAM so it's lightning fast. Despite that, it doesn't use much RAM; the base graphical installation used less than 50 MB running, if I remember correctly (<100 I'm sure).

    My other recommendations would be Alpine, Puppy (though everything runs as root there IIRC), Void, Slackware, etc. Also, have you tried the minimal installation of Debian? I've never tried the full installation and I'm surprised to hear it described as way too heavy for it.

    1 vote
  18. Comment on Linux Distro for an old PC in ~comp

    Crestwave
    Link Parent
    Late, but I don't think Haiku will run well with <512 MB of RAM now (Alpha4 should work).

    Late, but I don't think Haiku will run well with <512 MB of RAM now (Alpha4 should work).