aoc7
This commit is contained in:
parent
b0bde44ff4
commit
6465a1597a
@ -8,7 +8,7 @@ fn bench_aoc_7_part1(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bench_aoc_7_part2(c: &mut Criterion) {
|
fn bench_aoc_7_part2(c: &mut Criterion) {
|
||||||
let input = black_box(include_str!("../src/aoc/input/full_input_aoc7.txt"));
|
let input = black_box(include_bytes!("../src/aoc/input/full_input_aoc7.txt"));
|
||||||
c.bench_function("bench_aoc7 part 2", |b| b.iter(|| aoc_7::solve_p2(input)));
|
c.bench_function("bench_aoc7 part 2", |b| b.iter(|| aoc_7::solve_p2(input)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,28 +39,30 @@ pub fn solve_p1(input: &str) -> u64 {
|
|||||||
answer
|
answer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn solve_p2(input: &str) -> u64 {
|
pub fn solve_p2(input: &[u8]) -> u64 {
|
||||||
let mut answer = 0;
|
let mut answer = 0;
|
||||||
let mut data = Vec::with_capacity(256);
|
let mut data = Vec::with_capacity(256);
|
||||||
for line in input.lines() {
|
for line in input.split(|x1| {*x1 == b'\n'}).step_by(1) {
|
||||||
let chars = line.bytes().map(|mut x| {if x == b'.' {x = 0; x as u64} else {x as u64}}).collect::<Vec<u64>>();
|
let chars = line.into_iter().map(|mut x| {if x == &b'.' {x = &0; *x as u64} else {*x as u64}}).collect::<Vec<u64>>();
|
||||||
data.push(chars);
|
data.push(chars);
|
||||||
}
|
}
|
||||||
let start_idx = data[0].iter().len() / 2 ;
|
let start_idx = data[0].iter().len() / 2 ;
|
||||||
data[0][start_idx] = 1;
|
data[0][start_idx] = 1;
|
||||||
|
|
||||||
|
|
||||||
for (i,line) in data.clone().iter().enumerate() {
|
for i in 0..data.len() {
|
||||||
//println!("{:?}", data[i]);
|
//println!("{:?}", data[i]);
|
||||||
for (j,char) in line.iter().enumerate() {
|
for j in 0..data[0].len(){
|
||||||
//println!("{}", data[i][j]);
|
//println!("{}", data[i][j]);
|
||||||
if data[i][j] == 94 {
|
if data[i][j] == 94 {
|
||||||
|
data[i][j] = 0;
|
||||||
//println!("{}", data[i][j]);
|
//println!("{}", data[i][j]);
|
||||||
if data[i-1][j] != 0 {
|
if data[i-1][j] != 0 || data[i][j-1] == 49 {
|
||||||
//println!("{}", data[i-1][j]);
|
//println!("{}", data[i-1][j]);
|
||||||
let power = data[i-1][j];
|
let power = data[i-1][j];
|
||||||
data[i][j-1] += power;
|
data[i][j-1] += power;
|
||||||
data[i][j+1] += power;
|
data[i][j+1] += power;
|
||||||
|
|
||||||
data[i+1][j-1] = data[i][j-1];
|
data[i+1][j-1] = data[i][j-1];
|
||||||
data[i+1][j+1] = data[i][j+1];
|
data[i+1][j+1] = data[i][j+1];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user