pad numbers on directory names

This commit is contained in:
2024-03-12 22:42:38 -07:00
parent efd1fb5ca9
commit f2eb9929d7
55 changed files with 0 additions and 0 deletions

25
day06/src/main.rs Normal file
View File

@@ -0,0 +1,25 @@
use std::env;
use std::fs::File;
use std::io::{BufReader, Read};
use std::collections::{VecDeque, HashSet};
fn main() {
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
let reader = BufReader::new(file);
let mut prevs: VecDeque<u8> = VecDeque::new();
let mut i = 0;
for byte in reader.bytes() {
i += 1;
prevs.push_back(byte.unwrap());
if prevs.len() > 14 {
prevs.pop_front();
}
let set: HashSet<u8> = HashSet::from_iter(prevs.iter().cloned());
if set.len() == 14 {
println!("{}", i);
break;
}
}
}

26
day06/src/main1.rs Normal file
View 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;
}
}
}