day9 part2
This commit is contained in:
parent
9fd55c3aac
commit
2c3840f65a
@ -12,7 +12,7 @@ fn main() {
|
|||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
|
|
||||||
for line in input {
|
for line in input {
|
||||||
let mut line_enders: Vec<i64> = vec![*line.last().unwrap()];
|
let mut line_starters: Vec<i64> = vec![*line.first().unwrap()];
|
||||||
let mut cur_line: Vec<i64> = line;
|
let mut cur_line: Vec<i64> = line;
|
||||||
while !cur_line.iter().all(|x| *x == 0) {
|
while !cur_line.iter().all(|x| *x == 0) {
|
||||||
let mut next_line: Vec<i64> = vec![];
|
let mut next_line: Vec<i64> = vec![];
|
||||||
@ -20,15 +20,51 @@ fn main() {
|
|||||||
let diff = cur_line[i] - cur_line[i-1];
|
let diff = cur_line[i] - cur_line[i-1];
|
||||||
next_line.push(diff)
|
next_line.push(diff)
|
||||||
}
|
}
|
||||||
line_enders.push(*next_line.last().unwrap());
|
line_starters.push(*next_line.first().unwrap());
|
||||||
cur_line = next_line;
|
cur_line = next_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
for i in (1..line_enders.len()).rev() {
|
for i in (1..line_starters.len()).rev() {
|
||||||
sum = sum + line_enders[i - 1];
|
sum = line_starters[i - 1] - sum;
|
||||||
}
|
}
|
||||||
total += sum;
|
total += sum;
|
||||||
}
|
}
|
||||||
println!("{:?}", total)
|
println!("{:?}", total)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// use std::fs;
|
||||||
|
|
||||||
|
// fn main() {
|
||||||
|
// let input = fs::read_to_string("input.txt").unwrap();
|
||||||
|
// let input: Vec<_> = input.split('\n')
|
||||||
|
// .map(|line| {
|
||||||
|
// line.split_whitespace()
|
||||||
|
// .map(|num| num.parse::<i64>().unwrap())
|
||||||
|
// .collect::<Vec<_>>()
|
||||||
|
// }).collect();
|
||||||
|
|
||||||
|
// let mut total = 0;
|
||||||
|
|
||||||
|
// for line in input {
|
||||||
|
// let mut line_enders: Vec<i64> = vec![*line.last().unwrap()];
|
||||||
|
// let mut cur_line: Vec<i64> = line;
|
||||||
|
// while !cur_line.iter().all(|x| *x == 0) {
|
||||||
|
// let mut next_line: Vec<i64> = vec![];
|
||||||
|
// for i in 1..cur_line.len() {
|
||||||
|
// let diff = cur_line[i] - cur_line[i-1];
|
||||||
|
// next_line.push(diff)
|
||||||
|
// }
|
||||||
|
// line_enders.push(*next_line.last().unwrap());
|
||||||
|
// cur_line = next_line;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let mut sum = 0;
|
||||||
|
// for i in (1..line_enders.len()).rev() {
|
||||||
|
// sum = sum + line_enders[i - 1];
|
||||||
|
// }
|
||||||
|
// total += sum;
|
||||||
|
// }
|
||||||
|
// println!("{:?}", total)
|
||||||
|
// }
|
||||||
|
Loading…
Reference in New Issue
Block a user