done with part 2
This commit is contained in:
parent
1c7913285c
commit
d4af3e7c26
1 changed files with 14 additions and 6 deletions
|
@ -7,15 +7,23 @@ type Beep = HashSet<char>;
|
||||||
fn parse_input_day1(input: &str) -> String {
|
fn parse_input_day1(input: &str) -> String {
|
||||||
input.to_string()
|
input.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc_run(day6, part1)]
|
#[aoc_run(day6, part1)]
|
||||||
fn part1(input: &str) -> usize {
|
fn part1(input: &str) -> usize {
|
||||||
let input = input.trim();
|
get_token(input.trim(), 4)
|
||||||
let mut out = 4;
|
}
|
||||||
for (i, c) in input.as_bytes().windows(4).enumerate() {
|
|
||||||
|
#[aoc_run(day6, part2)]
|
||||||
|
fn part2(input: &str) -> usize {
|
||||||
|
get_token(input.trim(), 14)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_token(input: &str, len: usize) -> usize {
|
||||||
|
let mut out = 0;
|
||||||
|
for (i, c) in input.as_bytes().windows(len).enumerate() {
|
||||||
let window = Beep::from_iter(c.iter().map(|c| *c as char));
|
let window = Beep::from_iter(c.iter().map(|c| *c as char));
|
||||||
out = i + 4;
|
out = i + len;
|
||||||
dbg!(i, std::str::from_utf8(c).unwrap(), &window);
|
if window.len() == len {
|
||||||
if window.len() == 4 {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue