200fifty

joined 2 years ago
[–] [email protected] 4 points 1 year ago

day 2

perl

#!/usr/bin/env perl

use strict;
use warnings;
use v5.010;
use List::Util qw/ max /;

# Parse the input

my %games = ();

for my $line (<>) {
    $line =~ /Game (\d+): (.+)/;
    my $game_id = $1;
    my $game_str = $2;

    my @segments = split '; ', $game_str;
    my @game = ();
    for my $segment (@segments) {
        my @counts = split ', ', $segment;

        my %colors = (red => 0, blue => 0, green => 0);
        for my $count (@counts) {
            $count =~ /(\d+) (\w+)/;
            $colors{$2} = $1;
        }

        push @game, { %colors };
    }

    $games{$game_id} = [ @game ];
}

# Part 1

my $part1 = 0;

game: for my $game_id (keys %games) {
    for my $segment (@{$games{$game_id}}) {
        next game if $segment->{red} > 12 || $segment->{green} > 13 || $segment->{blue} > 14;
    }

    $part1 += $game_id;
}

say "Part 1: $part1";

# Part 2

my $part2 = 0;

for my $game (values %games) {
    my ($red, $green, $blue) = (0, 0, 0);

    for my $segment (@$game) {
        $red = max $segment->{red}, $red;
        $green = max $segment->{green}, $green;
        $blue = max $segment->{blue}, $blue;
    }

    $part2 += $red * $green * $blue;
}

say "Part 2: $part2";

Found this much easier than day 1 honestly...

[–] [email protected] 7 points 1 year ago* (last edited 1 year ago) (2 children)

day 1

part 1

perl

#!/usr/bin/env perl

use strict;
use warnings;
use 5.010;

my $total = 0;

for my $line (<>) {
    my @nums = ($line =~ /\d/g);
    $total += $nums[0] * 10 + $nums[-1];
}

say $total;

part 2

perl

#!/usr/bin/env perl

use strict;
use warnings;
use v5.010;

my %nums = (one => 1, two => 2, three => 3, four => 4, five => 5, six => 6, seven => 7, eight => 8, nine => 9);
$nums{$_} = $_ for 1..9;

my $regex = join "|", keys %nums;

my $total = 0;

for my $line (<>) {
    $line =~ /($regex)/;
    my $first_num = $nums{$1};

    my $window = 1;
    my $sub = substr $line, -1;
    while ($sub !~ /($regex)/) {
        $window ++;
        $sub = substr $line, -$window;
    }

    $sub =~ /($regex)/;
    my $second_num = $nums{$1};

    $total += $first_num * 10 + $second_num;
}

say $total;

Part 2 gave me a surprising amount of trouble. I resolved it by looking at longer and longer substrings from the end of the line in order to find the very last word even if it overlapped, which you can't do with normal regex split. I doubt this is the most efficient possible solution.

Also Lemmy is eating my < characters inside code blocks, which seems wrong. Pretend the "&lt;>" part says "<>", lol

[–] [email protected] 10 points 1 year ago

The problem is just transparency, you see -- if they could just show people the math that led them to determining that this would save X million more lives, then everyone would realize that it was actually a very good and sensible decision!

[–] [email protected] 21 points 1 year ago (2 children)

It’s not like a pig that can do calculus would suddenly become a reasonable romantic partner haha.

as a pig that can do calculus, this explains why I'm still single

[–] [email protected] 17 points 1 year ago (6 children)

why are the comments on this post such a disaster. who are these people

[–] [email protected] 12 points 1 year ago (1 children)

I feel like such a hipster. "I hated them before it was cool!"

[–] [email protected] 6 points 1 year ago* (last edited 1 year ago) (2 children)

Is this a correct characterisation of the EA community? That they all harbour anti-abortion sentiment but for whatever reason permit abortion?

I actually wouldn't be surprised if this were the case -- the whole schtick of a lot of these people is "worrying about increasing the number of future possibly-existing humans, even at the cost of the suffering of actually-existing humans", so being anti-abortion honestly seems not too far out of their wheelhouse?

Like I think in the EAverse you can just kinda go "well this makes people have less kids which means less QALYs therefore we all know it's obviously bad and I don't really need to justify it." (with bonus internet contrarian points if you are justifying some terrible thing using your abstract math, because that means you're Highly Decoupled and Very Smart.) See also the quote elsewhere in this thread about the guy defending child marriage for similar reasons.

[–] [email protected] 5 points 1 year ago (2 children)

I... think (hope??) the "*" is representing filled in squares in the crossword and that he has a grid of characters. But in that case the problem is super easy, you just need to print out HTML table tags between each character and color the table cell black when the character is "*". It takes like 10 minutes to solve without chatgpt already. :/

[–] [email protected] 1 points 1 year ago

I would blame the rise of smartphones for that too. Somehow everyone became convinced that if tech isn't radically upending everyone's lives every 10 years then something is wrong. But hey, maybe our lives don't need tech companies to disrupt them anymore actually?

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

I think he means script as in, literally a series of lines to say to your doctor to magically hack their brain into giving you the prescription you need (gee, I wonder how these people ever got into pickup artistry!), not a script as in prescription. I think it's not about cost, it's about doctors... prescribing you the wrong thing for some reason so you have to lie to them to get the correct medication? Is this some conspiracy theory I'm not aware of, lol

[–] [email protected] 5 points 1 year ago

For your team of developers to deploy at the speed and scale that you need to lead in the market, your developers must be empowered with AI at every step of the software development life cycle, customized and fine-tuned to your codebase.

I feel like I know who the target audience for this post is, and it's not programmers

view more: ‹ prev next ›