day8 slightly faster

This commit is contained in:
Jan-Bulthuis 2024-12-08 14:19:25 +01:00
parent 1277882310
commit 6e0519aa27
1 changed files with 3 additions and 3 deletions

View File

@ -28,7 +28,7 @@ fn parse(input: &str) -> Input {
#[aoc(day8, part1)]
fn part1(input: &Input) -> usize {
let mut set = HashSet::new();
let mut set = HashSet::with_capacity(input.1.len() * input.1.len());
input.1.iter().for_each(|vec| {
for l in 0..vec.len() {
for r in l + 1..vec.len() {
@ -50,7 +50,7 @@ fn part1(input: &Input) -> usize {
#[aoc(day8, part2)]
fn part2(input: &Input) -> usize {
let mut set = HashSet::new();
let mut set = HashSet::with_capacity(input.1.len() * input.1.len());
input.1.iter().for_each(|vec| {
for l in 0..vec.len() {
for r in l + 1..vec.len() {
@ -69,7 +69,7 @@ fn part2(input: &Input) -> usize {
break;
}
}
let mut d = 0;
let mut d = -1;
loop {
let c = (s.0 + d * v.0, s.1 + d * v.1);
d -= 1;