d6p1
This commit is contained in:
		
							
								
								
									
										26
									
								
								day6/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								day6/src/main.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| use std::env; | ||||
| use std::fs::File; | ||||
| use std::io::{BufReader, Read}; | ||||
|  | ||||
| fn main() { | ||||
|     let file = File::open(&env::args().nth(1).unwrap()).unwrap(); | ||||
|     let reader = BufReader::new(file); | ||||
|  | ||||
|     let (mut x1, mut x2, mut x3) = (0, 0, 0); | ||||
|     let mut i = 0; | ||||
|     for byte in reader.bytes() { | ||||
|         i += 1; | ||||
|         let c = byte.unwrap(); | ||||
|         if c != x1 && c != x2 && c != x3 | ||||
|                 && x1 != x2 && x1 != x3 && x2 != x3 | ||||
|                 && x1 != 0 { | ||||
|             println!("{}", i); | ||||
|             break; | ||||
|         } else { | ||||
|             x1 = x2; | ||||
|             x2 = x3; | ||||
|             x3 = c; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user