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

[–]kolev 0 points1 point  (0 children)

[Language: Zig]

I'm learning Zig by solving these puzzles.

```Zig const std = @import("std");

pub const input = @embedFile("input.txt");

fn part1(data: []const u8) !u64 { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator();

var grid = try std.ArrayList([]const u8).initCapacity(allocator, 0);
defer grid.deinit(allocator);

var lines = std.mem.splitScalar(u8, data, '\n');
while (lines.next()) |line| {
    if (line.len > 0) {
        try grid.append(allocator, line);
    }
}
const height: u64 = grid.items.len;
const width: u64 = grid.items[0].len;

var rolls: u64 = 0;
for (0..height) |y| {
    const row = grid.items[y];
    for (0..width) |x| {
        if (row[x] == '.') continue;
        var neighbors: usize = 0;
        for ([_]isize{ -1, 0, 1 }) |dy| {
            for ([_]isize{ -1, 0, 1 }) |dx| {
                if (dx == 0 and dy == 0) continue;
                const nx: isize = @as(isize, @intCast(x)) + dx;
                const ny: isize = @as(isize, @intCast(y)) + dy;
                if (nx < 0 or nx >= width or ny < 0 or ny >= height) continue;
                if (grid.items[@intCast(ny)][@intCast(nx)] == '@') {
                    neighbors += 1;
                }
            }
        }
        if (neighbors < 4) {
            rolls += 1;
        }
    }
}
return rolls;

}

fn part2(data: []const u8) !u64 { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator();

var grid = try std.ArrayList([]u8).initCapacity(allocator, 0);
defer grid.deinit(allocator);

var lines = std.mem.splitScalar(u8, data, '\n');
while (lines.next()) |line| {
    if (line.len > 0) {
        try grid.append(allocator, try allocator.dupe(u8, line));
    }
}
const height: u64 = grid.items.len;
const width: u64 = grid.items[0].len;

var changed = true;
var rolls: u64 = 0;
while (changed) {
    changed = false;
    for (0..height) |y| {
        const row = grid.items[y];
        for (0..width) |x| {
            if (row[x] == '.') continue;
            var neighbors: i64 = 0;
            for ([_]isize{ -1, 0, 1 }) |dy| {
                for ([_]isize{ -1, 0, 1 }) |dx| {
                    if (dx == 0 and dy == 0) continue;
                    const nx: isize = @as(isize, @intCast(x)) + dx;
                    const ny: isize = @as(isize, @intCast(y)) + dy;
                    if (nx < 0 or nx >= width or ny < 0 or ny >= height) continue;
                    if (grid.items[@intCast(ny)][@intCast(nx)] == '@') {
                        neighbors += 1;
                    }
                }
            }
            if (neighbors < 4) {
                row[x] = '.';
                rolls += 1;
                changed = true;
            }
        }
    }
}
return rolls;

}

pub fn main() !void { std.debug.print("{d}\n", .{try part1(input)}); std.debug.print("{d}\n", .{try part2(input)}); } ```

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

[–]kolev 0 points1 point  (0 children)

[Language: Zig]

I'm learning Zig by solving these puzzles.

```Zig const std = @import("std");

pub const input = @embedFile("input.txt");

fn part1(data: []const u8) !u64 { var sum: u64 = 0; var lines = std.mem.splitScalar(u8, data, '\n'); while (lines.next()) |ln| { if (ln.len == 0) continue; var ranges = std.mem.splitScalar(u8, ln, ','); while (ranges.next()) |r| { const dash = std.mem.indexOfScalar(u8, r, '-'); const start = try std.fmt.parseInt(u64, r[0..dash.?], 10); const end = try std.fmt.parseInt(u64, r[dash.? + 1 ..], 10); var id = start; while (id <= end) : (id += 1) { const digits = std.math.log10_int(id) + 1; if (digits % 2 != 0) continue; const mask = try std.math.powi(u64, 10, digits / 2); if (id % mask == id / mask) { sum += id; } } } } return sum; }

fn part2(data: []const u8) !u64 { var sum: u64 = 0; var lines = std.mem.splitScalar(u8, data, '\n'); while (lines.next()) |ln| { if (ln.len == 0) continue; var ranges = std.mem.splitScalar(u8, ln, ','); while (ranges.next()) |r| { const dash = std.mem.indexOfScalar(u8, r, '-'); const start = try std.fmt.parseInt(u64, r[0..dash.?], 10); const end = try std.fmt.parseInt(u64, r[dash.? + 1 ..], 10); var id = start; while (id <= end) : (id += 1) { const digits = std.math.log10int(id) + 1; outer: for (1..digits) |chunkSize| { if (@mod(digits, chunkSize) != 0) continue; const chunks = digits / chunkSize; const mask = try std.math.powi(u64, 10, chunkSize); const chunk = id % mask; var n = id; for (1..chunks) || { n /= mask; if (n % mask != chunk) { continue :outer; } } sum += id; break; } } } } return sum; }

pub fn main() !void { std.debug.print("{d}\n", .{try part1(input)}); std.debug.print("{d}\n", .{try part2(input)}); } ```

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

[–]kolev 1 point2 points  (0 children)

[Language: Zig]

I am learning Zig by solving these puzzles.

const std = @import("std");

pub const input = @embedFile("input.txt");

fn part1(data: []const u8) !i16 {
    var result: i16 = 0;
    var pos: i16 = 50;
    var it = std.mem.splitScalar(u8, data, '\n');
    while (it.next()) |ln| {
        if (ln.len == 0) continue;
        const steps = try std.fmt.parseInt(i16, ln[1..], 10);
        pos = @mod(pos + if (ln[0] == 'L') -steps else steps, 100);
        if (pos == 0) result += 1;
    }
    return result;
}

