moved code around so each year is a package.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "core"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
@@ -0,0 +1,20 @@
|
||||
fn num_to_change(input: &str) -> usize {
|
||||
let mut return_value = 0;
|
||||
let mut last_char = '\0';
|
||||
|
||||
for (index, current_char) in input.chars().enumerate() {
|
||||
if index != 0 {
|
||||
if last_char != current_char {
|
||||
return_value = index;
|
||||
break
|
||||
}
|
||||
}
|
||||
last_char = current_char
|
||||
}
|
||||
return_value
|
||||
}
|
||||
|
||||
fn main () {
|
||||
assert_eq!(num_to_change("01234567"), 1);
|
||||
assert_eq!(num_to_change("00000000001"), 10);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
use std::io::{stdout, Write};
|
||||
|
||||
/// AOC Lib
|
||||
/// Generic methods for loading various data inputs from
|
||||
/// the AOC project.
|
||||
|
||||
pub fn data_path(suffix: &str) -> String {
|
||||
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
stdout().flush().unwrap();
|
||||
format!("{}/../data/{}", path, suffix)
|
||||
}
|
||||
|
||||
pub fn read_data(suffix: &str) -> String {
|
||||
std::fs::read_to_string(
|
||||
data_path(suffix)
|
||||
).unwrap()
|
||||
}
|
||||
|
||||
pub fn string_to_3u32(input: &str) -> Option<(u32, u32, u32)> {
|
||||
let parts: Vec<&str> = input.split('x').collect();
|
||||
if parts.len() == 3 {
|
||||
if let (Ok(a), Ok(b), Ok(c)) = (
|
||||
parts[0].parse::<u32>(),
|
||||
parts[1].parse::<u32>(),
|
||||
parts[2].parse::<u32>(),
|
||||
) {
|
||||
return Some((a, b, c));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn largest_of_vec(to_check: &Vec<u32>) -> u32 {
|
||||
let mut working = to_check[0];
|
||||
for current in to_check {
|
||||
if current > &working {
|
||||
working = *current
|
||||
}
|
||||
}
|
||||
working
|
||||
}
|
||||
pub fn smallest_of_vec(to_check: &Vec<u32>) -> u32 {
|
||||
let mut working = to_check[0];
|
||||
for current in to_check {
|
||||
if current < &working {
|
||||
working = *current
|
||||
}
|
||||
}
|
||||
working
|
||||
}
|
||||
|
||||
pub fn sum_of_vec(to_add: &Vec<u32>) -> u32 {
|
||||
let mut working = 0;
|
||||
for current in to_add {
|
||||
working += current
|
||||
}
|
||||
working
|
||||
}
|
||||
Reference in New Issue
Block a user