creamsnail's recent activity

  1. Comment on Day 1: Secret Entrance in ~comp.advent_of_code

    creamsnail
    Link
    I probably did not follow the prescribed way to accomplish these. But I did them, and that's all that really matters. I hope to see other versions for those who are doing it in Rust. I think I saw...

    I probably did not follow the prescribed way to accomplish these. But I did them, and that's all that really matters.

    I hope to see other versions for those who are doing it in Rust. I think I saw two other folks on here mention trying it this year, hopefully it'll inspire them to post their solutions when or if they can (no pressure).

    Parts 1 and 2 (with tests) Also I thought it was kind of cute that the second part's hex `0x434C49434B` decodes to `CLICK`
    use std::fs::read_to_string;
    
    const test_file: &str = "example_input.txt";
    const puzzle_input: &str = "puzzle_input.txt";
    
    fn main() {
        // PART ONE
        let part_one_start = 50;
        let part_one_answer = part_one(read_puzzle_input(puzzle_input), part_one_start);
        println!("The answer to part one is: {}", part_one_answer);
    
        let part_two_start: usize = 50;
        let part_two_answer = part_two(read_puzzle_input(puzzle_input), part_two_start);
        println!("The answer to part two is: {}", part_two_answer)
    }
    
    // Reads in the puzzle input text file which contains the D##
    fn read_puzzle_input(file_name: &str) -> Vec<String> {
        return read_to_string(file_name)
            .unwrap()
            .lines()
            .map(String::from)
            .collect();
    }
    
    fn part_one(instruction: Vec<String>, start_point: usize) -> i32 {
        let mut dial = vec![
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
            "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
            "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
            "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61",
            "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76",
            "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91",
            "92", "93", "94", "95", "96", "97", "98", "99",
        ];
        dial.rotate_left(start_point);
    
        // Keep track of how many times we hit 0
        let mut count = 0;
    
        // Iterate over the instructions
        for line in instruction {
            let (direction, number) = line.split_at(1);
            // Set the number to a digit so we can rotate the dial
            let num: usize = number.parse::<usize>().unwrap();
            if direction == "R" {
                for _ in 0..num {
                    dial.rotate_left(1)
                }
            } else if direction == "L" {
                for _ in 0..num {
                    dial.rotate_right(1)
                }
            }
            if dial[0] == "0" {
                count += 1;
            }
        }
        return count;
    }
    
    fn part_two(instruction: Vec<String>, start_point: usize) -> i32 {
        let mut dial = vec![
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
            "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
            "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
            "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61",
            "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76",
            "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91",
            "92", "93", "94", "95", "96", "97", "98", "99",
        ];
        dial.rotate_left(start_point);
    
        // Keep track of how many times we hit 0
        let mut count = 0;
    
        // Iterate over the instructions
        for line in instruction {
            let (direction, number) = line.split_at(1);
            // Set the number to a digit so we can rotate the dial
            let num: usize = number.parse::<usize>().unwrap();
            if direction == "R" {
                for _ in 0..num {
                    dial.rotate_left(1);
                    if dial[0] == "0" {
                        count += 1;
                    }
                }
            } else if direction == "L" {
                for _ in 0..num {
                    dial.rotate_right(1);
                    if dial[0] == "0" {
                        count += 1;
                    }
                }
            }
        }
        return count;
    }
    
    #[test]
    fn part_one_example() {
        let instruction = read_puzzle_input(test_file);
        let start_point: usize = 50;
        assert_eq!(part_one(instruction, start_point), 3);
    }
    
    #[test]
    fn part_two_example() {
        let instruction = read_puzzle_input(test_file);
        let start_point: usize = 50;
        assert_eq!(part_two(instruction, start_point), 6);
    }
    
    2 votes
  2. Comment on Faithless: A Sojourn Story in ~books

    creamsnail
    Link Parent
    Thank you for the guest pass, I did end up getting it for a year but sadly didn't end up using it nearly as much as I thought I would. I think I'll stick to probably supporting through patreon and...

    Thank you for the guest pass, I did end up getting it for a year but sadly didn't end up using it nearly as much as I thought I would. I think I'll stick to probably supporting through patreon and such as I think it's a bit more direct in some capacity and I can focus on the folks I actively watch.

  3. Comment on Faithless: A Sojourn Story in ~books

    creamsnail
    Link Parent
    I’d be super happy to try it out, I’ve watched tons of videos from real engineering and started checking out paper skies on YouTube. Both from what I’ve been advertised are on there. I’ve been...

    I’d be super happy to try it out, I’ve watched tons of videos from real engineering and started checking out paper skies on YouTube. Both from what I’ve been advertised are on there. I’ve been wanting to try before I bought and haven’t known anyone with access. Is there really quite a bit to watch on there and have you enjoyed it?

    Link to real engineering cause why not:

    https://youtube.com/@realengineering

    1 vote