2020: day01: linear part 1
This commit is contained in:
parent
14756db40a
commit
c09ce94f6a
|
@ -37,14 +37,15 @@ fn part2(input: &str) -> Result<i64> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_2020_2_sum(entries: &[i64]) -> Result<(i64, i64)> {
|
fn find_2020_2_sum(entries: &[i64]) -> Result<(i64, i64)> {
|
||||||
|
let set: HashSet<i64> = entries.iter().copied().collect();
|
||||||
|
|
||||||
for i in 0..entries.len() {
|
for i in 0..entries.len() {
|
||||||
for j in 0..entries.len() {
|
let a = entries[i];
|
||||||
if i == j {
|
|
||||||
continue;
|
let b = 2020 - a;
|
||||||
}
|
|
||||||
if entries[i] + entries[j] == 2020 {
|
if set.contains(&b) {
|
||||||
return Ok((entries[i], entries[j]));
|
return Ok((a, b));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue