Toots for barubary@infosec.exchange account

Written by Füsilier Breitlinger on 2024-12-17 at 12:39

Finally figured out AoC day 12. In the end, I gave up and looked up what I now know is a "union-find" algorithm. But at least I recognized the connection between AoC 12 and HM type inference/unification, I guess.

Also, I'm not sure what's going on with the fence logic here. I mean, I can prove it correct, but shouldn't there be a more readable/simple way to express it?

use List::Util qw(sum0);

my $board = do { local $/; readline };

my $n = index $board, "\n";

$board =~ tr/\n//d;

my @regions;

my $representative = sub ($p) {

my $repr = $p;

while (defined(my $next = $regions[$repr]{repr})) {

    $repr = $next;

}

while ($p != $repr) {

    my $rr = \$regions[$p]{repr};

    ($p, $$rr) = ($$rr, $repr);

}

$repr

};

my $merge = sub ($p, $q) {

$p = $representative->($p);

$q = $representative->($q);

return if $p == $q;

if ($regions[$p]{area} > $regions[$q]{area}) {

    ($p, $q) = ($q, $p);

}

my $rp = $regions[$p];

my $rq = $regions[$q];

$rp->{repr} = $q;

$rq->{area} += $rp->{area};

$rq->{peri} += $rp->{peri};

};

my @fence = (

 4, 4,  4, 4,

 0, 0,  2, 2,

 0, 2,  2, 4,

-2, 0, -2, 0,

);

for my $p (0 .. length($board) - 1) {

my $t = substr $board, $p, 1;

my $c = $p % $n;

my @tbm;

my $fi = 0;

if ($p >= $n && $t eq substr $board, $p - $n, 1) {

    push @tbm, $p - $n;

    $fi |= 1;

}

$fi <<= 1;

if ($c > 0 && $t eq substr $board, $p - 1, 1) {

    push @tbm, $p - 1;

    $fi |= 1;

}

$fi <<= 1;

$fi |= 1 if $c > 0 && $p > $n && $t eq substr $board, $p - $n - 1, 1;

$fi <<= 1;

$fi |= 1 if $c < $n - 1 && $p >= $n && $t eq substr $board, $p - $n + 1, 1;

$regions[$p] = { area => 1, peri => $fence[$fi] };

$merge->($p, $_) for @tbm;

}

