day3 part1
This commit is contained in:
17
src/day2.rs
Normal file
17
src/day2.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#[aoc(day2, part1)]
|
||||||
|
pub fn part1(input: &str) -> i64 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_part1() {
|
||||||
|
let cases = vec![("11-22", 33), ("11-22,95-115", 132)];
|
||||||
|
for case in cases {
|
||||||
|
assert_eq!(part1(case.0), case.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/day3.rs
Normal file
44
src/day3.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#[aoc(day3, part1)]
|
||||||
|
pub fn part1(input: &str) -> u32 {
|
||||||
|
input.split("\n").map(|line| get_joltage(line)).sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_joltage(line: &str) -> u32 {
|
||||||
|
let len = line.len();
|
||||||
|
let (revpos_1, val_1) = line[..(len - 1)]
|
||||||
|
.chars()
|
||||||
|
.rev()
|
||||||
|
.enumerate()
|
||||||
|
.max_by(|x, y| x.1.cmp(&y.1))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let val_2 = line[(len - 1 - revpos_1)..].chars().max().unwrap();
|
||||||
|
let result = val_1.to_digit(10).unwrap() * 10 + val_2.to_digit(10).unwrap();
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_part1_1() {
|
||||||
|
let input = String::from(
|
||||||
|
"987654321111111
|
||||||
|
811111111111119
|
||||||
|
234234234234278
|
||||||
|
818181911112111",
|
||||||
|
);
|
||||||
|
assert_eq!(part1(&input), 357)
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_part1_2() {
|
||||||
|
let input = String::from(
|
||||||
|
"9891111111111111111
|
||||||
|
111111111111111
|
||||||
|
818181911112111",
|
||||||
|
);
|
||||||
|
assert_eq!(part1(&input), 99 + 11 + 92)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ extern crate aoc_runner;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate aoc_runner_derive;
|
extern crate aoc_runner_derive;
|
||||||
|
|
||||||
pub mod day1;
|
// pub mod day1;
|
||||||
|
// pub mod day2;
|
||||||
|
pub mod day3;
|
||||||
|
|
||||||
aoc_lib! { year = 2025 }
|
aoc_lib! { year = 2025 }
|
||||||
|
|||||||
Reference in New Issue
Block a user