• 18 Posts
  • 95 Comments
Joined 1 year ago
cake
Cake day: June 10th, 2023

help-circle
  • Raku

    Oof, my struggle to make custom index walking paths for part 1 did not pay off for part 2.

    Solution
    sub MAIN($input) {
        my $file = (open $input).slurp;
        my @grid is List = $file.lines».comb».list;
        my @transposedGrid is List = [Z] @grid;
        my @reversedGrid is List = @grid».reverse;
        my @transposedReversedGrid is List = @transposedGrid».reverse;
    
        my @horizontalScanRows is List = generateScanHorizontal(@grid);
        my @transposedHorizontalScanRows is List = generateScanHorizontal(@transposedGrid);
    
        my @part-one-counts = [];
        @part-one-counts.push(count-xmas(@grid, @horizontalScanRows)); # Right
        @part-one-counts.push(count-xmas(@transposedGrid, @transposedHorizontalScanRows)); # Down
        @part-one-counts.push(count-xmas(@reversedGrid, @horizontalScanRows)); # Left
        @part-one-counts.push(count-xmas(@transposedReversedGrid, @transposedHorizontalScanRows)); # Up
    
        my @diagonalScanRows is List = generateScanDiagonal(@grid);
        my @transposedDiagonalScanRows is List = generateScanDiagonal(@transposedGrid);
        @part-one-counts.push(count-xmas(@grid, @diagonalScanRows)); # Down Right
        @part-one-counts.push(count-xmas(@grid, @diagonalScanRows».reverse)); # Up Left
        @part-one-counts.push(count-xmas(@reversedGrid, @diagonalScanRows)); # Down Left
        @part-one-counts.push(count-xmas(@reversedGrid, @diagonalScanRows».reverse)); # Up Right
    
        my $part-one-solution = @part-one-counts.sum;
        say "part 1: $part-one-solution";
    
    
        my @part-two-counts = [];
        @part-two-counts.push(countGridMatches(@grid, (<M . S>,<. A .>,<M . S>)));
        @part-two-counts.push(countGridMatches(@grid, (<S . S>,<. A .>,<M . M>)));
        @part-two-counts.push(countGridMatches(@grid, (<S . M>,<. A .>,<S . M>)));
        @part-two-counts.push(countGridMatches(@grid, (<M . M>,<. A .>,<S . S>)));
    
        my $part-two-solution = @part-two-counts.sum;
        say "part 2: $part-two-solution";
    
    }
    
    sub count-xmas(@grid, @scanRows) {
        my $xmas-count = 0;
        for @scanRows -> @scanRow {
            my $xmas-pos = 0;
            for @scanRow -> @pos {
                my $char = @grid[@pos[0]][@pos[1]];
                if "X" eq $char {
                    $xmas-pos = 1;
                }elsif <X M A S>[$xmas-pos] eq $char {
                    if $xmas-pos == 3 {
                        $xmas-pos = 0;
                        $xmas-count += 1;
                    } else {
                        $xmas-pos += 1;
                    }
                } else {
                    $xmas-pos = 0;
                }
            }
        }
        return $xmas-count;
    }
    
    sub generateScanHorizontal(@grid) {
        # Horizontal
        my $rows = @grid.elems;
        my $cols = @grid[0].elems;
        my @scanRows = ();
        for 0..^$rows -> $row {
            my @scanRow = ();
            for 0..^$cols -> $col {
                @scanRow.push(($row, $col));
            }
            @scanRows.push(@scanRow);
        }
        return @scanRows.List».List;
    }
    
    sub generateScanDiagonal(@grid) {
        # Down-right diagonal
        my $rows = @grid.elems;
        my $cols = @grid[0].elems;
        my @scanRows = ();
        for 0..^($rows + $cols - 1) -> $diag {
            my @scanRow = ();
            my $starting-row = max(-$cols + $diag + 1, 0);
            my $starting-col = max($rows - $diag - 1, 0);
            my $diag-len = min($rows - $starting-row, $cols - $starting-col);
            for 0..^$diag-len -> $diag-pos {
                @scanRow.push(($starting-row + $diag-pos, $starting-col + $diag-pos));
            }
            @scanRows.push(@scanRow);
        }
        return @scanRows.List».List;
    }
    
    sub countGridMatches(@grid, @needle) {
        my $count = 0;
        for 0..(@grid.elems - @needle.elems) -> $top {
            TOP-LEFT:
            for 0..(@grid[$top].elems - @needle[0].elems) -> $left {
                for 0..^@needle.elems -> $row-offset {
                    for 0..^@needle[$row-offset].elems -> $col-offset {
                        my $needle-char = @needle[$row-offset][$col-offset];
                        next if $needle-char eq ".";
                        next TOP-LEFT if $needle-char ne @grid[$top+$row-offset][$left+$col-offset];
                    }
                }
                $count += 1;
            }
        }
        return $count;
    }
    

    github


  • Raku

    sub MAIN($input) {
        grammar Muls {
            token TOP { .*? <mul>+%.*? .* }
            token mul { "mul(" <number> "," <number> ")" }
            token number { \d+ }
        }
    
        my $parsedMuls = Muls.parsefile($input);
        my @muls = $parsedMuls<mul>.map({.<number>».Int});
        my $part-one-solution = @muls.map({[*] $_.List}).sum;
        say "part 1: $part-one-solution";
    
        grammar EnabledMuls {
            token TOP { .*? [<.disabled> || <mul>]+%.*? .* }
            token mul { "mul(" <number> "," <number> ")" }
            token number { \d+ }
            token disabled { "don't()" .*? ["do()" || $] }
        }
    
        my $parsedEnabledMuls = EnabledMuls.parsefile($input);
        my @enabledMuls = $parsedEnabledMuls<mul>.map({.<number>».Int});
        my $part-two-solution = @enabledMuls.map({[*] $_.List}).sum;
        say "part 2: $part-two-solution";
    }
    

    github



  • Raku

    I’m trying warm up to Raku again.

    Solution

    github

    use v6;
    
    sub MAIN($input) {
        my $file = open $input;
    
        grammar LocationList {
            token TOP { <row>+%"\n" "\n"* }
            token row { <left=.id> " "+ <right=.id> }
            token id { \d+ }
        }
    
        my $locations = LocationList.parse($file.slurp);
        my @rows = $locations<row>.map({ (.<left>.Int, .<right>.Int)});
        my $part-one-solution = (@rows[*;0].sort Z- @rows[*;1].sort)».abs.sum;
        say "part 1: $part-one-solution";
    
        my $rbag = bag(@rows[*;1].sort);
        my $part-two-solution = @rows[*;0].map({ $_ * $rbag{$_}}).sum;
        say "part 2: $part-two-solution";
    }
    

    I’m happy to see that Lemmy no longer eats Raku code.




  • Knowing what I know about why the emperor’s wife’s age is important, I can see that they’re trying to build it up into a mystery that we will slowly unravel, but without that knowledge it definitely seems like just a running gag

    I have no knowledge outside what’s been shown in the episodes, but I think it’s fairly obvious that the age is some specific condition from his curse (or similar thing). At the same time, the age gap is definitely pandering to a specific audience. The author knows exactly what they’re doing, it doesn’t matter if there is some in-story pretense. For better or worse, this is the story they wanted to tell.

    Jill did establish that their relationship should be platonic, which is nice. Hopefully that’s not just a front. The fact that the Jill is mentally older does help make it a little less gross (but at the same time, it feels like the author is trying to make an excuse for degeneracy).




  • Makeine is more like Alya in that they romantic comedies. Makeine is heavier on the comedy, with a heavy reliance on failed-romance to drive the comedy/plot forward. Alya has a more prominent non-romantic drama plot that runs alongside the romance/flirting. Both feed a bit into a basic male sexual fantasy (Alya more so, but episode 2 of Makeine had a pretty unnecessarily spicy scene).

    Days with my Stepsister is more of a romance / coming-of-age story without much comedy and I feel like it doesn’t excessively feed into a sexual fantasy. There’s like 1 exception early-ish in the season, but even that kinda felt like the main purpose was to shake up the story, rather than getting the viewers horny.







  • I’d think so. 3k is so many pixels to compute and send 60 times a second.

    But this video says the effect on battery life in their test was like 6%, going from 4k to 800x600. I can imagine that some screens are better at saving power when running at lower resolutions… but what screen manufacturer would optimize energy consumption for anything but maximum resolution? 🤔 I guess the computation of the pixels isn’t much compared to the expense of having those physical dots. But maybe if your web browser was ray-traced? … ?!

    Also, if you take a 2880x1800 screen and divide by 2 (to avoid fractional scaling), you get 1440x900 (this is not 1440p), which is a little closer to 720p than 1080p.



  • retains heat longer, and also loses heat faster

    These two points are contradictory. Something either holds heat longer or loses it faster.

    I read your second link and it seems that color matters way more than composite vs real wood. Though in any case they were measuring the upward-facing surface temperature of the decking material, not the inside temperature of a structure made from the material.

    I’m no bird building engineer, but here is what I’d consider if I was worried about bird house temperatures:

    • ventilation: helps bring the temperature down/up to the ambient air temperature
    • solar absorption: lighter colors tend to absorb less warmth from sunlight
    • insulation: more insulation means less heat/cold will transfer from the outside surface in, and will make the temperature inside more stable throughout the day/night

    And addressing each point in terms of composite vs real wood:

    • ventilation: same for both composite and real wood
    • solar absorption: unpainted light-colored wood appears to be fairly cool, but if it’s painted/stained then it doesn’t matter
    • insulation: I can’t find a good source, but it seems like real wood is a better insulator than composite. You can use thicker boards to increase insulation.

    So, if you make a bird house with unstained unpainted untreated wood and the exact same bird house design with composite wood, I think it’s reasonable to assume that the composite one will get a little warmer on a hot day. If the bird house has some ventilation, I don’t think there will be much of a difference.



  • I got a chuckle out of the middle one.

    The middle one I could find somebody mention online before the episode came out, the other two don’t show up at all. So the middle one I think is from the LN, the other two might be anime original (or maybe just not funny enough to post online). I have a feeling these are just referencing LNs this time. The cover arts feel inspired as well.

    • クラスの1軍女子に、赤スパ投げられてます!
    • 借りた部屋にJKが付いてきたけど、食費が高くてもう限界です。
    • 銀河皇帝の娘さんは、丁寧な暮らしを望んでいる。