Skip to content

Commit

Permalink
Prepare for 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
dtomvan committed Nov 13, 2022
1 parent d592c70 commit 37a1914
Show file tree
Hide file tree
Showing 95 changed files with 9,529 additions and 261 deletions.
10 changes: 6 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[alias]
xtask = "run --release --package xtask --"
day = "run --release --package xtask -- day"
2021 = "run --bin aoc-2021 --"
2022 = "run --bin aoc-2022 --"
r2021 = "run --release --bin aoc-2021 --"
r2022 = "run --release --bin aoc-2022 --"
2015 = "run --bin aoc_2015 --"
2021 = "run --bin aoc_2021 --"
2022 = "run --bin aoc_2022 --"
r2015 = "run --release --bin aoc_2015 --"
r2021 = "run --release --bin aoc_2021 --"
r2022 = "run --release --bin aoc_2022 --"
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*/inputs/
/*/target/
target
/crates/*/inputs/
/crates/*/target/
/target/
/crates/xtask/src/TOKEN
/.idea/
19 changes: 0 additions & 19 deletions 2021/src/_match_days.rs

This file was deleted.

16 changes: 0 additions & 16 deletions 2021/src/days/mod.rs

This file was deleted.

35 changes: 0 additions & 35 deletions 2022/build.rs

This file was deleted.

1 change: 0 additions & 1 deletion 2022/src/days/mod.rs

This file was deleted.

33 changes: 0 additions & 33 deletions 2022/src/main.rs

This file was deleted.

41 changes: 37 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"2021",
"2022",
"xtask",
"util/*",
"year/*"
]
2 changes: 1 addition & 1 deletion benchmarks/2021.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Running the benchmarks
`cargo bench -p aoc-2021`
`cargo bench -p aoc_2021`

## Benches
```
Expand Down
11 changes: 11 additions & 0 deletions util/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "aoc_common"
version = "0.1.0"
edition = "2021"
build = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.62"
num-bigint = "0.4.3"
File renamed without changes.
14 changes: 11 additions & 3 deletions 2021/src/main.rs → util/common/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#![feature(drain_filter, let_chains, iterator_try_collect, hash_set_entry)]
use std::{collections::HashMap, time::Instant};

use aoc_2021::days::*;
mod days;
use days::*;

include!(concat!(env!("OUT_DIR"), "/loc.rs"));

fn main() -> anyhow::Result<()> {
let loc: HashMap<&str, u32> = HashMap::from(PAIRS);

let name = env!("CARGO_PKG_NAME");
let rep = "#".repeat(name.len() + 6);
println!("{rep}");
println!("## {name} ##");
println!("{rep}");
for arg in std::env::args().skip(1) {
let func = include!("_match_days.rs");

println!("\n=== Day {:0>2} ===", arg);
println!("\n=== Day {arg:0>2} ===");
println!("From {}/day/{arg}", env!("CARGO_PKG_HOMEPAGE"));

let instant = Instant::now();
let result = func();
Expand All @@ -20,7 +28,7 @@ fn main() -> anyhow::Result<()> {
println!("Part 1: {}\nPart 2: {}", part_1, part_2);
println!("Took {} μs", elapsed);

let lines = loc.get(format!("day{:0>2}.rs", arg).as_str()).unwrap();
let lines = loc.get(format!("day{}.rs", arg).as_str()).unwrap();
println!("Lines of code: {}", lines);
} else {
eprintln!("Error: {}", result.unwrap_err());
Expand Down
8 changes: 0 additions & 8 deletions 2021/src/coords.rs → util/common/src/coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ fn as_index(x: isize, y: isize, width: isize) -> isize {
x + y * width
}

impl std::convert::Into<Point> for Direction {
fn into(self) -> Point {
self.to_tuple()
}
}

impl std::convert::TryFrom<Point> for Direction {
type Error = &'static str;

Expand All @@ -80,5 +74,3 @@ impl std::convert::TryFrom<Point> for Direction {
}
}
}

// fn as_xy
2 changes: 2 additions & 0 deletions util/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod result;
pub mod coords;
90 changes: 90 additions & 0 deletions util/common/src/result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use std::fmt::Display;

use num_bigint::{BigInt, BigUint};

pub fn done<A: Into<AocD>, B: Into<AocD>>(a: A, b: B) -> AocResult {
Ok((a.into(), b.into()))
}

pub type AocResult = anyhow::Result<(AocD, AocD)>;

#[derive(Default, Debug, Clone)]
pub enum AocD {
#[default]
Nothing,
Number(usize),
ULong(BigUint),
Integer(isize),
Long(BigInt),
String(String),
List(Vec<AocD>),
}

impl Display for AocD {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use AocD::*;
match self {
Nothing => write!(f, "TODO"),
Integer(n) => write!(f, "{n}"),
Long(n) => write!(f, "{n}"),
Number(n) => write!(f, "{n}"),
String(s) => write!(f, "{s}"),
ULong(n) => write!(f, "{n}"),
List(l) => {
write!(f, "[")?;
let mut second = false;
for x in l {
if second {
write!(f, ", ")?;
} else {
second = true;
}
write!(f, "{x}")?;
}
write!(f, "]")
}
}
}
}

impl From<()> for AocD {
fn from(_: ()) -> Self {
Self::Nothing
}
}

impl From<Vec<AocD>> for AocD {
fn from(v: Vec<AocD>) -> Self {
Self::List(v)
}
}

impl From<String> for AocD {
fn from(v: String) -> Self {
Self::String(v)
}
}

impl From<BigInt> for AocD {
fn from(v: BigInt) -> Self {
Self::Long(v)
}
}

impl From<isize> for AocD {
fn from(v: isize) -> Self {
Self::Integer(v)
}
}

impl From<BigUint> for AocD {
fn from(v: BigUint) -> Self {
Self::ULong(v)
}
}

impl From<usize> for AocD {
fn from(v: usize) -> Self {
Self::Number(v)
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions util/xtask/src/TOKEN
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
53616c7465645f5f4c9bdcd6d080dc8e543af5be4d06b6da11a3c411a7527125dba01f618c97eede9fc8a185711d44cd92df0c701db8a4e638467adf46fe2d3d
Loading

0 comments on commit 37a1914

Please sign in to comment.