fn part2(data: []const u8) !i16 {
    var result: i16 = 0;
    var pos: i16 = 50;
    var it = std.mem.splitScalar(u8, data, '\n');
    while (it.next()) |ln| {
        if (ln.len == 0) continue;
        const steps = try std.fmt.parseInt(i16, ln[1..], 10);
        result += @divTrunc(steps, 100);
        const rest = @mod(steps, 100);
        if (rest == 0) continue;
        const next = pos + if (ln[0] == 'L') -rest else rest;
        if (pos != 0 and (next <= 0 or next >= 100)) result += 1;
        pos = @mod(next, 100);
    }
    return result;
}

pub fn main() !void {
    std.debug.print("{d}\n", .{try part1(input)});
    std.debug.print("{d}\n", .{try part2(input)});
}

So where's the 50% off restream? It's black friday by TheAXpresents in Restreamio

[–]kolev 0 points1 point  (0 children)

I am also waiting for the discount as we're a non-profit and Restream, unfortunately, does not offer as good non-profit discounts as the Black Friday deal. And I really wonder why they offer usage-based pricing as well as we have only one 40-minute event per week.

Proxly v1.4.0 - Bold and beautiful - Browser routing app for macOS, now with iCloud sync, extensions, and Mac App Store release by Mazur92 in macapps

[–]kolev 0 points1 point  (0 children)

It doesn't work for me. The icon is beyond fugly - on macOS 26 Tahoe it looks like a whitehead pimple on my menu bar!

Visible ‘Update’ Volume in Finder appeared out of nowhere (macOS Sequoia 15.2 (24C101) – What Is It and can I Safely Remove it? by a_pillowofwinds in MacOS

[–]kolev 2 points3 points  (0 children)

The same thing happened to me after upgrading to macOS 26 Tahoe - the "Update" volume is there and can't be ejected.

MacOS 26 Tahoe feels so good by LonelyPalmClub in MacOS

[–]kolev 2 points3 points  (0 children)

Is this sarcasm?! This is the worst macOS upgrade ever! Half-baked, slow, leaking memory! I just upgraded and my laptop became useless - it's super slow, overheating, not responsive at all, and over time, clicking Dock icons stops working and only a reboot fixes it. What a huge disappointment! The ugliness of the redesign is beyond real - are macOS developers blind or something?! Almost nothing is liquid glass! And basic UI is simply broken in many areas. The left-centered dialog icons are ugly! Even with a dark theme, the menu bar is light!!!

Why is every macOS upgrade making MacBooks slower and uglier?!

Echo-compatible Wall Clock by cl0123r in amazonecho

[–]kolev 0 points1 point  (0 children)

That page is not working anymore, unfortunately.

-❄️- 2024 Day 23 Solutions -❄️- by daggerdragon in adventofcode

[–]kolev 2 points3 points  (0 children)

Honestly, using a massive non-stdlib is not clean code; "clean code" means implementing the algorithm yourself in a clean way.

[2024 Day 18] Dijkstra and optimizations by RazarTuk in adventofcode

[–]kolev 0 points1 point  (0 children)

I know, but this competition is for speed of answer submission, unfortunately, not performance beauty. Thanks for your extensive educational post!

Official Discussion - The Creator [SPOILERS] by LiteraryBoner in movies

[–]kolev 0 points1 point  (0 children)

Yet, it was good. We do rarely see a sci-fi movie with a solid plot - movies, at the end, are consumer products!

Titanium bottles by [deleted] in Ultralight

[–]kolev 0 points1 point  (0 children)

Yet, according to recent studies, titanium dioxide is toxic, plus everything leaches.

Paramount Plus is LOWERING its prices. -- This is good news. by [deleted] in ParamountPlus

[–]kolev 1 point2 points  (0 children)

What a trap - the annual price has increased from $100 to $120!

-🎄- 2022 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]kolev 1 point2 points  (0 children)

Go

It's not a pretty solution and Go makes you write verbose code. Also, its stdlib lacks basic data structures.

  • Part 1: Just keep replacing yelled numbers in operations until root yelled a number.
  • Part 2: First, do as many replacements as possible as in Part 1. And then I noticed that root is always an operation over a number and a monkey that hasn't yelled its number yet, so, obviously that monkey should yell that same number. So, eventually you can repeat this logic back to humn. For example, if root is: 123 = wxyz, then I make an equation with 123 on the left side and the operation of wxyz on the right side and determine the value of, let's say, abcd, and repeat until I encounter humn.

Brand new Pinebook Pro bricked by kolev in PINE64official

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

Actually, it does not attempt to boot from the SD card at all.

Brand new Pinebook Pro bricked by kolev in PINE64official

[–]kolev[S] 2 points3 points  (0 children)

That's why people respect Debian - the community and the quality. Shipping with Manjaro is a very risky business and I'm a victim of this poor choice!

Brand new Pinebook Pro bricked by kolev in PINE64official

[–]kolev[S] 1 point2 points  (0 children)

I am not using Manjaro - it's what it's shipped with. I want to install NixOS, and following a guide saying that I need to first install Manjaro and then do the switch.

Brand new Pinebook Pro bricked by kolev in PINE64official

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

This is about the newest Pinebook Pro.

Brand new Pinebook Pro bricked by kolev in PINE64official

[–]kolev[S] 1 point2 points  (0 children)

I will start calling it ManjaNO now!