moved code around so each year is a package.

This commit is contained in:
2025-08-29 16:14:42 -04:00
parent 8aa7fe572f
commit 46b91dae30
67 changed files with 246 additions and 77 deletions
+7
View File
@@ -0,0 +1,7 @@
[package]
name="aoc2017"
version = "0.1.0"
edition = "2024"
[dependencies]
core = { path = "../core" }
+55
View File
@@ -0,0 +1,55 @@
// The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit after the last digit is the first digit in the list.
//
// For example:
//
// 1122 produces a sum of 3 (1 + 2) because the first digit (1) matches the second digit and the third digit (2) matches the fourth digit.
// 1111 produces 4 because each digit (all 1) matches the next.
// 1234 produces 0 because no digit matches the next.
// 91212129 produces 9 because the only digit that matches the next one is the last digit, 9.
use core::read_data;
fn circular_digit_sum(input: &str) -> u32 {
let mut running_total = 0;
let mut first_char = ' ';
let mut last_char = ' ';
let input_length = input.len();
for (index, char) in input.chars().enumerate() {
if index == 0 {
first_char = char;
}
if index == input_length - 1 {
if char == first_char {
let num_val = char.to_digit(10).unwrap();
running_total += num_val;
}
}
if char == last_char {
let num_val = char.to_digit(10).unwrap();
running_total += num_val;
}
last_char = char;
}
running_total
}
fn main() {
let binding = read_data("2017_01_data.txt");
let params = vec![
("1122", 3),
("1111", 4),
("1234", 0),
("91212129", 9),
(&*binding, 1031)
];
for (param, expected) in params {
let result = circular_digit_sum(param);
print!("Checking if ||{param}|| calculates to ||{expected}|| actual ||{result}||...");
assert_eq!(result, expected);
println!("success!");
}
}
// 1031
+56
View File
@@ -0,0 +1,56 @@
// Now, instead of considering the next digit, it wants you to consider the digit halfway around
// the circular list. That is, if your list contains 10 items, only include a digit in your sum if
// the digit 10/2 = 5 steps forward matches it. Fortunately, your list has an even number of
// elements.
//
// For example:
//
// 1212 produces 6: the list contains 4 items, and all four digits match the digit 2 items ahead.
// 1221 produces 0, because every comparison is between a 1 and a 2.
// 123425 produces 4, because both 2s match each other, but no other digit has a match.
// 123123 produces 12.
// 12131415 produces 4.
use core::read_data;
fn halfway_sum_thing(input: &str) -> u32 {
let mut running_total = 0;
let total_len = input.len();
let mut mid_point = total_len / 2;
for index in 0..=mid_point {
let second_index = index + mid_point;
let first_char = input.as_bytes()[index];
let second_char = input.as_bytes()[index + mid_point];
println!("{input} / Comparing {index} and {second_index} of {total_len}");
let input_chars: Vec<_> = input.chars().collect();
println!("CHARS INPUT = {input_chars:?}");
// let second = input.chars().collect()[index + mid_point];
if first_char == second_char {
println!("match {first_char} == {second_char}");
} else {
println!("no match");
}
}
running_total as u32
}
fn main() {
let binding = read_data("2017_01_data.txt");
let params = vec![
("1212", 6),
("1221", 0),
("123425", 4),
("123123", 12),
("12131415", 4),
(&binding, 0)
];
for (input, expected) in params {
let result = halfway_sum_thing(input);
println!("Input: {input} results in {result} with {expected} expected.");
assert_eq!(result, expected);
}
}
//
+26
View File
@@ -0,0 +1,26 @@
use core::read_data;
fn main() {
let mut running_total = 0;
let binding = read_data("2017_02_data.txt");
let lines = binding.lines();
for line in lines {
let parts = line.split_whitespace();
let mut highest = 0;
let mut lowest = i32::MAX;
for part in parts {
println!("**PART = {part}");
let val = part.parse().unwrap();
if lowest > val {
lowest = val;
}
if highest < val {
highest = val;
}
}
println!("||{line}|| <<<< LINE DONE -> {highest} > {lowest}");
running_total += highest - lowest;
}
println!("Is the total {running_total}?");
}
// 53460
+35
View File
@@ -0,0 +1,35 @@
// To ensure security, a valid passphrase must contain no duplicate words.
//
// For example:
//
// aa bb cc dd ee is valid.
// aa bb cc dd aa is not valid - the word aa appears more than once.
// aa bb cc dd aaa is valid - aa and aaa count as different words.
// The system's full passphrase list is available as your puzzle input. How many passphrases are valid?
//
use std::collections::HashMap;
use core::read_data;
fn is_valid(input: &str) -> bool {
let parts = input.split(' ');
let mut working = HashMap::new();
for part in parts {
working.entry(part);
}
true
}
fn main() {
// let binding = read_data("2017_04_data.txt");
let params = vec![
("aa bb cc dd ee", true),
("aa bb cc dd aa", false),
("aa bb cc dd aaa", true)
];
for (input, expected) in params {
let actual = is_valid(input);
println!("||{input}|| was expected to be {expected} but was {actual}");
}
}