aoc: stop printing inside run functions
This will make benching implementations easier
This commit is contained in:
parent
6f06d5d7ca
commit
4bff689da0
21 changed files with 139 additions and 75 deletions
|
|
@ -1,12 +1,16 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use aoc::Result;
|
||||
|
||||
const INPUT: &str = include_str!("../input/day01.txt");
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
println!("part 1: {}", part1(INPUT)?);
|
||||
println!("part 2: {}", part2(INPUT)?);
|
||||
pub fn run() -> Result<String> {
|
||||
let mut res = String::with_capacity(128);
|
||||
|
||||
Ok(())
|
||||
writeln!(res, "part 1: {}", part1(INPUT)?)?;
|
||||
writeln!(res, "part 2: {}", part2(INPUT)?)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn fuel_needed(module_weight: u64) -> u64 {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use aoc::err;
|
||||
use aoc::Result;
|
||||
|
||||
|
|
@ -12,12 +14,15 @@ fn parse_intcode(input: &str) -> Result<Vec<usize>> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
let intcode = parse_intcode(INPUT)?;
|
||||
println!("part 1: {}", part1(&mut intcode.clone())?);
|
||||
println!("part 2: {}", part2(&intcode, PART2_EXPECTED)?);
|
||||
pub fn run() -> Result<String> {
|
||||
let mut res = String::with_capacity(128);
|
||||
|
||||
Ok(())
|
||||
let intcode = parse_intcode(INPUT)?;
|
||||
|
||||
writeln!(res, "part 1: {}", part1(&mut intcode.clone())?)?;
|
||||
writeln!(res, "part 2: {}", part2(&intcode, PART2_EXPECTED)?)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn eval(intcode: &mut [usize]) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::error::Error;
|
||||
use std::fmt::Write;
|
||||
use std::str::FromStr;
|
||||
|
||||
use aoc::err;
|
||||
|
|
@ -8,11 +9,13 @@ use aoc::Result;
|
|||
|
||||
const INPUT: &str = include_str!("../input/day03.txt");
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
println!("part 1: {}", part1(INPUT)?);
|
||||
println!("part 2: {}", part2(INPUT)?);
|
||||
pub fn run() -> Result<String> {
|
||||
let mut res = String::with_capacity(128);
|
||||
|
||||
Ok(())
|
||||
writeln!(res, "part 1: {}", part1(INPUT)?)?;
|
||||
writeln!(res, "part 2: {}", part2(INPUT)?)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
enum Move {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use aoc::err;
|
||||
use aoc::Result;
|
||||
|
||||
const INPUT: &str = include_str!("../input/day04.txt");
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
println!("part 1: {}", part1(INPUT)?);
|
||||
println!("part 2: {}", part2(INPUT)?);
|
||||
pub fn run() -> Result<String> {
|
||||
let mut res = String::with_capacity(128);
|
||||
|
||||
Ok(())
|
||||
writeln!(res, "part 1: {}", part1(INPUT)?)?;
|
||||
writeln!(res, "part 2: {}", part2(INPUT)?)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn part1(input: &str) -> Result<usize> {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use aoc::err;
|
||||
use aoc::Result;
|
||||
|
||||
const INPUT: &str = include_str!("../input/day05.txt");
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
println!("part 1: {}", part1(INPUT)?);
|
||||
println!("part 2: {}", part2(INPUT)?);
|
||||
pub fn run() -> Result<String> {
|
||||
let mut res = String::with_capacity(128);
|
||||
|
||||
Ok(())
|
||||
writeln!(res, "part 1: {}", part1(INPUT)?)?;
|
||||
writeln!(res, "part 2: {}", part2(INPUT)?)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn part1(input: &str) -> Result<i64> {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Write;
|
||||
use std::iter;
|
||||
|
||||
use aoc::err;
|
||||
|
|
@ -7,11 +8,13 @@ use aoc::Result;
|
|||
|
||||
const INPUT: &str = include_str!("../input/day06.txt");
|
||||
|
||||
pub fn run() -> Result<()> {
|
||||
println!("part 1: {}", part1(INPUT)?);
|
||||
println!("part 2: {}", part2(INPUT)?);
|
||||
pub fn run() -> Result<String> {
|
||||
let mut res = String::with_capacity(128);
|
||||
|
||||
Ok(())
|
||||
writeln!(res, "part 1: {}", part1(INPUT)?)?;
|
||||
writeln!(res, "part 2: {}", part2(INPUT)?)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn count_orbits(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use aoc::DayFunc;
|
||||
use aoc::Result;
|
||||
|
||||
use aoc2019::day01;
|
||||
|
|
@ -8,7 +9,7 @@ use aoc2019::day05;
|
|||
use aoc2019::day06;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let days: &[fn() -> Result<()>] = &[
|
||||
let days: &[DayFunc] = &[
|
||||
day01::run,
|
||||
day02::run,
|
||||
day03::run,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue