start day 5
This commit is contained in:
		
							
								
								
									
										29
									
								
								2022/src/day5.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								2022/src/day5.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
const DATA: &'static str = "
 | 
			
		||||
    [D]    
 | 
			
		||||
[N] [C]    
 | 
			
		||||
[Z] [M] [P]
 | 
			
		||||
 1   2   3 
 | 
			
		||||
 | 
			
		||||
move 1 from 2 to 1
 | 
			
		||||
move 3 from 1 to 3
 | 
			
		||||
move 2 from 2 to 1
 | 
			
		||||
move 1 from 1 to 2
 | 
			
		||||
";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct State {
 | 
			
		||||
    stacks: Vec<Vec<char>>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl std::str::FromStr for State {
 | 
			
		||||
    fn from_str(data: &str) -> State {
 | 
			
		||||
        let lines: Vec<&str> = data.lines().collect();
 | 
			
		||||
        let mut stacks = Vec::new(Vec::new());
 | 
			
		||||
        // skip the first row, because it's just the stack numbers
 | 
			
		||||
        for row in lines.rev().skip(1) {
 | 
			
		||||
            for (i, ident) in row.split(' ') {
 | 
			
		||||
                let ident = ident.trim_matches(|c| c == '[' || c == ']');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user