From c459715f321248cab0cc7081667bb61116d4fc31 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Mon, 2 Dec 2024 09:05:35 +0100 Subject: Base framework --- .gitignore | 133 +++++++++++++++++++ .idea/.gitignore | 8 ++ .idea/aoc2024.iml | 15 +++ .idea/inspectionProfiles/Project_Default.xml | 177 +++++++++++++++++++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + Cargo.toml | 3 + aoc/Cargo.toml | 7 + aoc/src/lib.rs | 74 +++++++++++ 11 files changed, 441 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/aoc2024.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Cargo.toml create mode 100644 aoc/Cargo.toml create mode 100644 aoc/src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f22051 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +# Created by https://www.toptal.com/developers/gitignore/api/rust,intellij +# Edit at https://www.toptal.com/developers/gitignore?templates=rust,intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# End of https://www.toptal.com/developers/gitignore/api/rust,intellij diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/aoc2024.iml b/.idea/aoc2024.iml new file mode 100644 index 0000000..784d79e --- /dev/null +++ b/.idea/aoc2024.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..a9696b0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,177 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..23231ce --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..18c94bc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8018f3d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +members = ["aoc", "day1"] +resolver = "2" \ No newline at end of file diff --git a/aoc/Cargo.toml b/aoc/Cargo.toml new file mode 100644 index 0000000..44564e1 --- /dev/null +++ b/aoc/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap = { version = "4.5.21", features = ["derive"] } diff --git a/aoc/src/lib.rs b/aoc/src/lib.rs new file mode 100644 index 0000000..5fad72d --- /dev/null +++ b/aoc/src/lib.rs @@ -0,0 +1,74 @@ +use clap::Parser; +use std::fs::File; +use std::io; +use std::io::{BufRead, BufReader, Read}; + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Args { + #[arg(short, long, default_value = "-")] + file: String, + + #[arg(short, long, default_value_t = 1)] + part: u8, +} + +pub trait Day { + fn example_input(&self) -> &'static str; + fn example_result_part_1(&self) -> &'static str; + fn example_result_part_2(&self) -> &'static str; + + fn read_lines(&self, input: BufReader>) -> Vec { + let mut lines = Vec::new(); + + for line in input.lines() { + match line { + Ok(content) => lines.push(content), + Err(e) => eprintln!("Error reading line: {}", e), + } + } + + lines + } + + fn part_1(&self, input: BufReader>) -> String; + fn part_2(&self, input: BufReader>) -> String; +} + +pub fn main(day: &dyn Day) { + let args = Args::parse(); + + let reader: Box = if args.file == "-" { + Box::new(io::stdin()) + } else { + Box::new(File::open(&args.file).expect("Failed to open file")) + }; + + let buffer = BufReader::new(reader); + + let result: String; + if args.part == 1 { + result = day.part_1(buffer); + } else { + result = day.part_2(buffer); + } + + println!("Result: {result}") +} + +pub fn test_day(day: &T) { + use std::io::Cursor; + use std::io::{BufReader, Read}; + + let example_input = day.example_input(); + + // Test Part 1 + let input = BufReader::new(Box::new(Cursor::new(example_input)) as Box); + let output = day.part_1(input); + assert_eq!(output.trim(), day.example_result_part_1(), "Part 1 failed"); + + // Test Part 2 + let input = BufReader::new(Box::new(Cursor::new(example_input)) as Box); + let output = day.part_2(input); + assert_eq!(output.trim(), day.example_result_part_2(), "Part 2 failed"); +} \ No newline at end of file -- cgit v1.2.3