aoc: stop printing inside run functions

This will make benching implementations easier
This commit is contained in:
Antoine Martin 2019-12-06 19:06:49 +01:00
parent 6f06d5d7ca
commit 4bff689da0
21 changed files with 139 additions and 75 deletions

View file

@ -1,14 +1,17 @@
use std::collections::HashSet;
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 part1(input: &str) -> Result<i32> {

View file

@ -1,14 +1,17 @@
use std::collections::HashMap;
use std::fmt::Write;
use aoc::Result;
const INPUT: &str = include_str!("../input/day02.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<u32> {

View file

@ -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)
}
struct Claim {

View file

@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::error::Error;
use std::fmt::Write;
use std::str::FromStr;
use aoc::err;
@ -13,10 +14,12 @@ fn sorted_lines(input: &str) -> String {
lines.join("\n")
}
pub fn run() -> Result<()> {
println!("part 1: {}", part1(&sorted_lines(INPUT))?);
pub fn run() -> Result<String> {
let mut res = String::with_capacity(128);
Ok(())
writeln!(res, "part 1: {}", part1(&sorted_lines(INPUT))?)?;
Ok(res)
}
#[derive(Debug)]

View file

@ -1,14 +1,17 @@
use std::collections::HashSet;
use std::fmt::Write;
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 same_type(a: char, b: char) -> bool {

View file

@ -1,3 +1,4 @@
use aoc::DayFunc;
use aoc::Result;
use aoc2018::day01;
@ -7,7 +8,7 @@ use aoc2018::day04;
use aoc2018::day05;
fn main() -> Result<()> {
let days: &[fn() -> Result<()>] = &[day01::run, day02::run, day03::run, day04::run, day05::run];
let days: &[DayFunc] = &[day01::run, day02::run, day03::run, day04::run, day05::run];
aoc::run(days)
}