Solve Part 2
This commit is contained in:
parent
7fe1a60dc2
commit
973f6b1856
26
src/main.rs
26
src/main.rs
@ -1,4 +1,5 @@
|
|||||||
// https://adventofcode.com/2022/day/3
|
// https://adventofcode.com/2022/day/3
|
||||||
|
#![feature(iter_array_chunks)]
|
||||||
|
|
||||||
const DATA: &'static str = include_str!("input.txt");
|
const DATA: &'static str = include_str!("input.txt");
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ fn item_priority(item: char) -> u8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn part1()
|
fn part1()
|
||||||
{
|
{
|
||||||
let mut priority_sum = 0;
|
let mut priority_sum = 0;
|
||||||
@ -32,9 +34,31 @@ fn part1()
|
|||||||
println!("The sum of the priorities of duplicate item types is {}", priority_sum);
|
println!("The sum of the priorities of duplicate item types is {}", priority_sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn part2()
|
||||||
|
{
|
||||||
|
let mut priority_sum = 0;
|
||||||
|
for slice in DATA.split("\n").array_chunks::<3>()
|
||||||
|
{
|
||||||
|
let left = slice[0];
|
||||||
|
let mid = slice[1];
|
||||||
|
let right = slice[2];
|
||||||
|
|
||||||
|
for c in left.chars().into_iter()
|
||||||
|
{
|
||||||
|
if mid.contains(c) && right.contains(c)
|
||||||
|
{
|
||||||
|
priority_sum += item_priority(c) as u32;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("The sum of the priorities of team badges is {}", priority_sum);
|
||||||
|
}
|
||||||
|
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
part1()
|
//part1()
|
||||||
|
part2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user