Compare commits
No commits in common. "7510bc2f59385e9ef958f6731752906035cb935d" and "5b22965ad39a98e4348707afe61a658ffd175bae" have entirely different histories.
7510bc2f59
...
5b22965ad3
|
@ -1,2 +0,0 @@
|
||||||
/target
|
|
||||||
/Cargo.lock
|
|
|
@ -1,12 +0,0 @@
|
||||||
[workspace]
|
|
||||||
members = [
|
|
||||||
"common",
|
|
||||||
"day-1_calorie_counting",
|
|
||||||
"day-2_rock_paper_scissors",
|
|
||||||
"day-3_rucksack_reorganization",
|
|
||||||
]
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 1
|
|
|
@ -1,95 +0,0 @@
|
||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "common"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "once_cell"
|
|
||||||
version = "1.16.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pin-project-lite"
|
|
||||||
version = "0.2.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.47"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.105"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing"
|
|
||||||
version = "0.1.37"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"pin-project-lite",
|
|
||||||
"tracing-attributes",
|
|
||||||
"tracing-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-attributes"
|
|
||||||
version = "0.1.23"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-core"
|
|
||||||
version = "0.1.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
|
||||||
dependencies = [
|
|
||||||
"once_cell",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
|
|
@ -1,9 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "common"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
tracing = "0.1.0"
|
|
||||||
clap = {version = "4.0.22", features = ["derive"]}
|
|
|
@ -1,24 +0,0 @@
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::Path;
|
|
||||||
use tracing::{debug, info};
|
|
||||||
|
|
||||||
pub mod cli;
|
|
||||||
|
|
||||||
pub fn create_file(path: &Path, content: String) {
|
|
||||||
info!("Creating file");
|
|
||||||
debug!("Writing file from: {:?}\nWith:\n{}", path, content);
|
|
||||||
|
|
||||||
let mut file = File::create(path).unwrap();
|
|
||||||
let _ = file.write_all(content.as_bytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_file(path: &Path) -> std::io::Result<String> {
|
|
||||||
info!("Reading file");
|
|
||||||
debug!("Reading file from: {:?}", path);
|
|
||||||
|
|
||||||
let mut file = File::open(path)?;
|
|
||||||
let mut contents = String::new();
|
|
||||||
let _ = file.read_to_string(&mut contents)?;
|
|
||||||
Ok(contents.trim().to_string())
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
/input.txt
|
|
|
@ -1,6 +0,0 @@
|
||||||
# Calorie Counting
|
|
||||||
Some quick and dirty python code, that didn't make me cry.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Expecting the `input.txt` in the same folder as the `main.py`
|
|
||||||
`python main.py`
|
|
|
@ -1,9 +0,0 @@
|
||||||
def task_1a():
|
|
||||||
return max([sum([int(calorie) for calorie in elf.split() if calorie]) for elf in open('input.txt', 'r').read().split("\n\n") if elf])
|
|
||||||
|
|
||||||
def task_1b():
|
|
||||||
return sum(sorted([sum([int(calorie) for calorie in elf.split() if calorie]) for elf in open('input.txt', 'r').read().split("\n\n") if elf])[-3:])
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print(f"Result (1a): {task_1a()}")
|
|
||||||
print(f"Result (1b): {task_1b()}")
|
|
|
@ -1,54 +0,0 @@
|
||||||
# --- Day 1: Calorie Counting ---
|
|
||||||
|
|
||||||
Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas. For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you on their annual expedition to the grove where the fruit grows.
|
|
||||||
|
|
||||||
To supply enough magical energy, the expedition needs to retrieve a minimum of fifty stars by December 25th. Although the Elves assure you that the grove has plenty of fruit, you decide to grab any fruit you see along the way, just in case.
|
|
||||||
|
|
||||||
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
|
||||||
|
|
||||||
## --- Part One ---
|
|
||||||
|
|
||||||
The jungle must be too overgrown and difficult to navigate in vehicles or access from the air; the Elves' expedition traditionally goes on foot. As your boats approach land, the Elves begin taking inventory of their supplies. One important consideration is food - in particular, the number of Calories each Elf is carrying (your puzzle input).
|
|
||||||
|
|
||||||
The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with them, one item per line. Each Elf separates their own inventory from the previous Elf's inventory (if any) by a blank line.
|
|
||||||
|
|
||||||
For example, suppose the Elves finish writing their items' Calories and end up with the following list:
|
|
||||||
|
|
||||||
```
|
|
||||||
1000
|
|
||||||
2000
|
|
||||||
3000
|
|
||||||
|
|
||||||
4000
|
|
||||||
|
|
||||||
5000
|
|
||||||
6000
|
|
||||||
|
|
||||||
7000
|
|
||||||
8000
|
|
||||||
9000
|
|
||||||
|
|
||||||
10000
|
|
||||||
```
|
|
||||||
|
|
||||||
This list represents the Calories of the food carried by five Elves:
|
|
||||||
|
|
||||||
The first Elf is carrying food with 1000, 2000, and 3000 Calories, a total of 6000 Calories.
|
|
||||||
The second Elf is carrying one food item with 4000 Calories.
|
|
||||||
The third Elf is carrying food with 5000 and 6000 Calories, a total of 11000 Calories.
|
|
||||||
The fourth Elf is carrying food with 7000, 8000, and 9000 Calories, a total of 24000 Calories.
|
|
||||||
The fifth Elf is carrying one food item with 10000 Calories.
|
|
||||||
|
|
||||||
In case the Elves get hungry and need extra snacks, they need to know which Elf to ask: they'd like to know how many Calories are being carried by the Elf carrying the most Calories. In the example above, this is 24000 (carried by the fourth Elf).
|
|
||||||
|
|
||||||
Find the Elf carrying the most Calories. **How many total Calories is that Elf carrying?**
|
|
||||||
|
|
||||||
## --- Part Two ---
|
|
||||||
|
|
||||||
By the time you calculate the answer to the Elves' question, they've already realized that the Elf carrying the most Calories of food might eventually run out of snacks.
|
|
||||||
|
|
||||||
To avoid this unacceptable situation, the Elves would instead like to know the total Calories carried by the top three Elves carrying the most Calories. That way, even if one of those Elves runs out of snacks, they still have two backups.
|
|
||||||
|
|
||||||
In the example above, the top three Elves are the fourth Elf (with 24000 Calories), then the third Elf (with 11000 Calories), then the fifth Elf (with 10000 Calories). The sum of the Calories carried by these three elves is 45000.
|
|
||||||
|
|
||||||
Find the top three Elves carrying the most Calories. **How many Calories are those Elves carrying in total?**
|
|
|
@ -57,20 +57,11 @@ dependencies = [
|
||||||
"os_str_bytes",
|
"os_str_bytes",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "common"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day-1_calorie_counting"
|
name = "day-1_calorie_counting"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"common",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,16 +3,20 @@ name = "day-1_calorie_counting"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 1
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "calorie_counting_lib"
|
name = "calorie_counting_lib"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "calorie_counting"
|
name = "calorie_counting_bin"
|
||||||
path = "src/bin.rs"
|
path = "src/bin.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = {version = "4.0.22", features = ["derive"]}
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = {version = "0.3.16", features = ["env-filter"]}
|
tracing-subscriber = {version = "0.3.16", features = ["env-filter"]}
|
||||||
common = {path = "../common/"}
|
|
||||||
clap = {version = "4.0.22", features = ["derive"]}
|
|
|
@ -1,13 +1,2 @@
|
||||||
# Calorie Counting
|
|
||||||
Implementation of [this task](./task.md) that started clean but ended up in a lot of [bodging](https://en.wiktionary.org/wiki/bodge).
|
|
||||||
|
|
||||||
<sup>and is very much not idiomatic rust</sup>
|
Usage: `cargo run --release -- --input <Path to file with inputs`
|
||||||
|
|
||||||
## Usage
|
|
||||||
`cargo run --release -- --input <Path to file with inputs>`
|
|
||||||
|
|
||||||
Alternative
|
|
||||||
```sh
|
|
||||||
cargo install --release .
|
|
||||||
calorie_counting -i <Path to file with inputs>
|
|
||||||
```
|
|
||||||
|
|
|
@ -1,17 +1,46 @@
|
||||||
use common::cli::Cli;
|
use calorie_counting_lib::*;
|
||||||
|
use std::path::PathBuf;
|
||||||
use calorie_counting_lib::{task_1a, task_1b};
|
use std::collections::BinaryHeap;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use tracing::{info, debug};
|
use tracing::{info, debug};
|
||||||
|
use crate::cli::Cli;
|
||||||
|
|
||||||
|
mod cli;
|
||||||
|
|
||||||
|
/// Finds the Elf carrying the most Calories.
|
||||||
|
/// Outputs how many total Calories that Elf is carrying.
|
||||||
|
fn task_1a(input: &PathBuf) {
|
||||||
|
debug!("Running task 1a");
|
||||||
|
let file_path = input;
|
||||||
|
let content = calorie_counting_lib::read_file(file_path).unwrap();
|
||||||
|
let splits = content.split("\n\n");
|
||||||
|
|
||||||
|
println!("{}", splits.map(|s| Elf::new(s).total_calories()).max().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Finds the top three Elves carrying the most Calories.
|
||||||
|
/// Outputs how many Calories those Elves are carrying in total.
|
||||||
|
fn task_1b(input: &PathBuf) {
|
||||||
|
debug!("Running task 1b");
|
||||||
|
let file_path = input;
|
||||||
|
let content = calorie_counting_lib::read_file(file_path).unwrap();
|
||||||
|
let splits = content.split("\n\n");
|
||||||
|
let mut heap = splits.map(|s| Elf::new(s).total_calories()).collect::<BinaryHeap<_>>();
|
||||||
|
|
||||||
|
let mut top_three = Vec::new();
|
||||||
|
for _ in 0..3 {
|
||||||
|
if let Some(c) = heap.pop() {
|
||||||
|
top_three.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{}", top_three.iter().sum::<u64>());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
debug!("Running with DEBUG logging");
|
debug!("Running with debugging level logging");
|
||||||
info!("Running with INFO logging");
|
|
||||||
|
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
debug!("{:#?}", args);
|
|
||||||
|
|
||||||
task_1a(&args.input);
|
task_1a(&args.input);
|
||||||
task_1b(&args.input);
|
task_1b(&args.input);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use clap::Parser;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about=None, long_about = None)]
|
#[command(author, version, about="CLI tool to output latency at a given gps location.", long_about = None)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Path to the input file.
|
/// Path to the input file.
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
|
@ -1,30 +0,0 @@
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Elf {
|
|
||||||
_input: String,
|
|
||||||
calories: Vec<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Elf {
|
|
||||||
pub fn new(input: &str) -> Self {
|
|
||||||
let cal: Vec<u64> = input
|
|
||||||
.split('\n')
|
|
||||||
.map(|i| i.parse::<u64>().unwrap())
|
|
||||||
.collect();
|
|
||||||
Self {
|
|
||||||
_input: input.to_string(),
|
|
||||||
calories: cal,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn total_calories(self) -> u64 {
|
|
||||||
self.calories.iter().sum()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Elf {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "Elf: {:?}", self.calories)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +1,91 @@
|
||||||
use std::path::PathBuf;
|
use std::fs::File;
|
||||||
use std::collections::BinaryHeap;
|
use std::io::{Write, Read};
|
||||||
use tracing::{debug, info};
|
use std::path::Path;
|
||||||
use common::read_file;
|
use std::fmt;
|
||||||
|
use tracing::{info, debug};
|
||||||
|
|
||||||
mod elf;
|
pub fn create_file(path: &Path, content: String) {
|
||||||
use crate::elf::Elf;
|
debug!("Creating file");
|
||||||
|
let mut file = File::create(path).unwrap();
|
||||||
|
let _ = file.write_all(content.as_bytes());
|
||||||
/// Finds the Elf carrying the most Calories.
|
|
||||||
/// Outputs how many total Calories that Elf is carrying.
|
|
||||||
pub fn task_1a(input: &PathBuf) {
|
|
||||||
debug!("Running task 1a");
|
|
||||||
info!("Running task 1a with {:?}", input);
|
|
||||||
|
|
||||||
let content = read_file(input).unwrap();
|
|
||||||
let splits = content.split("\n\n");
|
|
||||||
println!("Result (1a): {}", splits.map(|s| Elf::new(s).total_calories()).max().unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the top three Elves carrying the most Calories.
|
pub fn read_file(path: &Path) -> std::io::Result<String> {
|
||||||
/// Outputs how many Calories those Elves are carrying in total.
|
debug!("Reading file");
|
||||||
pub fn task_1b(input: &PathBuf) {
|
let mut file = File::open(path)?;
|
||||||
debug!("Running task 1b");
|
let mut contents = String::new();
|
||||||
info!("Running task 1b with {:?}", input);
|
let _ = file.read_to_string(&mut contents)?;
|
||||||
|
Ok(contents.trim().to_string())
|
||||||
let content = read_file(input).unwrap();
|
}
|
||||||
let splits = content.split("\n\n");
|
|
||||||
let mut heap = splits.map(|s| Elf::new(s).total_calories()).collect::<BinaryHeap<_>>();
|
|
||||||
|
|
||||||
let mut sum = 0u64;
|
#[derive(Debug, Clone)]
|
||||||
for _ in 0..3 {
|
pub struct Elf {
|
||||||
if let Some(c) = heap.pop() {
|
_input: String,
|
||||||
sum += c;
|
calories: Vec<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Elf {
|
||||||
|
pub fn new (input: &str) -> Self {
|
||||||
|
let cal: Vec<u64> = input.split('\n')
|
||||||
|
.map(|i| i.parse::<u64>().unwrap())
|
||||||
|
.collect();
|
||||||
|
Self { _input: input.to_string(), calories: cal }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn total_calories(self) -> u64 {
|
||||||
|
self.calories.iter().sum()
|
||||||
}
|
}
|
||||||
println!("Result (1b): {}", sum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Elf{
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "Elf: {:?}", self.calories)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pub fn get_calories() -> std::io::Result<Vec<Elf>> {
|
||||||
|
// let content = read_file(Path::new("input.txt"))?;
|
||||||
|
// }
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::fs::remove_file;
|
use std::fs::remove_file;
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
use common::{create_file, read_file};
|
|
||||||
|
|
||||||
const PATH: &str = "input.txt";
|
const PATH: &str = "input.txt";
|
||||||
const CONTENT: &[u8; 54] =
|
const CONTENT: &[u8; 55] = b"1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000\n";
|
||||||
b"1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000";
|
|
||||||
|
|
||||||
fn create_test_setup() {
|
fn create_test_setup() {
|
||||||
let file_path = &PathBuf::from(PATH);
|
let file_path = Path::new(PATH);
|
||||||
let original = CONTENT;
|
let original = CONTENT;
|
||||||
create_file(file_path, from_utf8(original).unwrap().to_string());
|
create_file(file_path, from_utf8(original).unwrap().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup_test_setup() {
|
fn cleanup_test_setup() {
|
||||||
let _ = remove_file(&PathBuf::from(PATH));
|
let _ = remove_file(&Path::new(PATH));
|
||||||
}
|
}
|
||||||
/// Test if we corretly read file input.
|
/// Test if we corretly read file input.
|
||||||
#[test]
|
#[test]
|
||||||
fn file_io() {
|
fn file_io() {
|
||||||
create_test_setup();
|
create_test_setup();
|
||||||
let content = read_file(&PathBuf::from(PATH));
|
let content = read_file(&Path::new(PATH));
|
||||||
|
cleanup_test_setup();
|
||||||
|
assert_eq!(from_utf8(CONTENT).unwrap(), content.unwrap().to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Test if the calculation of calories each elf is carrying is correct.
|
||||||
|
#[test]
|
||||||
|
fn elf_calories() {
|
||||||
|
create_test_setup();
|
||||||
|
let content = read_file(&Path::new(PATH)).unwrap();
|
||||||
|
let file_path = Path::new("input.txt");
|
||||||
|
let content = calorie_counting_lib::read_file(file_path).unwrap();
|
||||||
|
let splits = content.split("\n\n");
|
||||||
|
let result_vec = Vec::<u64>::new();
|
||||||
|
for elf in splits.map(|s| Elf::new(s)) {
|
||||||
|
result_vec.push(elf.total_calories());
|
||||||
|
}
|
||||||
cleanup_test_setup();
|
cleanup_test_setup();
|
||||||
assert_eq!(from_utf8(CONTENT).unwrap(), content.unwrap());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
/input.txt
|
|
|
@ -1,34 +0,0 @@
|
||||||
def calc(u1, u2):
|
|
||||||
if u1 == u2:
|
|
||||||
print(f'{chr(u1+ord("A")-1)} {chr(u2+ord("X")-1)} draw')
|
|
||||||
return u2 + 3
|
|
||||||
elif u1 == (u2 % 3 - 1):
|
|
||||||
print(f'{chr(u1+ord("A")-1)} {chr(u2+ord("X")-1)} win')
|
|
||||||
return u2 + 6
|
|
||||||
else:
|
|
||||||
print(f'{chr(u1+ord("A")-1)} {chr(u2+ord("X")-1)} loss')
|
|
||||||
return u2 + 0
|
|
||||||
|
|
||||||
def test_2a(file):
|
|
||||||
res = []
|
|
||||||
for l in open(file, 'r').read().split('\n'):
|
|
||||||
if l:
|
|
||||||
a, b = l.split()
|
|
||||||
res.append(calc(*(ord(a) - ord("A") + 1, ord(b) - ord("X") + 1)))
|
|
||||||
res = sum(res)
|
|
||||||
print(res)
|
|
||||||
apprehension = task_2a(file)
|
|
||||||
assert res == apprehension
|
|
||||||
|
|
||||||
|
|
||||||
def task_2a(file):
|
|
||||||
numify = lambda a_b: (ord(a_b[0]) - ord("A") + 1, ord(a_b[1]) - ord("X") + 1)
|
|
||||||
return sum([calc(*numify(l.split())) for l in open(file, 'r').read().split('\n') if l])
|
|
||||||
|
|
||||||
def task_2b(file):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print(task_2a('input.txt'))
|
|
||||||
# print(task_2b('input.txt'))
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
Gave up for now, tried to solve the task more or less functionally/mathematically, but it didn't work out.
|
|
||||||
|
|
||||||
Related:
|
|
||||||
- [Calculus on finite weighted graphs](https://en.wikipedia.org/wiki/Calculus_on_finite_weighted_graphs)
|
|
||||||
- ![notes](whiteboard_notes.jpeg)
|
|
Binary file not shown.
Before Width: | Height: | Size: 181 KiB |
|
@ -1,2 +0,0 @@
|
||||||
/input
|
|
||||||
/target
|
|
|
@ -1,528 +0,0 @@
|
||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "1.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cc"
|
|
||||||
version = "1.0.77"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap"
|
|
||||||
version = "4.0.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"clap_derive",
|
|
||||||
"clap_lex",
|
|
||||||
"is-terminal",
|
|
||||||
"once_cell",
|
|
||||||
"strsim",
|
|
||||||
"termcolor",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap_derive"
|
|
||||||
version = "4.0.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap_lex"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
|
|
||||||
dependencies = [
|
|
||||||
"os_str_bytes",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "common"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "errno"
|
|
||||||
version = "0.2.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
|
|
||||||
dependencies = [
|
|
||||||
"errno-dragonfly",
|
|
||||||
"libc",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "errno-dragonfly"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hermit-abi"
|
|
||||||
version = "0.2.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "io-lifetimes"
|
|
||||||
version = "1.0.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "is-terminal"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi",
|
|
||||||
"io-lifetimes",
|
|
||||||
"rustix",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.137"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "linux-raw-sys"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log"
|
|
||||||
version = "0.4.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "matchers"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
|
||||||
dependencies = [
|
|
||||||
"regex-automata",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nu-ansi-term"
|
|
||||||
version = "0.46.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
|
||||||
dependencies = [
|
|
||||||
"overload",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "once_cell"
|
|
||||||
version = "1.16.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "os_str_bytes"
|
|
||||||
version = "6.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "overload"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pin-project-lite"
|
|
||||||
version = "0.2.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.47"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex"
|
|
||||||
version = "1.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
|
|
||||||
dependencies = [
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-automata"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
|
||||||
dependencies = [
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-syntax"
|
|
||||||
version = "0.6.28"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rock_paper_scissors"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"common",
|
|
||||||
"strum",
|
|
||||||
"strum_macros",
|
|
||||||
"tracing",
|
|
||||||
"tracing-subscriber",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustix"
|
|
||||||
version = "0.36.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cb93e85278e08bb5788653183213d3a60fc242b10cb9be96586f5a73dcb67c23"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"errno",
|
|
||||||
"io-lifetimes",
|
|
||||||
"libc",
|
|
||||||
"linux-raw-sys",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustversion"
|
|
||||||
version = "1.0.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sharded-slab"
|
|
||||||
version = "0.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
|
|
||||||
dependencies = [
|
|
||||||
"lazy_static",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "smallvec"
|
|
||||||
version = "1.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strsim"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strum"
|
|
||||||
version = "0.24.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strum_macros"
|
|
||||||
version = "0.24.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"rustversion",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.105"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termcolor"
|
|
||||||
version = "1.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thread_local"
|
|
||||||
version = "1.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
|
|
||||||
dependencies = [
|
|
||||||
"once_cell",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing"
|
|
||||||
version = "0.1.37"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"pin-project-lite",
|
|
||||||
"tracing-attributes",
|
|
||||||
"tracing-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-attributes"
|
|
||||||
version = "0.1.23"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-core"
|
|
||||||
version = "0.1.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
|
||||||
dependencies = [
|
|
||||||
"once_cell",
|
|
||||||
"valuable",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-log"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
|
|
||||||
dependencies = [
|
|
||||||
"lazy_static",
|
|
||||||
"log",
|
|
||||||
"tracing-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-subscriber"
|
|
||||||
version = "0.3.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
|
|
||||||
dependencies = [
|
|
||||||
"matchers",
|
|
||||||
"nu-ansi-term",
|
|
||||||
"once_cell",
|
|
||||||
"regex",
|
|
||||||
"sharded-slab",
|
|
||||||
"smallvec",
|
|
||||||
"thread_local",
|
|
||||||
"tracing",
|
|
||||||
"tracing-core",
|
|
||||||
"tracing-log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "valuable"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version_check"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.3.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-i686-pc-windows-gnu",
|
|
||||||
"winapi-x86_64-pc-windows-gnu",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-util"
|
|
||||||
version = "0.1.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
|
||||||
dependencies = [
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-sys"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
|
||||||
dependencies = [
|
|
||||||
"windows_aarch64_gnullvm",
|
|
||||||
"windows_aarch64_msvc",
|
|
||||||
"windows_i686_gnu",
|
|
||||||
"windows_i686_msvc",
|
|
||||||
"windows_x86_64_gnu",
|
|
||||||
"windows_x86_64_gnullvm",
|
|
||||||
"windows_x86_64_msvc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_gnullvm"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_msvc"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_gnu"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_msvc"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnu"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnullvm"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_msvc"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
|
|
|
@ -1,23 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "rock_paper_scissors"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "rock_paper_scissors_lib"
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "rock_paper_scissors"
|
|
||||||
path = "src/bin.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
common = {path = "../common/"}
|
|
||||||
|
|
||||||
clap = {version = "4.0.22", features = ["derive"]}
|
|
||||||
tracing = "0.1"
|
|
||||||
tracing-subscriber = {version = "0.3.16", features = ["env-filter"]}
|
|
||||||
strum = "0.24.1"
|
|
||||||
strum_macros = "0.24"
|
|
|
@ -1,14 +0,0 @@
|
||||||
# Calorie Counting
|
|
||||||
Implementation of [this task](./task.md). I tried to do it idiomatically, but it quickly turned into a mess when part two was introduced.
|
|
||||||
|
|
||||||
<sub>I'm sensing a theme here</sub>
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
`cargo run --release -- --input <Path to file with inputs>`
|
|
||||||
|
|
||||||
Alternative
|
|
||||||
```sh
|
|
||||||
cargo install --release .
|
|
||||||
rock_paper_scissors -i <Path to file with inputs>
|
|
||||||
```
|
|
|
@ -1,16 +0,0 @@
|
||||||
use rock_paper_scissors_lib::{task_2a, task_2b};
|
|
||||||
use clap::Parser;
|
|
||||||
use tracing::debug;
|
|
||||||
|
|
||||||
mod cli;
|
|
||||||
use crate::cli::Cli;
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
tracing_subscriber::fmt::init();
|
|
||||||
|
|
||||||
let args = Cli::parse();
|
|
||||||
debug!("Args: {:?}", args);
|
|
||||||
|
|
||||||
println!("Result (2a): {}", task_2a(&args.input));
|
|
||||||
println!("Result (2b): {}", task_2b(&args.input));
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
use strum::IntoEnumIterator;
|
|
||||||
use strum_macros::{Display, EnumIter};
|
|
||||||
use tracing::{info, debug};
|
|
||||||
|
|
||||||
use crate::gameresult::GameResult;
|
|
||||||
|
|
||||||
/// Enum containing the possible choices for Rock, Paper, Scissors.
|
|
||||||
#[derive(Display, Clone, Eq, PartialEq, EnumIter)]
|
|
||||||
pub enum Choice {
|
|
||||||
Rock,
|
|
||||||
Paper,
|
|
||||||
Scissors,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Choice {
|
|
||||||
/// Returns the outcome of the game from `i`s perspective, playing against `other`.
|
|
||||||
fn win(i: &Choice, other: &Choice) -> GameResult {
|
|
||||||
debug!("Get GameResult based on {}, {}", i, other);
|
|
||||||
|
|
||||||
let result = match (i, other) {
|
|
||||||
(Choice::Rock, Choice::Scissors) => GameResult::Win,
|
|
||||||
(Choice::Paper, Choice::Rock) => GameResult::Win,
|
|
||||||
(Choice::Scissors, Choice::Paper) => GameResult::Win,
|
|
||||||
_ if i == other => GameResult::Draw,
|
|
||||||
_ => GameResult::Loose
|
|
||||||
};
|
|
||||||
info!("GameResult: {}", &result);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculate score based on `self`s and `other`s =Rock, Paper, Scissors=-choice and the resulting outcome.
|
|
||||||
pub fn play(&self, other: &Choice) -> u64 {
|
|
||||||
debug!("Get score based on {}, {}", &self, other);
|
|
||||||
|
|
||||||
let hand_value = match self {
|
|
||||||
Choice::Rock => 1,
|
|
||||||
Choice::Paper => 2,
|
|
||||||
Choice::Scissors => 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
let game_value = match Choice::win(self, other) {
|
|
||||||
GameResult::Win => 6,
|
|
||||||
GameResult::Draw => 3,
|
|
||||||
GameResult::Loose => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = hand_value + game_value;
|
|
||||||
|
|
||||||
info!("Score: {}", &result);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculates the score based on the wished upon `outcome` when `self` is the opponents choice.
|
|
||||||
pub fn cheat(&self, outcome: &GameResult) -> u64 {
|
|
||||||
debug!("Get score by cheating based on {}, {}", &self, outcome);
|
|
||||||
|
|
||||||
let user_choice = Choice::iter().filter(|c| &Choice::win(&c, &self) == outcome).next();
|
|
||||||
let result =user_choice.unwrap().play(&self);
|
|
||||||
info!("Score: {}", result);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
use std::path::PathBuf;
|
|
||||||
use clap::Parser;
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
|
||||||
#[command(author, version, about=None, long_about = None)]
|
|
||||||
pub struct Cli {
|
|
||||||
/// Path to input file
|
|
||||||
#[arg(short, long)]
|
|
||||||
pub input: PathBuf
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
use strum_macros::Display;
|
|
||||||
|
|
||||||
/// Enum containing the possible outcomes for Rock, Paper, Scissors.
|
|
||||||
#[derive(Display, Clone, Eq, PartialEq)]
|
|
||||||
pub enum GameResult {
|
|
||||||
Win,
|
|
||||||
Loose,
|
|
||||||
Draw
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
use common::read_file;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use tracing::{info, debug};
|
|
||||||
|
|
||||||
mod choice;
|
|
||||||
use crate::choice::Choice;
|
|
||||||
|
|
||||||
mod gameresult;
|
|
||||||
use crate::gameresult::GameResult;
|
|
||||||
|
|
||||||
/// Calculates score for single game, given specification from part one of the task.
|
|
||||||
fn calculate_result_1a(line: &str) -> u64 {
|
|
||||||
debug!("Get score for 1a of game {}", line);
|
|
||||||
|
|
||||||
let mut input = line.chars();
|
|
||||||
let opponent_choice = match input.next() {
|
|
||||||
Some('A') => Choice::Rock,
|
|
||||||
Some('B') => Choice::Paper,
|
|
||||||
Some('C') => Choice::Scissors,
|
|
||||||
_ => Choice::Rock, // Todo: Error handling, this shouldn't happen
|
|
||||||
};
|
|
||||||
|
|
||||||
input.next();
|
|
||||||
|
|
||||||
let user_choice = match input.next() {
|
|
||||||
Some('X') => Choice::Rock,
|
|
||||||
Some('Y') => Choice::Paper,
|
|
||||||
Some('Z') => Choice::Scissors,
|
|
||||||
_ => Choice::Rock, // Todo: Error handling, this shouldn't happen
|
|
||||||
};
|
|
||||||
let result = user_choice.play(&opponent_choice);
|
|
||||||
info!("Total score (1a): {}", result);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculates score for single game, given specification from part two of the task.
|
|
||||||
fn calculate_result_1b(line: &str) -> u64 {
|
|
||||||
debug!("Get score for 1b of game {}", line);
|
|
||||||
|
|
||||||
let mut input = line.chars();
|
|
||||||
let opponent_choice = match input.next() {
|
|
||||||
Some('A') => Choice::Rock,
|
|
||||||
Some('B') => Choice::Paper,
|
|
||||||
Some('C') => Choice::Scissors,
|
|
||||||
_ => Choice::Rock, // Todo: Error handling, this shouldn't happen
|
|
||||||
};
|
|
||||||
|
|
||||||
input.next();
|
|
||||||
|
|
||||||
let outcome = match input.next() {
|
|
||||||
Some('X') => GameResult::Loose,
|
|
||||||
Some('Y') => GameResult::Draw,
|
|
||||||
Some('Z') => GameResult::Win,
|
|
||||||
_ => GameResult::Loose, // Todo: Error handling, this shouldn't happen
|
|
||||||
};
|
|
||||||
let result = opponent_choice.cheat(&outcome);
|
|
||||||
info!("Total score (1b): {}", result);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn task_2a(input: &PathBuf) -> u64 {
|
|
||||||
let content = read_file(input).unwrap();
|
|
||||||
content.split('\n').map(|l| {
|
|
||||||
let r = calculate_result_1a(l);
|
|
||||||
info!("{}", r);
|
|
||||||
r
|
|
||||||
}).sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn task_2b(input: &PathBuf) -> u64 {
|
|
||||||
let content = read_file(input).unwrap();
|
|
||||||
content.split('\n').map(|l| calculate_result_1b(l)).sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use common::create_file;
|
|
||||||
use std::fs::remove_file;
|
|
||||||
|
|
||||||
const PATH: &str = "input.txt";
|
|
||||||
const CONTENT: &str = "A Y\nB X\nC Z";
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_task_2a() {
|
|
||||||
let test_file = PathBuf::from(PATH);
|
|
||||||
create_file(&test_file, CONTENT.to_string());
|
|
||||||
let result = task_2a(&test_file);
|
|
||||||
let _ = remove_file(&test_file);
|
|
||||||
let expected = 15u64;
|
|
||||||
|
|
||||||
assert_eq!(result, expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_task_2b() {
|
|
||||||
let test_file = PathBuf::from(PATH);
|
|
||||||
create_file(&test_file, CONTENT.to_string());
|
|
||||||
let result = task_2b(&test_file);
|
|
||||||
let _ = remove_file(&test_file);
|
|
||||||
let expected = 12u64;
|
|
||||||
|
|
||||||
assert_eq!(result, expected);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
# --- Day 2: Rock Paper Scissors ---
|
|
||||||
## --- Part One ---
|
|
||||||
|
|
||||||
The Elves begin to set up camp on the beach. To decide whose tent gets to be closest to the snack storage, a giant Rock Paper Scissors tournament is already in progress.
|
|
||||||
|
|
||||||
Rock Paper Scissors is a game between two players. Each game contains many rounds; in each round, the players each simultaneously choose one of Rock, Paper, or Scissors using a hand shape. Then, a winner for that round is selected: Rock defeats Scissors, Scissors defeats Paper, and Paper defeats Rock. If both players choose the same shape, the round instead ends in a draw.
|
|
||||||
|
|
||||||
Appreciative of your help yesterday, one Elf gives you an encrypted strategy guide (your puzzle input) that they say will be sure to help you win. "The first column is what your opponent is going to play: A for Rock, B for Paper, and C for Scissors. The second column--" Suddenly, the Elf is called away to help with someone's tent.
|
|
||||||
|
|
||||||
The second column, you reason, must be what you should play in response: X for Rock, Y for Paper, and Z for Scissors. Winning every time would be suspicious, so the responses must have been carefully chosen.
|
|
||||||
|
|
||||||
The winner of the whole tournament is the player with the highest score. Your total score is the sum of your scores for each round. The score for a single round is the score for the shape you selected (1 for Rock, 2 for Paper, and 3 for Scissors) plus the score for the outcome of the round (0 if you lost, 3 if the round was a draw, and 6 if you won).
|
|
||||||
|
|
||||||
Since you can't be sure if the Elf is trying to help you or trick you, you should calculate the score you would get if you were to follow the strategy guide.
|
|
||||||
|
|
||||||
For example, suppose you were given the following strategy guide:
|
|
||||||
|
|
||||||
```
|
|
||||||
A Y
|
|
||||||
B X
|
|
||||||
C Z
|
|
||||||
```
|
|
||||||
|
|
||||||
This strategy guide predicts and recommends the following:
|
|
||||||
|
|
||||||
In the first round, your opponent will choose Rock (A), and you should choose Paper (Y). This ends in a win for you with a score of 8 (2 because you chose Paper + 6 because you won).
|
|
||||||
In the second round, your opponent will choose Paper (B), and you should choose Rock (X). This ends in a loss for you with a score of 1 (1 + 0).
|
|
||||||
The third round is a draw with both players choosing Scissors, giving you a score of 3 + 3 = 6.
|
|
||||||
|
|
||||||
In this example, if you were to follow the strategy guide, you would get a total score of 15 (8 + 1 + 6).
|
|
||||||
|
|
||||||
**What would your total score be if everything goes exactly according to your strategy guide?**
|
|
||||||
|
|
||||||
### --- Part Two ---
|
|
||||||
|
|
||||||
The Elf finishes helping with the tent and sneaks back over to you. "Anyway, the second column says how the round needs to end: X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. Good luck!"
|
|
||||||
|
|
||||||
The total score is still calculated in the same way, but now you need to figure out what shape to choose so the round ends as indicated. The example above now goes like this:
|
|
||||||
|
|
||||||
In the first round, your opponent will choose Rock (A), and you need the round to end in a draw (Y), so you also choose Rock. This gives you a score of 1 + 3 = 4.
|
|
||||||
In the second round, your opponent will choose Paper (B), and you choose Rock so you lose (X) with a score of 1 + 0 = 1.
|
|
||||||
In the third round, you will defeat your opponent's Scissors with Rock for a score of 1 + 6 = 7.
|
|
||||||
|
|
||||||
Now that you're correctly decrypting the ultra top secret strategy guide, you would get a total score of 12.
|
|
||||||
|
|
||||||
**Following the Elf's instructions for the second column, what would your total score be if everything goes exactly according to your strategy guide?**
|
|
|
@ -1 +0,0 @@
|
||||||
/input.txt
|
|
|
@ -1,9 +0,0 @@
|
||||||
# Rucksack Reorganization
|
|
||||||
Created this solution first, since the implementation seemed fairly easy.
|
|
||||||
Turns out it was.
|
|
||||||
|
|
||||||
<sub> Could use some more list comprehensions though </sub>
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Expecting the `input.txt` in the same folder as the `main.py`
|
|
||||||
`python main.py`
|
|
|
@ -1,26 +0,0 @@
|
||||||
def task3a():
|
|
||||||
sum = 0
|
|
||||||
for rucksack in open('input.txt', 'r').read().splitlines():
|
|
||||||
left = rucksack[:int(len(rucksack)/2)]
|
|
||||||
right= rucksack[int(len(rucksack)/2):]
|
|
||||||
|
|
||||||
common = [c for c in left if c in right][0]
|
|
||||||
priority = ord(common) - ord('a') + 1 if common.islower() else ord(common) - ord('A') + 27
|
|
||||||
# print(f"{common}: {priority}")
|
|
||||||
sum += priority
|
|
||||||
return sum
|
|
||||||
print(f'Task 3a: {task3a()}')
|
|
||||||
|
|
||||||
def task3b():
|
|
||||||
sum = 0
|
|
||||||
lines = open('input.txt', 'r').read().splitlines()
|
|
||||||
for rucksacks in [lines[n:n+3] for n in range(0, len(lines), 3)]:
|
|
||||||
common = [d for d in [c for c in rucksacks[0] if c in rucksacks[1]] if d in rucksacks[2]][0]
|
|
||||||
priority = ord(common) - ord('a') + 1 if common.islower() else ord(common) - ord('A') + 27
|
|
||||||
# print(f"{common}: {priority}")
|
|
||||||
sum += priority
|
|
||||||
return sum
|
|
||||||
|
|
||||||
print(f'Task 3b: {task3b()}')
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
/target
|
|
||||||
/input
|
|
|
@ -1,518 +0,0 @@
|
||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "1.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cc"
|
|
||||||
version = "1.0.77"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap"
|
|
||||||
version = "4.0.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"clap_derive",
|
|
||||||
"clap_lex",
|
|
||||||
"is-terminal",
|
|
||||||
"once_cell",
|
|
||||||
"strsim",
|
|
||||||
"termcolor",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap_derive"
|
|
||||||
version = "4.0.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap_lex"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
|
|
||||||
dependencies = [
|
|
||||||
"os_str_bytes",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "common"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "day-3_rucksack_reorganization"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"common",
|
|
||||||
"itertools",
|
|
||||||
"tracing",
|
|
||||||
"tracing-subscriber",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "errno"
|
|
||||||
version = "0.2.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
|
|
||||||
dependencies = [
|
|
||||||
"errno-dragonfly",
|
|
||||||
"libc",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "errno-dragonfly"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hermit-abi"
|
|
||||||
version = "0.2.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "io-lifetimes"
|
|
||||||
version = "1.0.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "is-terminal"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi",
|
|
||||||
"io-lifetimes",
|
|
||||||
"rustix",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.10.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.138"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "linux-raw-sys"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log"
|
|
||||||
version = "0.4.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "matchers"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
|
||||||
dependencies = [
|
|
||||||
"regex-automata",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nu-ansi-term"
|
|
||||||
version = "0.46.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
|
||||||
dependencies = [
|
|
||||||
"overload",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "once_cell"
|
|
||||||
version = "1.16.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "os_str_bytes"
|
|
||||||
version = "6.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "overload"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pin-project-lite"
|
|
||||||
version = "0.2.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.47"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex"
|
|
||||||
version = "1.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
|
|
||||||
dependencies = [
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-automata"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
|
||||||
dependencies = [
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-syntax"
|
|
||||||
version = "0.6.28"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustix"
|
|
||||||
version = "0.36.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cb93e85278e08bb5788653183213d3a60fc242b10cb9be96586f5a73dcb67c23"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"errno",
|
|
||||||
"io-lifetimes",
|
|
||||||
"libc",
|
|
||||||
"linux-raw-sys",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sharded-slab"
|
|
||||||
version = "0.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
|
|
||||||
dependencies = [
|
|
||||||
"lazy_static",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "smallvec"
|
|
||||||
version = "1.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strsim"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.105"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termcolor"
|
|
||||||
version = "1.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thread_local"
|
|
||||||
version = "1.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
|
|
||||||
dependencies = [
|
|
||||||
"once_cell",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing"
|
|
||||||
version = "0.1.37"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"pin-project-lite",
|
|
||||||
"tracing-attributes",
|
|
||||||
"tracing-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-attributes"
|
|
||||||
version = "0.1.23"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-core"
|
|
||||||
version = "0.1.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
|
||||||
dependencies = [
|
|
||||||
"once_cell",
|
|
||||||
"valuable",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-log"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
|
|
||||||
dependencies = [
|
|
||||||
"lazy_static",
|
|
||||||
"log",
|
|
||||||
"tracing-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-subscriber"
|
|
||||||
version = "0.3.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
|
|
||||||
dependencies = [
|
|
||||||
"matchers",
|
|
||||||
"nu-ansi-term",
|
|
||||||
"once_cell",
|
|
||||||
"regex",
|
|
||||||
"sharded-slab",
|
|
||||||
"smallvec",
|
|
||||||
"thread_local",
|
|
||||||
"tracing",
|
|
||||||
"tracing-core",
|
|
||||||
"tracing-log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "valuable"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version_check"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.3.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-i686-pc-windows-gnu",
|
|
||||||
"winapi-x86_64-pc-windows-gnu",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-util"
|
|
||||||
version = "0.1.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
|
||||||
dependencies = [
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-sys"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
|
||||||
dependencies = [
|
|
||||||
"windows_aarch64_gnullvm",
|
|
||||||
"windows_aarch64_msvc",
|
|
||||||
"windows_i686_gnu",
|
|
||||||
"windows_i686_msvc",
|
|
||||||
"windows_x86_64_gnu",
|
|
||||||
"windows_x86_64_gnullvm",
|
|
||||||
"windows_x86_64_msvc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_gnullvm"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_msvc"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_gnu"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_msvc"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnu"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnullvm"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_msvc"
|
|
||||||
version = "0.42.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
|
|
|
@ -1,24 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "day-3_rucksack_reorganization"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "rucksack_reorganization_lib"
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "rucksack_reorganization"
|
|
||||||
path = "src/bin.rs"
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
common = {path = "../common/"}
|
|
||||||
|
|
||||||
clap = {version = "4.0.22", features = ["derive"]}
|
|
||||||
tracing = "0.1"
|
|
||||||
tracing-subscriber = {version = "0.3.16", features = ["env-filter"]}
|
|
||||||
|
|
||||||
itertools = "0.10.5"
|
|
|
@ -1,15 +0,0 @@
|
||||||
# Calorie Counting
|
|
||||||
Implementation of [this task](./task.md).
|
|
||||||
|
|
||||||
This time I ran with this implementation second, since it seemed easier to quickly implement in Python.
|
|
||||||
Implementing it in Python first, allowed me to have a more organized approach to the task, given that I had already completed it once.
|
|
||||||
I may continue doing this going forward.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
`cargo run --release -- --input <Path to file with inputs>`
|
|
||||||
|
|
||||||
Alternative
|
|
||||||
```sh
|
|
||||||
cargo install --release .
|
|
||||||
rucksack_reorganization -i <Path to file with inputs>
|
|
||||||
```
|
|
|
@ -1,17 +0,0 @@
|
||||||
use common::cli::Cli;
|
|
||||||
use common::read_file;
|
|
||||||
use rucksack_reorganization_lib::{task_3a, task_3b};
|
|
||||||
use tracing::debug;
|
|
||||||
|
|
||||||
use clap::Parser;
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
tracing_subscriber::fmt::init();
|
|
||||||
|
|
||||||
let args = Cli::parse();
|
|
||||||
debug!("Args: {:?}", args);
|
|
||||||
|
|
||||||
let content = read_file(&args.input).unwrap();
|
|
||||||
println!("Result (3a): {}", task_3a(&content));
|
|
||||||
println!("Result (3b): {}", task_3b(&content));
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
use tracing::{info, debug};
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
|
||||||
|
|
||||||
mod rucksack;
|
|
||||||
use crate::rucksack::Rucksack;
|
|
||||||
|
|
||||||
/// Gives a list of characters in `first` and `second`, that are in both strings
|
|
||||||
fn common_chars(first: &str, second: &str) -> Vec<char> {
|
|
||||||
// probably not very idiomatic, also I shouldnt use Vec<char> here, instead String
|
|
||||||
debug!("Comparing: {:10}, {:10}", first, second);
|
|
||||||
let result = first.chars().filter(|c| second.chars().find(|d| d == c).is_some()).collect::<Vec<char>>();
|
|
||||||
info!("Common Characters: {:?}", result);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts `input` to it's "priority" based on the tasks specifications
|
|
||||||
/// a-z -> 01-26 respectivly
|
|
||||||
/// A-Z -> 27-52 respectivly
|
|
||||||
fn priority_of(input: &char) -> u64 {
|
|
||||||
debug!("Priority of {}", input);
|
|
||||||
let base: u32 = 'a'.into();
|
|
||||||
let mut priority: u32 = input.to_ascii_lowercase() as u32 - base + 1;
|
|
||||||
if input.is_ascii_uppercase() {
|
|
||||||
priority += 26;
|
|
||||||
}
|
|
||||||
let result: u64 = priority.into();
|
|
||||||
debug!("Priority {}", &result);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Solution for 3a
|
|
||||||
pub fn task_3a (content: &str) -> u64 {
|
|
||||||
content.split('\n')
|
|
||||||
.map(|c| Rucksack::new(c))
|
|
||||||
.map(|c| priority_of(&common_chars(&c.compartments[0], &c.compartments[1])[0]))
|
|
||||||
.sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Solution for 3b
|
|
||||||
pub fn task_3b (content: &str) -> u64 {
|
|
||||||
let result: u64 = content.split('\n')
|
|
||||||
.map(|c| Rucksack::new(c))
|
|
||||||
.chunks(3).into_iter()
|
|
||||||
.map(|c| {
|
|
||||||
let group = c.map(|r| r.total_content()).collect_vec();
|
|
||||||
let common_badge_0_1: String = common_chars(&group[0], &group[1]).into_iter().collect();
|
|
||||||
let badge = common_chars(&common_badge_0_1, &group[2])[0];
|
|
||||||
priority_of(&badge)
|
|
||||||
}).sum();
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
const CONTENT: &str = "vJrwpWtwJgWrhcsFMMfFFhFp\njqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL\nPmmdzqPrVvPwwTWBwg\nwMqvLMZHhHMvwLHjbvcjnnSBnvTQFn\nttgJtRGJQctTZtZT\nCrZsJsPPZsGzwwsLwLmpwMDw";
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_common_chars() {
|
|
||||||
let inputs: Vec<&str> = CONTENT.split('\n').collect();
|
|
||||||
let results: Vec<char> = inputs.iter().map(|r| {
|
|
||||||
let rucksack = Rucksack::new(r);
|
|
||||||
common_chars(&rucksack.compartments[0], &rucksack.compartments[1])[0]
|
|
||||||
}).collect();
|
|
||||||
let expected: Vec<char> = vec!('p', 'L', 'P', 'v', 't', 's');
|
|
||||||
assert_eq!(results, expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_priority_of() {
|
|
||||||
let inputs: Vec<char> = vec!('p', 'L', 'P', 'v', 't', 's');
|
|
||||||
let results: Vec<u64> = inputs.iter().map(|c| priority_of(c)).collect();
|
|
||||||
let expected: Vec<u64> = vec!(16, 38, 42, 22, 20, 19);
|
|
||||||
|
|
||||||
assert_eq!(results, expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_task_3a() {
|
|
||||||
let result = task_3a(CONTENT);
|
|
||||||
let expected = 157u64;
|
|
||||||
|
|
||||||
assert_eq!(result, expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_task_3b() {
|
|
||||||
let result = task_3b(CONTENT);
|
|
||||||
let expected = 70;
|
|
||||||
|
|
||||||
assert_eq!(result, expected);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
use tracing::{info, debug};
|
|
||||||
|
|
||||||
const COMPARTMENT_COUNT: usize = 2;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Rucksack {
|
|
||||||
pub compartments: [String; COMPARTMENT_COUNT],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Rucksack {
|
|
||||||
/// Splits the `total_content` by half and puts it in their respective compartments
|
|
||||||
pub fn new(total_content: &str) -> Self {
|
|
||||||
debug!("Rucksack with {}", total_content);
|
|
||||||
let split_position = total_content.len()/2;
|
|
||||||
let (left, right) = total_content.split_at(split_position.into());
|
|
||||||
let content = [left.to_string(), right.to_string()];
|
|
||||||
|
|
||||||
debug!("Rucksack with {:?}", content);
|
|
||||||
Rucksack {
|
|
||||||
compartments: content,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the content of the rucksack as a single String
|
|
||||||
pub fn total_content(&self) -> String {
|
|
||||||
info!("");
|
|
||||||
self.compartments.concat().to_string()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
# --- Day 3: Rucksack Reorganization ---
|
|
||||||
## --- Part One ---
|
|
||||||
|
|
||||||
One Elf has the important job of loading all of the rucksacks with supplies for the jungle journey. Unfortunately, that Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged.
|
|
||||||
|
|
||||||
Each rucksack has two large compartments. All items of a given type are meant to go into exactly one of the two compartments. The Elf that did the packing failed to follow this rule for exactly one item type per rucksack.
|
|
||||||
|
|
||||||
The Elves have made a list of all of the items currently in each rucksack (your puzzle input), but they need your help finding the errors. Every item type is identified by a single lowercase or uppercase letter (that is, a and A refer to different types of items).
|
|
||||||
|
|
||||||
The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same number of items in each of its two compartments, so the first half of the characters represent items in the first compartment, while the second half of the characters represent items in the second compartment.
|
|
||||||
|
|
||||||
For example, suppose you have the following list of contents from six rucksacks:
|
|
||||||
|
|
||||||
```
|
|
||||||
vJrwpWtwJgWrhcsFMMfFFhFp
|
|
||||||
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
|
||||||
PmmdzqPrVvPwwTWBwg
|
|
||||||
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
|
||||||
ttgJtRGJQctTZtZT
|
|
||||||
CrZsJsPPZsGzwwsLwLmpwMDw
|
|
||||||
```
|
|
||||||
|
|
||||||
The first rucksack contains the items vJrwpWtwJgWrhcsFMMfFFhFp, which means its first compartment contains the items vJrwpWtwJgWr, while the second compartment contains the items hcsFMMfFFhFp. The only item type that appears in both compartments is lowercase p.
|
|
||||||
The second rucksack's compartments contain jqHRNqRjqzjGDLGL and rsFMfFZSrLrFZsSL. The only item type that appears in both compartments is uppercase L.
|
|
||||||
The third rucksack's compartments contain PmmdzqPrV and vPwwTWBwg; the only common item type is uppercase P.
|
|
||||||
The fourth rucksack's compartments only share item type v.
|
|
||||||
The fifth rucksack's compartments only share item type t.
|
|
||||||
The sixth rucksack's compartments only share item type s.
|
|
||||||
|
|
||||||
To help prioritize item rearrangement, every item type can be converted to a priority:
|
|
||||||
|
|
||||||
Lowercase item types a through z have priorities 1 through 26.
|
|
||||||
Uppercase item types A through Z have priorities 27 through 52.
|
|
||||||
|
|
||||||
In the above example, the priority of the item type that appears in both compartments of each rucksack is 16 (p), 38 (L), 42 (P), 22 (v), 20 (t), and 19 (s); the sum of these is 157.
|
|
||||||
|
|
||||||
Find the item type that appears in both compartments of each rucksack. What is the sum of the priorities of those item types?
|
|
||||||
|
|
||||||
## --- Part Two ---
|
|
||||||
|
|
||||||
As you finish identifying the misplaced items, the Elves come to you with another issue.
|
|
||||||
|
|
||||||
For safety, the Elves are divided into groups of three. Every Elf carries a badge that identifies their group. For efficiency, within each group of three Elves, the badge is the only item type carried by all three Elves. That is, if a group's badge is item type B, then all three Elves will have item type B somewhere in their rucksack, and at most two of the Elves will be carrying any other item type.
|
|
||||||
|
|
||||||
The problem is that someone forgot to put this year's updated authenticity sticker on the badges. All of the badges need to be pulled out of the rucksacks so the new authenticity stickers can be attached.
|
|
||||||
|
|
||||||
Additionally, nobody wrote down which item type corresponds to each group's badges. The only way to tell which item type is the right one is by finding the one item type that is common between all three Elves in each group.
|
|
||||||
|
|
||||||
Every set of three lines in your list corresponds to a single group, but each group can have a different badge item type. So, in the above example, the first group's rucksacks are the first three lines:
|
|
||||||
|
|
||||||
```
|
|
||||||
vJrwpWtwJgWrhcsFMMfFFhFp
|
|
||||||
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
|
||||||
PmmdzqPrVvPwwTWBwg
|
|
||||||
```
|
|
||||||
|
|
||||||
And the second group's rucksacks are the next three lines:
|
|
||||||
|
|
||||||
```
|
|
||||||
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
|
||||||
ttgJtRGJQctTZtZT
|
|
||||||
CrZsJsPPZsGzwwsLwLmpwMDw
|
|
||||||
```
|
|
||||||
|
|
||||||
In the first group, the only item type that appears in all three rucksacks is lowercase r; this must be their badges. In the second group, their badge item type must be Z.
|
|
||||||
|
|
||||||
Priorities for these items must still be found to organize the sticker attachment efforts: here, they are 18 (r) for the first group and 52 (Z) for the second group. The sum of these is 70.
|
|
||||||
|
|
||||||
Find the item type that corresponds to the badges of each three-Elf group. What is the sum of the priorities of those item types?
|
|
12
README.md
12
README.md
|
@ -1,18 +1,8 @@
|
||||||
|
|
||||||
#Advent of Code
|
#Advent of Code
|
||||||
|
|
||||||
```
|
```
|
||||||
.
|
.
|
||||||
├── 2022
|
├── 2022
|
||||||
│ ├── Cargo.toml
|
│ └── day-1_calorie_counting
|
||||||
│ ├── common
|
|
||||||
│ ├── day-1_calorie_counting
|
|
||||||
│ ├── day-1_calorie_counting-alt
|
|
||||||
│ ├── day-2_rock_paper_scissors
|
|
||||||
│ ├── day-2_rock_paper_scissors-alt
|
|
||||||
│ ├── day-3_rucksack_reorganization
|
|
||||||
│ └── day-3_rucksack_reorganization-alt
|
|
||||||
├── create_readme.sh
|
├── create_readme.sh
|
||||||
└── README.md
|
└── README.md
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo -e """
|
echo -e "#Advent of Code\n\`\`\`\n$(tree -L 2|head -n -1)\n\`\`\`" > README.md
|
||||||
#Advent of Code
|
|
||||||
|
|
||||||
\`\`\`
|
|
||||||
$(tree -L 2 --gitignore | head -n -1)
|
|
||||||
\`\`\`
|
|
||||||
""" > README.md
|
|
||||||
|
|
Loading…
Reference in New Issue