[-] anonymouse@sh.itjust.works 4 points 1 month ago

Is your husband my girlfriend?

[-] anonymouse@sh.itjust.works 5 points 4 months ago

Jacha-chacha-chacha-chow!

[-] anonymouse@sh.itjust.works 3 points 7 months ago

Yeah the scene is great! And it's amazing too see then all together at NAC at the moment, great vibes! For those interested, big tourney going op at the moment (starts again in 2/3 hours): https://www.twitch.tv/nili_aoe?sr=a

[-] anonymouse@sh.itjust.works 4 points 7 months ago

I watch him indeed, among others

[-] anonymouse@sh.itjust.works 4 points 7 months ago

I started on the Tawny Man triology by Robin Hobb, love it so far!

[-] anonymouse@sh.itjust.works 4 points 7 months ago

Fantasy book series by Brandon Sanderson!

[-] anonymouse@sh.itjust.works 2 points 7 months ago

Nice username! Stormlight right?

[-] anonymouse@sh.itjust.works 2 points 8 months ago* (last edited 8 months ago)

I usually buy them on my phone (Kobo app), which is easier with payments. Afterwards the book is immediately available on my e-reader. Started doing this a couple of months back and I like it. You can also preview books, but got no personal experience with that.

[-] anonymouse@sh.itjust.works 2 points 8 months ago

This would be amazing

[-] anonymouse@sh.itjust.works 4 points 8 months ago* (last edited 8 months ago)

Rust

Feedback welcome! Feel like I'm getting the hand of Rust more and more.

use regex::Regex;
pub fn part_1(input: &str) {
    let lines: Vec<&str> = input.lines().collect();
    let time_data = number_string_to_vec(lines[0]);
    let distance_data = number_string_to_vec(lines[1]);

    // Zip time and distance into a single iterator
    let data_iterator = time_data.iter().zip(distance_data.iter());

    let mut total_possible_wins = 1;
    for (time, dist_req) in data_iterator {
        total_possible_wins *= calc_possible_wins(*time, *dist_req)
    }
    println!("part possible wins: {:?}", total_possible_wins);
}

pub fn part_2(input: &str) {
    let lines: Vec<&str> = input.lines().collect();
    let time_data = number_string_to_vec(&lines[0].replace(" ", ""));
    let distance_data = number_string_to_vec(&lines[1].replace(" ", ""));

    let total_possible_wins = calc_possible_wins(time_data[0], distance_data[0]);
    println!("part 2 possible wins: {:?}", total_possible_wins);
}

pub fn calc_possible_wins(time: u64, dist_req: u64) -> u64 {
    let mut ways_to_win: u64 = 0;

    // Second half is a mirror of the first half, so only calculate first part
    for push_time in 1..=time / 2 {
        // If a push_time crosses threshold the following ones will too so break loop
        if push_time * (time - push_time) > dist_req {
            // There are (time+1) options (including 0).
            // Subtract twice the minimum required push time, also removing the longest push times
            ways_to_win += time + 1 - 2 * push_time;
            break;
        }
    }
    ways_to_win
}

fn number_string_to_vec(input: &str) -> Vec {
    let regex_number = Regex::new(r"\d+").unwrap();
    let numbers: Vec = regex_number
        .find_iter(input)
        .filter_map(|m| m.as_str().parse().ok())
        .collect();
    numbers
}

[-] anonymouse@sh.itjust.works 2 points 8 months ago

Same here, yesterday felt like a trap, but didn't run into anything today?

[-] anonymouse@sh.itjust.works 2 points 8 months ago

Thanks, used this as input for reading the Day 2 file and looping the lines, just getting started with rust :)

view more: โ€น prev next โ€บ

anonymouse

joined 8 months ago