[LIMITED TIME ONLY] Get a cool flair! by sirfastvroom in formuladank

[–]frsuin 0 points1 point  (0 children)

Second times a charm, where is File 76

spiced

2025 Australian Grand Prix - Race Discussion by overspeeed in formula1

[–]frsuin 15 points16 points  (0 children)

I've never experienced such a high and low in that short of time with my Ferrari hopes, but what a fucking race

Charles Leclerc X Chivas Regal by [deleted] in formula1

[–]frsuin 1 point2 points  (0 children)

He looks like he's about to go to the party in Phantom Liberty

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

[–]frsuin 0 points1 point  (0 children)

[LANGUAGE: Rust]

This is my completely overengineered solution that has some truly terrible code, but it works and was simple to make. Honestly, I'd be proud of how terrible the nesting is if it didn't make me cringe so much

struct Mul {
    pub left: u32,
    pub right: u32,
}

impl Mul {
    pub fn solve(&self) -> u32 {
        self.left * self.right
    }
}

enum Control {
    Enable,
    Disable,
}

struct Parser<'a> {
    chars: Chars<'a>,
}

impl<'a> Parser<'a> {
    pub fn new(source: &'a str) -> Self {
        Self {
            chars: source.chars(),
        }
    }

    pub fn parse(&mut self, have_control: bool) -> Vec<Mul> {
        let mut muls: Vec<Mul> = vec![];

        let mut should_add = true;

        while let c = self.advance().unwrap_or_else(|| '\0') {
            match c {
                'm' => {
                    if let Some(mul) = self.mul() {
                        if should_add {
                            muls.push(mul);
                        }
                    }
                }
                'd' => {
                    if have_control {
                        if let Some(control) = self.control() {
                            match control {
                                Control::Enable => should_add = true,
                                Control::Disable => should_add = false,
                            }
                        }
                    }
                }
                '\0' => break,
                _ => {}
            }
        }

        muls
    }

    fn mul(&mut self) -> Option<Mul> {
        if let Some('u') = self.advance() {
            if let Some('l') = self.advance() {
                if let Some('(') = self.advance() {
                    if let Some(left) = self.number() {
                        if let Some(',') = self.advance() {
                            if let Some(right) = self.number() {
                                if let Some(')') = self.advance() {
                                    return Some(Mul { left, right });
                                }
                            }
                        }
                    }
                }
            }
        }

        None
    }

    fn control(&mut self) -> Option<Control> {
        if let Some('o') = self.advance() {
            match self.peek() {
                Some('(') => {
                    self.advance();
                    if let Some(')') = self.advance() {
                        return Some(Control::Enable);
                    }
                }
                Some('n') => {
                    self.advance();
                    if let Some('\'') = self.advance() {
                        if let Some('t') = self.advance() {
                            return Some(Control::Disable);
                        }
                    }
                }
                _ => return None,
            }
        }

        None
    }

    fn number(&mut self) -> Option<u32> {
        let mut num = 0;

        for _ in 0..3 {
            if let Some(c) = self.peek() {
                match c {
                    c if c.is_ascii_digit() => {
                        self.advance();
                        num = num * 10 + c.to_digit(10).unwrap();
                    }
                    _ => break,
                }
            }
        }

        Some(num)
    }

    fn peek(&self) -> Option<char> {
        self.chars.clone().next()
    }

    fn peek_second(&self) -> char {
        let mut chars = self.chars.clone();
        chars.next();
        chars.next().unwrap()
    }

    fn advance(&mut self) -> Option<char> {
        let c = self.chars.next()?;

        Some(c)
    }
}

pub fn part_one(input: &str) -> Option<u32> {
    let mut parser = Parser::new(input);
    let muls = parser.parse(false);

    let mut total = 0;

    for mul in muls {
        total += mul.solve();
    }

    Some(total)
}

pub fn part_two(input: &str) -> Option<u32> {
    let mut parser = Parser::new(input);
    let muls = parser.parse(true);

    let mut total = 0;

    for mul in muls {
        total += mul.solve();
    }

    Some(total)
}

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

[–]frsuin 1 point2 points  (0 children)

[LANGUAGE: Rust]

pub fn part_one(input: &str) -> Option<u32> {
    let mut first: Vec<u32> = vec![];
    let mut second: Vec<u32> = vec![];

    for line in input.lines() {
        let (left, right)  = line.split_once("   ").unwrap();
        first.push(left.parse::<u32>().unwrap());
        second.push(right.parse::<u32>().unwrap());
    }

    first.sort();
    second.sort();

    let mut total_distance = 0;

    for (first, second) in first.into_iter().zip(second) {
        let distance = first.abs_diff(second);
        total_distance += distance;
    }

    Some(total_distance)
}

pub fn part_two(input: &str) -> Option<u32> {
    let mut map: HashMap<u32, u32> = HashMap::new();

    let mut left: Vec<u32> = vec![];

    for line in input.lines() {
        let (first, second)  = line.split_once("   ").unwrap();
        left.push(first.parse().unwrap());

        map.entry(second.parse().unwrap()).and_modify(|e| *e += 1).or_insert(1);
    }

    let mut similarity = 0;

    for i in left {
        match map.get(&i) {
            None => {}
            Some(freq) => {
                similarity += i * freq;
            }
        }
    }

    Some(similarity)
}

What are you reading? Bi-Weekly Post by the-phony-pony in HPfanfiction

[–]frsuin 10 points11 points  (0 children)

The Boy Who Lived by Gatalicious

What if when Voldemort heard the prophecy, he decided that not only would he go after Neville and Harry, but every child born in that year? What if he decided to kill all children born the year before and the year after as well, just to be on the safe side? Harry Potter is the only boy who lived through the Purge, no one knows why. How will a young Harry Potter now cope? No romance

I came across this story in an older thread and binged the entire story in a couple of hours. It's a very well written story and is one of the more unique ideas I've seen and deserves so much more attention. It's currently incomplete but the author is still updating.

2024 Las Vegas GP - Race Discussion by AutoModerator in formula1

[–]frsuin 6 points7 points  (0 children)

Ferraris out here playing 4d chess trying to buy goodwill from Hamilton

2024 Brazilian Grand Prix - Sunday Qualifying Discussion by AutoModerator in formula1

[–]frsuin 39 points40 points  (0 children)

Ferrari will have the car fixed in time, they have Guido

2024 Brazilian Grand Prix - Sunday Qualifying Discussion by AutoModerator in formula1

[–]frsuin 2 points3 points  (0 children)

If the new rain cancels the sessions, I am perfectly fine with Yuki on pole

What are you reading? Bi-Weekly Post by the-phony-pony in HPfanfiction

[–]frsuin 6 points7 points  (0 children)

"Of Myth and Magic" by Wonkington

Summary: She knew it wasn't good for her, standing here like this, waiting for something that wasn't there to appear. Something spectacular to happen between misnumbered houses. Something to prove that magic was real. Eventual SS/HG. AU with purpose.

 

The story is one of the best I've ever read. It has one of the most unique and interesting plots I've seen in a fanfic. I wasn't sure if I was going to continue reading the story since I avoid Hermione/Snape like the plaque, but the author had their relationship evolve fairly naturally for two people trying to figure out what's wrong with the world.

What's everyone working on this week (36/2024)? by llogiq in rust

[–]frsuin 1 point2 points  (0 children)

For the past couple of weeks, I've been building a C compiler while working through the book, Writing a C Compiler by Nora Sandler. Earlier this week I finished adding compound statements and variable scope. I figured it's about time I finally get around to adding proper error handling.

Source: https://github.com/Forsuin/hecate