• gay_king_prince_charles [she/her, he/him]
    ·
    20 days ago

    Can I get some rigorous critique? I have a feeling that I did this very poorly, and I would like to turn this into a learning experience.

    abandon all hope ye who enter
    use std::{char, fs, vec};
    
    pub fn day3() {
        let mut ret = 0;
        for i in extract() {
            ret += i.0 * i.1;
        }
        println!("{}", ret);
    }
    
    fn extract() -> Vec<(i32, i32)> {
        let text = fs::read_to_string("input").unwrap();
        let mut ret: Vec<(i32, i32)> = vec::Vec::new();
        let text_vec = text.chars().collect::<Vec<char>>();
        let mut in_mul = false;
        let mut lhs = true;
        let mut collector: (Vec<char>, Vec<char>) = (Vec::new(), Vec::new());
        for (i, v) in text.chars().enumerate() {
            println!("---START({},{})---", i, v);
            if i < 3 {
                //Jump to line 3 as loop peeks backwards
                continue;
            }
            if v == '(' && text_vec[i - 1] == 'l' && text_vec[i - 2] == 'u' && text_vec[i - 3] == 'm' {
                // If the code is here, the last 3 chars spell 'mul'
                println!("Last 4 spelled mul(");
                in_mul = true;
                continue;
            } else if in_mul {
                // You are inside of a mul(... block
                // volcel police have been alerted to your position
                if lhs && v.is_numeric() {
                    println!("pushed left: {}", v);
                    collector.0.push(v);
                    continue;
                } else if !lhs && v.is_numeric() {
                    println!("pushed right: {}", v);
                    collector.1.push(v);
                    continue;
                } else if v == ',' {
                    println!("comma");
                    lhs = false; // Swap to the right because you are on the other side of the comma
                } else if v == ')' && in_mul {
                    println!("pushing... {}", in_mul);
                    lhs = true;
                    in_mul = false;
    
                    // Collect chars into ints and then add to vec
                    ret.push((
                        (collector
                            .0
                            .iter()
                            .cloned()
                            .collect::<String>()
                            .parse::<i32>()
                            .unwrap()),
                        (collector
                            .1
                            .iter()
                            .cloned()
                            .collect::<String>()
                            .parse::<i32>()
                            .unwrap()),
                    ));
                    collector.1.clear();
                    collector.0.clear();
                    println!("current final vec: {:?}", ret);
                } else {
                    println!("cleared");
                    collector.1.clear();
                    collector.0.clear();
                    lhs = true;
                    in_mul = false;
                }
            } else {
            }
    
            println!("---END({},{})---", i, v);
        }
        return ret;
    }
    
    • VOLCEL_POLICE [it/its]B
      ·
      20 days ago

      Show

      The VOLCEL POLICE are on the scene! PLEASE KEEP YOUR VITAL ESSENCES TO YOURSELVES AT ALL TIMES.

      نحن شرطة VolCel.بناءا على تعليمات الهيئة لترويج لألعاب الفيديو و النهي عن الجنس نرجوا الإبتعاد عن أي أفكار جنسية و الحفاظ على حيواناتكم المنويَّة حتى يوم الحساب. اتقوا الله، إنك لا تراه لكنه يراك.

      volcel-police