Set up everything for 2021
This commit is contained in:
parent
adb0e84858
commit
a65c137864
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "aoc2021"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
itertools = "0.10"
|
||||
paste = "1.0"
|
|
@ -0,0 +1,7 @@
|
|||
newline_style = "Unix"
|
||||
max_width = 140
|
||||
imports_layout = "Horizontal"
|
||||
merge_imports = true
|
||||
struct_field_align_threshold = 25
|
||||
where_single_line = true
|
||||
edition = "2021"
|
|
@ -0,0 +1,56 @@
|
|||
#!/bin/sh
|
||||
|
||||
today=$(date +%d)
|
||||
# this assumes that your puzzle input is already in your clipboard
|
||||
if [ -n "$WAYLAND_DISPLAY" ]; then
|
||||
wl-paste > inputs/day$today
|
||||
else
|
||||
xsel -b > inputs/day$today
|
||||
fi
|
||||
# add trailing newline if necessary
|
||||
sed -i -e '$a\' inputs/day$today
|
||||
|
||||
echo '#![feature(test)]
|
||||
extern crate test;
|
||||
use aoc2020::common::*;
|
||||
|
||||
type Parsed = Vec<usize>;
|
||||
|
||||
fn read_input() -> String {
|
||||
read_file('$today')
|
||||
}
|
||||
|
||||
|
||||
fn parse_input(raw: &str) -> Parsed {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn part1(parsed: &Parsed) -> usize {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn part2(parsed: &Parsed) -> usize {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = parse_input(&read_input());
|
||||
println!("Part 1: {}", part1(&input));
|
||||
println!("Part 2: {}", part2(&input));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use aoc2020::*;
|
||||
use paste::paste;
|
||||
use test::black_box;
|
||||
|
||||
const TEST_INPUT: &str = "";
|
||||
|
||||
test!(part1() == 0);
|
||||
test!(part2() == 0);
|
||||
bench!(part1() == 0);
|
||||
bench!(part2() == 0);
|
||||
bench_input!(len == 0);
|
||||
}' > src/bin/day$today.rs
|
|
@ -0,0 +1,16 @@
|
|||
use std::env;
|
||||
|
||||
pub fn read_file(day: usize) -> String {
|
||||
std::fs::read_to_string(
|
||||
env::args()
|
||||
.nth(1)
|
||||
.filter(|n| n != "--bench")
|
||||
.unwrap_or_else(|| format!("inputs/day{:0>2}", day)),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn parse_nums(l: &str) -> Vec<usize> {
|
||||
l.split(',').filter_map(|n| n.parse().ok()).collect()
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
pub mod common;
|
||||
pub mod teststuff;
|
|
@ -0,0 +1,39 @@
|
|||
#[macro_export]
|
||||
macro_rules! bench {
|
||||
($part: ident ($($param: expr),*) == $expected:expr) => {
|
||||
use paste::paste;
|
||||
paste! {
|
||||
#[bench]
|
||||
fn [<$part _bench>](b: &mut test::Bencher) {
|
||||
let raw = &read_input();
|
||||
let input = parse_input(&raw);
|
||||
b.iter(|| assert_eq!($part(black_box(&input)$(, $param)*), $expected));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! bench_input {
|
||||
($fn:ident == $expected_len:expr) => {
|
||||
#[bench]
|
||||
fn bench_input_parsing(b: &mut test::Bencher) {
|
||||
let raw = read_input();
|
||||
b.iter(|| assert_eq!(parse_input(black_box(&raw)).$fn(), $expected_len));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! test {
|
||||
($part: ident ($($param: expr),*) == $expected:expr) => {
|
||||
use paste::paste;
|
||||
paste! {
|
||||
#[test]
|
||||
fn [<$part _test>]() {
|
||||
let input = parse_input(TEST_INPUT);
|
||||
assert_eq!($part(&input$(, $param)*), $expected);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user