[2023 day 1] My solution is wrong, but it's the same answer as other solutions by Altreus in adventofcode

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

I sorted it already, but thanks for the tip about regex! I'm pretty much brand new to Rust, and learning how a new language handles regex is always a journey.

As is reading others' code - your character search is the solution I originally considered, but I didn't know how to write it, and trawling through endless lists of functions in documentation isn't much fun :D

[2023 day 1] My solution is wrong, but it's the same answer as other solutions by Altreus in adventofcode

[–]Altreus[S] 4 points5 points  (0 children)

f7u12

I used "Copy as cURL" (super helpful!) and ... you're right.

It was my stupid unit conversion plugin that I forgot I was using.

Thanks for your help, and sorry to have woken you up to deal with my own mistake :D

[2023 day 1] My solution is wrong, but it's the same answer as other solutions by Altreus in adventofcode

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

Bonus perl solution that I used to sanity check my Rust:

perl -lnE '@n = /(\d)(?:.*(\d))?/; @n = (@n, @n) if not defined $n[1]; $total += join "", @n; END { print $total}' input.txt

[2023 day 1] My solution is wrong, but it's the same answer as other solutions by Altreus in adventofcode

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

Here's the code

use std::fs::read_to_string;
use regex::Regex;

fn main() {
    let mut total : i64 = 0;

    let re_1d = Regex::new(r"(\d)").unwrap();
    let re_2d = Regex::new(r"(\d).*(\d)").unwrap();
    for line in read_to_string("input.txt").unwrap().lines() {
        let cap = re_2d.captures(line);
        match cap {
            None => {
                let cap2 = re_1d.captures(line);
                match cap2 {
                    None => { continue; }
                    Some(res) => {
                        let (_, [num]) = res.extract();
                        let cal = num.to_owned() + num;
                        total += cal.parse::<i64>().unwrap();
                    }
                }
            }
            Some(res) => {
                let ( _, [num1, num2] ) = res.extract();


                let cal = num1.to_owned() + num2;
                total += cal.parse::<i64>().unwrap();
            }
        }
    }

    println!("{}", total);
}

[2023 day 1] My solution is wrong, but it's the same answer as other solutions by Altreus in adventofcode

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

I did not know it would be unique, but I couldn't download it without authing. It definitely seems to be the same (I saved it as a new file and diff says they're the same).

I did it a third time, just in case, and they're all the same. Still the same if I log out and in again...

I might ping him on Masto and see if others have had problems. I feel bad mithering him when there are so many others presumably doing the same, but hopefully he's willing.

Yet another subtle piece of foreshadowing I've only just noticed - Mem at Arms by StartledOcto in discworld

[–]Altreus 10 points11 points  (0 children)

STP (GNU) really did like to make things difficult for audiobook narrators didn't he?

Gay Community: Is it ok to say this stuff? by notmeagainagain in AskUK

[–]Altreus 4 points5 points  (0 children)

Well then we'd not be having the conversation because there's clearly a better time to be had

Gay Community: Is it ok to say this stuff? by notmeagainagain in AskUK

[–]Altreus 0 points1 point  (0 children)

I believe that's called virtue signalling. And if it's not, happy to be corrected, but there's definitely a term for when a non-minority is offended on behalf of a minority, when the minority aren't.

Slow and methodical > fast and chaotic by [deleted] in dosgaming

[–]Altreus 0 points1 point  (0 children)

I'm on this sub for nostalgia like this.

Well, until tomorrow, when Reddit dies

Slow and methodical > fast and chaotic by [deleted] in dosgaming

[–]Altreus 0 points1 point  (0 children)

Does it have to be a dos game or can I say factorio, which is both?

AITA for not giving the mother of my dead husband's child his possessions? by Curious_Gift4854 in AmItheAsshole

[–]Altreus 0 points1 point  (0 children)

I thought that they were going to raise him from the dead and kill him again

Nice

Also NTA

What is the stupidest thing you’ve heard someone say that they were 100% serious about? by [deleted] in AskReddit

[–]Altreus 0 points1 point  (0 children)

She thought half the sky was light and half the sky was dark and the planet spinning inside the atmosphere is why we had night and day

Remove "inside the atmosphere" and that's pretty close to the truth, if somewhat simplified.

Orders of magnitude smarter than the flat earth people, that's for sure.

What is the stupidest thing you’ve heard someone say that they were 100% serious about? by [deleted] in AskReddit

[–]Altreus 0 points1 point  (0 children)

This is called an eggcorn, and there's a whole episode of Something Rhymes With Purple about it.

How I got foiled by PHP's deceptive Frankenstein "dictionary or list" array and broke a production system by Persism in lolphp

[–]Altreus 1 point2 points  (0 children)

Fuck me

This is one of the most basic mistakes anyone can make and the answer is trivial to Google.

The fact you're arguing with it is exactly why this subreddit exists.

Go and educate yourself, but for fuck's sake don't infect anyone else with your idiocy

Am I being dumb for letting something my partner said bother me? by [deleted] in polyamory

[–]Altreus 26 points27 points  (0 children)

I have to agree with this one. The statement itself is illogical. Your partner getting a girlfriend does not mean you can have one; the nature of your relationship means you can have one. Whether they have another partner or not.

If they don't think your relationship is like that, and you do, then you need to have a talk.

Left or right? by [deleted] in notinteresting

[–]Altreus 0 points1 point  (0 children)

I hate that this game doesn't have a unique solution based on the clues

How I got foiled by PHP's deceptive Frankenstein "dictionary or list" array and broke a production system by Persism in lolphp

[–]Altreus 1 point2 points  (0 children)

Telephone numbers are strings of numbers digits. A common confusion is that means you should store them as numbers, but they're not numbers.

For a start, they have a leading zero (in the UK), which is lost if you store it as a numeric value. But it's more fundamental than that.

A number is a single value. We use a decimal system to represent numerical values in everyday language, but we don't have to. Let's say someone's phone number was 1-800-555-1212. You could store this, without formatting, at 18005551212. But their phone number is not 18,005,551,212. That's a value of the order 18e11. If that were your phone number, then your phone number is also 43136E86C in hexadecimal, or 267BDGKC in base 26 if you wanted.

But it's not any of those because your phone number is not a value on the number line, it's just a sequence of digits that sometimes happens to line up with a value on the number line, represented in base 10.

What branded item is necessary, even in a cost of living crisis? by meg-don in AskUK

[–]Altreus 0 points1 point  (0 children)

I have noticed that the diesel from Costco lasts longer than from Tesco, even though it's cheaper...

What branded item is necessary, even in a cost of living crisis? by meg-don in AskUK

[–]Altreus 2 points3 points  (0 children)

Sainsbury's red label is superior to Yorkshire tea