kartoffelsaft

joined 1 year ago
[–] kartoffelsaft 2 points 11 months ago

Did this in Odin (very hashed together, especially finding the last number in part 2):

spoiler

package day1

import "core:fmt"
import "core:strings"
import "core:strconv"
import "core:unicode"

p1 :: proc(input: []string) {
    total := 0

    for line in input {
        firstNum := line[strings.index_proc(line, unicode.is_digit):][:1]
        lastNum := line[strings.last_index_proc(line, unicode.is_digit):][:1]

        calibrationValue := strings.concatenate({firstNum, lastNum})
        defer delete(calibrationValue)

        num, ok := strconv.parse_int(calibrationValue)

        total += num
    }

    // daggonit thought it was the whole numbers
    /*
    for line in input {
        firstNum := line

        fFrom := strings.index_proc(firstNum, unicode.is_digit)
        firstNum = firstNum[fFrom:]

        fTo := strings.index_proc(firstNum, proc(r:rune)->bool {return !unicode.is_digit(r)})
        if fTo == -1 do fTo = len(firstNum)
        firstNum = firstNum[:fTo]


        lastNum := line
        lastNum = lastNum[:strings.last_index_proc(lastNum, unicode.is_digit)+1]
        lastNum = lastNum[strings.last_index_proc(lastNum, proc(r:rune)->bool {return !unicode.is_digit(r)})+1:]

        calibrationValue := strings.concatenate({firstNum, lastNum})
        defer delete(calibrationValue)

        num, ok := strconv.parse_int(calibrationValue, 10)
        if !ok {
            fmt.eprintf("%s could not be parsed from %s", calibrationValue, line)
            return
        }

        total += num;
    }
    */

    fmt.println(total)
}

p2 :: proc(input: []string) {
    parse_wordable :: proc(s: string) -> int {
        if len(s) == 1 {
            num, ok := strconv.parse_int(s)
            return num
        } else do switch s {
            case "one"  : return 1
            case "two"  : return 2
            case "three": return 3
            case "four" : return 4
            case "five" : return 5
            case "six"  : return 6
            case "seven": return 7
            case "eight": return 8
            case "nine" : return 9
        }

        return -1
    }

    total := 0

    for line in input {
        firstNumI, firstNumW := strings.index_multi(line, {
            "one"  , "1",
            "two"  , "2",
            "three", "3",
            "four" , "4",
            "five" , "5",
            "six"  , "6",
            "seven", "7",
            "eight", "8",
            "nine" , "9",
        })
        firstNum := line[firstNumI:][:firstNumW]


        // last_index_multi doesn't seem to exist, doing this as backup
        lastNumI, lastNumW := -1, -1
        for {
            nLastNumI, nLastNumW := strings.index_multi(line[lastNumI+1:], {
                "one"  , "1",
                "two"  , "2",
                "three", "3",
                "four" , "4",
                "five" , "5",
                "six"  , "6",
                "seven", "7",
                "eight", "8",
                "nine" , "9",
            })

            if nLastNumI == -1 do break

            lastNumI += nLastNumI+1
            lastNumW  = nLastNumW
        }
        lastNum := line[lastNumI:][:lastNumW]

        total += parse_wordable(firstNum)*10 + parse_wordable(lastNum)
    }

    fmt.println(total)
}

Had a ton of trouble with part 1 until I realized I misinterpreted it. Especially annoying because the example was working fine. So paradoxically part 2 was easier than 1.

[–] kartoffelsaft 5 points 1 year ago

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.

[–] kartoffelsaft 5 points 1 year ago* (last edited 1 year ago) (1 children)

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.

[–] kartoffelsaft 1 points 1 year ago

I just saw the second clue and realized the stuff I've been building might cause some misdirection. Guessing that clue will be harder to figure out than intended 🀷.

[–] kartoffelsaft 3 points 1 year ago

To be fair, that post specifically asks people who don't have a technical background. It can be used to show that laymen have the capacity to use a federated platform like lemmy, but not that they are a significant portion of the userbase (albeit that post does have a lot of replies).

[–] kartoffelsaft 1 points 1 year ago

One library I've become very fond of using is Raylib. It has a ridiculously simple interface. If you just want to program a game and don't want/need the details of OpenGL/Vulkan/DirectX (which I'd suggest you do at some point anyways), then It'd be my pick.

[–] kartoffelsaft 5 points 1 year ago (1 children)

It's a setting you can change. The default is a "quick generation" mode which looks as similar to the world seed/settings as it can without taking the performance hit of actually generating it. But it can either be changed to generate the chunks genuinely out to the render distance (which would be lag hell for 128 chunks) or to only render already generated chunks (like you suspect). Only the latter works in multiplayer though.

[–] kartoffelsaft 1 points 1 year ago

Huh. When I took Calculus II in community college, the professor introduced sum notation and like 2/3 of the class was like "wow that's cool I didn't know about that". I don't remember ever being formally taught it before that but it still surprises be how few people where already familiar with it.

[–] kartoffelsaft 2 points 1 year ago

I haven't actually. I'll go do that now.

[–] kartoffelsaft 2 points 1 year ago* (last edited 1 year ago) (1 children)

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.

[–] kartoffelsaft 1 points 1 year ago (3 children)

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'

hintsome of the escape sequences move the cursor

full explanationgenerates 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.

[–] kartoffelsaft 2 points 1 year ago (1 children)

There is this excellent video which shows how a simple C program looks in assembly (don't worry about it being C, the program is simple enough to be understood without C knowledge). There's also this which does what the video shows automatically for you. Neither of these are fully sufficient to understand assembly but they are still incredibly useful resources.

Also: watch out for AT&T syntax vs Intel syntax if you're doing x86. It took me way to long to figure this out. And as another commenter mentioned look at TIS-100, but also some other similar games (sorted from easiest to hardest, TIS being harder than all of these): Human resource machine, EXAPUNKS, Shezhen I/O, and Box-256

view more: β€Ή prev next β€Ί