[#]for my $i (0 .. $#regions) {

[#] my $r = $regions[$i];

[#] next if defined $r->{repr};

[#] say substr($board, $i, 1) . ": $r->{area} * $r->{peri} = " . $r->{area} * $r->{peri};

[#]}

say sum0 map $->{area} * $->{peri}, grep !defined $_->{repr}, @regions;

#AdventOfCode #perl

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-12-11 at 12:00

/etc/sudörs

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-12-05 at 05:56

AoC day 5 in Perl. I'm not quite happy with the second loop. It feels a bit ad-hoc, like maybe there is a simpler algorithm waiting to be revealed. But it's not too bad, and it works:

use builtin qw(true);

my %after;

while (readline) {

chomp;

last if $_ eq '';

my ($fst, $snd) = /^ (\d+) \| (\d+) \z/xa

    or die "Malformed input: $_";

push @{$after{$fst}}, $snd;

}

my $good_total = 0;

my $bad_total = 0;

while (readline) {

chomp;

my @pgs = split /,/;

my $ok = true;

my (%seen, %before);

for my $pg (@pgs) {

    $seen{$pg} = true;

    for my $x (@{$after{$pg} // []}) {

        push @{$before{$x}}, $pg;

        $ok &&= !$seen{$x};

    }

}

my ($mid) = grep { @{$before{$_} // []} == $#pgs / 2 } @pgs;

${$ok ? \$good_total : \$bad_total} += $mid;

}

say $good_total;

say $bad_total;

#AdventOfCode #perl

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-12-04 at 18:35

AoC day 4. Still pretty simple to solve with a couple of regexes. The hardest part was remembering to add the g flag to all matches.

$_ = do { local $/; readline };

my $n = index $_, "\n";

my $m = $n - 1;

my $o = $n + 1;

say

+ (() = /XMAS/g)

+ (() = /SAMX/g)

+ (() = /X(?=.{$n}M.{$n}A.{$n}S)/sg)

+ (() = /S(?=.{$n}A.{$n}M.{$n}X)/sg)

+ (() = /X(?=.{$m}M.{$m}A.{$m}S)/sg)

+ (() = /S(?=.{$m}A.{$m}M.{$m}X)/sg)

+ (() = /X(?=.{$o}M.{$o}A.{$o}S)/sg)

+ (() = /S(?=.{$o}A.{$o}M.{$o}X)/sg)

;

say

+ (() = /M(?=.{$o}A.{$o}S)(?=[^\n]M.{$m}A.{$m}S)/sg)

+ (() = /M(?=.{$o}A.{$o}S)(?=[^\n]S.{$m}A.{$m}M)/sg)

+ (() = /S(?=.{$o}A.{$o}M)(?=[^\n]M.{$m}A.{$m}S)/sg)

+ (() = /S(?=.{$o}A.{$o}M)(?=[^\n]S.{$m}A.{$m}M)/sg)

;

#AdventOfCode #perl

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-12-03 at 20:16

Just for fun, here's a solution for day 3 of AoC written in standard C without using regexes:

[#]include <inttypes.h>

[#]include <stdbool.h>

[#]include <stdint.h>

[#]include <stdio.h>

[#]include <string.h>

typedef uint_least32_t u32x;

static u32x parse_uint(char **pp, const char *base) {

u32x n = 0, e = 1;

for (; *pp > base && isdigit((unsigned char)(*pp)[-1]); (*pp)--) {

    n += ((*pp)[-1] - '0') * e;

    e *= 10;

}

return n;

}

int main(void) {

u32x total = 0;

bool enabled = true;

char buf[4096];

while (fgets(buf, sizeof buf, stdin)) {

    for (char *p = buf; (p = strchr(p, ')')); p++) {

        if (enabled) {

            if (p >= buf + 6 && strncmp(p - 6, "don't(", 6) == 0) {

                enabled = false;

                continue;

            }

        } else {

            if (p >= buf + 3 && strncmp(p - 3, "do(", 3) == 0) {

                enabled = true;

            }

            continue;

        }

        char *t = p;

        const u32x b = parse_uint(&t, buf);

        if (*t == ')' || t == buf || t[-1] != ',') continue;

        t--;

        const u32x a = parse_uint(&t, buf);

        if (*t == ',' || t < buf + 4 || strncmp(t - 4, "mul(", 4) != 0) continue;

        total += a * b;

    }

}

printf("%" PRIuLEAST32 "\n", total);

}

#AdventOfCode #c

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-11-28 at 14:51

@hallo Nanu, was ist denn mit https://dashboard.uberspace.de/dashboard los? Ich kriege einen 500-Fehler.

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-11-26 at 11:31

@bfdi Ist so eine Negativ-Checkbox (Werbe-Opt-Out) eigentlich erlaubt?

(Gesehen im Online-Bestellformular von #lieferando.)

=> View attached media

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-11-25 at 19:02

Call me by your value

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-11-23 at 13:45

TIL if you load a page from x.com without allowing scripts from twimg.com, all you get is an obscure error page ("Something went wrong, try again") with no indication what the problem is. I guess it's hard to render short text posts without letting third parties execute arbitrary code on the visitor's computer.

[#]twitter

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-10-04 at 11:30

@jerry Ever since the last upgrade, the "new notifications" badge doesn't clear anymore when I check my notifications, even after I mark all notifications as seen manually. Do you know what's up with that?

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-09-24 at 22:30

Is Github forcing you to add "2FA" to your account, but you don't want to install another app? Turns out you can do TOTP 2FA from the command line.

When Github asks you to scan the QR code, look for the download link instead. Save the setup code in a file such as github_2fa.txt. Now when Github asks you for a security code, just run

to generate a 6-digit code.

[#]github #2fa #totp

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-08-03 at 18:29

How did I miss this? Perl has had a /n regex flag for almost a decade (added in 5.22.0), which makes parentheses do the right thing. Which is grouping things without capturing, as in math. Capturing is explicit under /n.

[#]perl #regex

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-07-31 at 20:25

null = \case(:){}->False;[]{}->True

#haskell

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-07-31 at 13:32

Acyclic paint

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-07-26 at 19:34

x && y | x = y | True = False

#haskell #logic

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-06-17 at 12:48

Another stealth benefit of upgrading to the latest version of Perl: Better detection of common errors through improved diagnostics.

https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8228

[#]perl #warnings

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-06-11 at 15:01

[#]poll

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-06-09 at 21:27

Perl 5.40.0 is out. 🎉

https://metacpan.org/release/HAARG/perl-5.40.0/view/pod/perldelta.pod

[#]perl

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-05-18 at 20:21

There are 10 types of people: binary and non-binary

=> More informations about this toot | View the thread

Written by Füsilier Breitlinger on 2024-04-28 at 14:49

Is there a good introduction to the ActiviityPub protocol, particularly the stuff used by Mastodon? Like, if I wanted to write my own Mastodon-like software from scratch, what should I read to get started?

[#]ActivityPub #Fediverse

=> More informations about this toot | View the thread

=> This profile with reblog | Go to barubary@infosec.exchange account

Proxy Information
Original URL
gemini://mastogem.picasoft.net/profile/109303300392077788
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
500.675196 milliseconds
Gemini-to-HTML Time
10.541592 milliseconds

This content has been proxied by September (ba2dc).