Time to break out the hex editors and fix some corrupted memory.
Also fun with regex I expect. Or if you go full throttle and make a lexer/parser out of it.
@Enjoyer_of_Games@hexbear.net @Speaker@hexbear.net @gay_king_prince_charles@hexbear.net @iByteABit@hexbear.net
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.بناءا على تعليمات الهيئة لترويج لألعاب الفيديو و النهي عن الجنس نرجوا الإبتعاد عن أي أفكار جنسية و الحفاظ على حيواناتكم المنويَّة حتى يوم الحساب. اتقوا الله، إنك لا تراه لكنه يراك.