forked from danmax/aoc
DeaDvey day 4
This commit is contained in:
@@ -18,9 +18,7 @@ fn algorithm(banks: &Vec<&str>) -> (u64, u64)
|
||||
overall_index += 1;
|
||||
if joltage as u64 > highest {
|
||||
prev_index = overall_index;
|
||||
unsafe {
|
||||
ptr::write(&mut highest as *mut u64, joltage as u64);
|
||||
}
|
||||
unsafe {ptr::write(&mut highest as *mut u64, joltage as u64);}
|
||||
if joltage == 57 { break; }
|
||||
}
|
||||
}
|
||||
@@ -28,27 +26,6 @@ fn algorithm(banks: &Vec<&str>) -> (u64, u64)
|
||||
joltages[i] = highest ^ 48;
|
||||
highest = 0;
|
||||
}
|
||||
prev_index = 0;
|
||||
for i in 0..=10 {
|
||||
if joltages[i] > highest.into() {
|
||||
unsafe {
|
||||
ptr::write(&mut highest as *mut u64, joltages[i] as u64);
|
||||
}
|
||||
prev_index = i+1;
|
||||
if joltages[i] == 9 { break; }
|
||||
}
|
||||
}
|
||||
total1 += highest * 10;
|
||||
highest = 0;
|
||||
for i in prev_index..=11 {
|
||||
if joltages[i] > highest.into() {
|
||||
unsafe {
|
||||
ptr::write(&mut highest as *mut u64, joltages[i] as u64);
|
||||
}
|
||||
if joltages[i] == 9 { break; }
|
||||
}
|
||||
}
|
||||
total1 += highest;
|
||||
total2 += joltages[0] * 10_u64.pow(11)
|
||||
+ joltages[1] * 10_u64.pow(10)
|
||||
+ joltages[2] * 10_u64.pow(9)
|
||||
@@ -61,6 +38,25 @@ fn algorithm(banks: &Vec<&str>) -> (u64, u64)
|
||||
+ joltages[9] * 10_u64.pow(2)
|
||||
+ joltages[10] * 10_u64
|
||||
+ joltages[11];
|
||||
// part 1
|
||||
prev_index = 0;
|
||||
for i in 0..=10 {
|
||||
if joltages[i] > highest.into() {
|
||||
unsafe {ptr::write(&mut highest as *mut u64, joltages[i] as u64);}
|
||||
prev_index = i+1;
|
||||
if joltages[i] == 9 { break; }
|
||||
}
|
||||
}
|
||||
total1 += highest * 10;
|
||||
highest = 0;
|
||||
for i in prev_index..=11 {
|
||||
if joltages[i] > highest.into() {
|
||||
unsafe {
|
||||
ptr::write(&mut highest as *mut u64, joltages[i] as u64);}
|
||||
if joltages[i] == 9 { break; }
|
||||
}
|
||||
}
|
||||
total1 += highest;
|
||||
}
|
||||
|
||||
(total1, total2)
|
||||
|
||||
Reference in New Issue
Block a user