aoc2022 day10 part two
This commit is contained in:
parent
c191f67b95
commit
705eb5b2b2
@ -29,5 +29,49 @@ pub fn task_one(input: &str) -> String {
|
||||
}
|
||||
|
||||
pub fn task_two(input: &str) -> String {
|
||||
String::new()
|
||||
let mut x = 1;
|
||||
let mut cycle = 1;
|
||||
let mut output: Vec<char> = Vec::new();
|
||||
|
||||
for line in input.trim().lines() {
|
||||
let mut split = line.split_whitespace();
|
||||
|
||||
match split.next().unwrap() {
|
||||
"noop" => {
|
||||
if (x - 1) <= cycle % 40 && cycle % 40 <= (x + 1) {
|
||||
output.push('#');
|
||||
} else {
|
||||
output.push('.');
|
||||
}
|
||||
}
|
||||
"addx" => {
|
||||
if (x - 1) <= cycle % 40 && cycle % 40 <= (x + 1) {
|
||||
output.push('#');
|
||||
} else {
|
||||
output.push('.');
|
||||
}
|
||||
|
||||
cycle += 1;
|
||||
|
||||
x += split.next().unwrap().parse::<isize>().unwrap();
|
||||
|
||||
if (x - 1) <= cycle % 40 && cycle % 40 <= (x + 1) {
|
||||
output.push('#');
|
||||
} else {
|
||||
output.push('.');
|
||||
}
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
|
||||
cycle += 1;
|
||||
}
|
||||
|
||||
println!("{}", String::from_iter(output.get(0..40).unwrap().iter()));
|
||||
println!("{}", String::from_iter(output.get(40..80).unwrap().iter()));
|
||||
println!("{}", String::from_iter(output.get(80..120).unwrap().iter()));
|
||||
println!("{}", String::from_iter(output.get(120..160).unwrap().iter()));
|
||||
println!("{}", String::from_iter(output.get(160..200).unwrap().iter()));
|
||||
println!("{}", String::from_iter(output.get(200..240).unwrap().iter()));
|
||||
"print above PBZGRAZA".to_string()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user