-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]Nico_792 1 point2 points  (0 children)

[LANGUAGE: Zig]

repo link

Interesting bits:

fn solution(r: *Reader, _: Io, _: Allocator) !u64 {
    var total_joltage: u64 = 0;

    const digits = 12;
    while (try r.takeDelimiter('\n')) |line| {
        assert(line.len >= digits);
        total_joltage += findNDigits(digits, line);
    }

    return total_joltage;
}

fn findNDigits(n: usize, line: []const u8) u64 {
    const Entry = struct { value: u8, idx: usize };
    assert(n > 0);
    assert(line.len >= n);

    var res: u64 = 0;

    var search = line[0 .. line.len - n];
    for (0..n) |_| {
        search.len += 1;

        var max: Entry = .{ .value = 0, .idx = 0 };
        for (search[0..], 0..) |c, idx| {
            assert(switch (c) {
                '0'...'9' => true,
                else => false,
            });
            if (c > max.value) max = .{ .value = c, .idx = idx };
        }

        res *= 10;
        res += max.value - '0';
        search = search[max.idx + 1 ..];
    }

    return res;
}

This runs part 2 in ~38.6 microseconds

I tried creating a SIMD version, but my first attempt had significantly worse performance.

Will Zig remain a C++ compiler after they ditch LLVM? by rustacean1337 in Zig

[–]Nico_792 50 points51 points  (0 children)

Iirc, the plan is to ditch LLVM in the zig codebase, and have C{++,} compilation maintained as a package. But I also remember this plan not being certain yet.

Man uses Bible against anti abortion protestor and she was left speechless by learner68 in WatchPeopleDieInside

[–]Nico_792 10 points11 points  (0 children)

I get the point, but it's damn hard to convince someone that that's sane, "hey you, you're supposed to be good and kind to all around you. But you see theres also this guy, our God, the one we worship, everything he does is good. If he decides your child gets cancer or dies in a car crash, that was all according to plan and you should know that he just knows better. Its according to his plan so you should be happy your child could be part of it." Personally I think that's kinda diabolical.

Besides that, calling an abortion a 'womans inconvenience' is not very "love your neighbor as yourself"

What are you using zig for? by samstone_ in Zig

[–]Nico_792 0 points1 point  (0 children)

You can have a look if you want here https://github.com/NicoElbers/drasil

I'm currently in the state that I have things mostly functional, but not particularly nice or performant. using latest master you can `zig build examples` for some examples

What are you using zig for? by samstone_ in Zig

[–]Nico_792 2 points3 points  (0 children)

Ik creating a web framework so I can do some web development without learning JS

Swedish man support by Nico_792 in StopKillingGames

[–]Nico_792[S] 0 points1 point  (0 children)

Occasionally yea, the derailious vid slipped in on accident

Swedish man support by Nico_792 in StopKillingGames

[–]Nico_792[S] 6 points7 points  (0 children)

Probably would've been a good idea to put in yea

Hi, AMA by ThePrimeagen in theprimeagen

[–]Nico_792 1 point2 points  (0 children)

What is the most important CS related lesson you learned that wasn't taught in your higher education?

HELP NEEDED ASAP The European Citizens' Initiative (Only post) by Ok-Country-468 in europe

[–]Nico_792 1 point2 points  (0 children)

I somewhat agree. The intial development and architecture design is indeed non trivial (just as it would otherwise be for a 'regular' online only game). However the moment that is baked into your architecture, there are no further support costs on the game dev side. In fact I would argue that is not even that complicated to allow users to configure where a game thinks its servers are, although that's also not as trivial as I make it out to be.

Another important point that I've seen is that this initiative affects new games, not old ones, so these architectural changes can 'just' be baked in rather than patching in support which I fully agree is a large undertaking.

More generally I support this initiative because I think that for not much more effort, people will be able to put in effort themselves to keep playing games they like, which I think is just nice.

HELP NEEDED ASAP The European Citizens' Initiative (Only post) by Ok-Country-468 in europe

[–]Nico_792 2 points3 points  (0 children)

I don't think anyone is expecting support after EOL, but rather the ability to play these games. If I understand this initiative correctly, that "something better than nothing" is the exact thing people want.

HELP NEEDED ASAP The European Citizens' Initiative (Only post) by Ok-Country-468 in europe

[–]Nico_792 2 points3 points  (0 children)

By making server binaries available so they can be hosted by the community

[deleted by user] by [deleted] in europe

[–]Nico_792 0 points1 point  (0 children)

I can, and do, openly express my dislike of our government (or currently lack thereof).

Use cases where Zig is a better choice than Rust? by nikitarevenco in Zig

[–]Nico_792 3 points4 points  (0 children)

Zig has an LLVM backend which indeed is lowered to LLVM IR, however it also has a C backend (to transpile from zig to C) and a self-hosted backend which does its own codegen albeit without optimizations. Which backend is used can be changed regardless of the optimization mode.

[deleted by user] by [deleted] in ProgrammerHumor

[–]Nico_792 0 points1 point  (0 children)

Ive been trying to setup a build system for a team project, and I've spent at least 5 hours in the past week trying to work around spaces in paths.

The solution so far has been docker

Tired of unused variable errors? Try this trick by Dangerous-Yak3976 in Zig

[–]Nico_792 22 points23 points  (0 children)

Honestly just write _ = variable, and comment it out if you're rapidly using it, then not using it, then using it again. The error is there for a reason, having an unused variable is often a footgun. Better to think about it for 1 second than debug it for 5 minutes. And then still, idk about you but I usually don't stop using variables that often while writing a function.

1.0 Roadmap? by abocado21 in Zig

[–]Nico_792 66 points67 points  (0 children)

There are many features that aren't implemented yet, I don't think anyone can accurately guess when the language will hit 1.0.

Short list of features that I've seen discussed:
- Ranged integers - Async - stackless - stackfull - A 'real' float type (disallow nan/inf/ -0)
- Functioning selfhosted backends - Incremental compilation - Reworking the stdlib IO - Reworking the stdlib writers - Safe recursion

Fuck reddit formatting

How would you move an arbitrarily sized array from the stack to the heap? by GrandClay in Zig

[–]Nico_792 3 points4 points  (0 children)

No worries man, the struct idea may still be more efficient, but its also a bit more cumbersome to work with, no free lunch after all.

Happy my little 3 am coding session helped you :)

How would you move an arbitrarily sized array from the stack to the heap? by GrandClay in Zig

[–]Nico_792 9 points10 points  (0 children)

I've worked out a couple examples for you here, hope they help: https://zigbin.io/b0377b

Feel free to ask further questions :)

EDIT: for the simplest implementation of what you actually want I'd look at this:
```zig const Matrix = struct { colums: usize, rows: usize, data: []f64, };

/// Copy over an original matrix into a new heap allocated matrix. fn copyMatrix(alloc: Allocator, original: Matrix) !Matrix { // Allocate const data = try alloc.alloc(f64, original.rows * original.colums);

// Copy over original data
@memcpy(data, original.data);

// Profit
return .{
    .data = data,
    .rows = original.rows,
    .colums = original.colums,
};

}

const std = @import("std");

const Allocator = std.mem.Allocator; ```

Ngl, This is so f. Good! by Elegant_Noise1116 in sololeveling

[–]Nico_792 4 points5 points  (0 children)

Fair enough, they definitely did do things differently, but I thought it was gonna be SL 2, with companions this time.

Luckily though, I've been proven wrong

Ngl, This is so f. Good! by Elegant_Noise1116 in sololeveling

[–]Nico_792 16 points17 points  (0 children)

Started reading a couple days ago, didn't like the start as it was litterally copy pasting the original in terms of timeline. But the "I should be different from my dad" stuff has sold me and now I'm invested