move everything to single crate
This commit is contained in:
parent
1ee14b228c
commit
b4c1f36767
|
@ -1,9 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "aoc02"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Antoine Martin <antoine97.martin@gmail.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1,10 +1,6 @@
|
||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aoc01"
|
name = "aoc2018"
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aoc02"
|
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"2018/aoc01",
|
"aoc2018",
|
||||||
"2018/aoc02",
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "aoc01"
|
name = "aoc2018"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Antoine Martin <antoine97.martin@gmail.com>"]
|
authors = ["Antoine Martin <antoine97.martin@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
|
@ -1,21 +1,12 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::env;
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
use super::Result;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
const INPUT: &str = include_str!("../input/day01.txt");
|
||||||
let mut args = env::args();
|
|
||||||
args.next();
|
|
||||||
|
|
||||||
let input = fs::read_to_string(
|
pub fn run() -> Result<()> {
|
||||||
&args
|
println!("part 1: {}", part1(INPUT)?);
|
||||||
.next()
|
println!("part 2: {}", part2(INPUT)?);
|
||||||
.expect("Please provide the path to the input file"),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
println!("part 1: {}", part1(&input)?);
|
|
||||||
println!("part 2: {}", part2(&input)?);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -34,7 +25,6 @@ fn part2(input: &str) -> Result<i32> {
|
||||||
loop {
|
loop {
|
||||||
for line in input.lines() {
|
for line in input.lines() {
|
||||||
if freqs.contains(&freq) {
|
if freqs.contains(&freq) {
|
||||||
println!("{}", freq);
|
|
||||||
return Ok(freq);
|
return Ok(freq);
|
||||||
} else {
|
} else {
|
||||||
freqs.insert(freq);
|
freqs.insert(freq);
|
||||||
|
@ -91,9 +81,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn part1_real() {
|
fn part1_real() {
|
||||||
let input = include_str!("../input/input.txt");
|
assert_eq!(part1(INPUT).unwrap(), 427);
|
||||||
|
|
||||||
assert_eq!(part1(input).unwrap(), 427);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -154,8 +142,6 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn part2_real() {
|
fn part2_real() {
|
||||||
let input = include_str!("../input/input.txt");
|
assert_eq!(part2(INPUT).unwrap(), 341);
|
||||||
|
|
||||||
assert_eq!(part2(input).unwrap(), 341);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,20 +1,11 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
use super::Result;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
const INPUT: &str = include_str!("../input/day02.txt");
|
||||||
let mut args = env::args();
|
|
||||||
args.next();
|
|
||||||
|
|
||||||
let input = fs::read_to_string(
|
pub fn run() -> Result<()> {
|
||||||
&args
|
println!("part 1: {}", part1(INPUT)?);
|
||||||
.next()
|
|
||||||
.expect("Please provide the path to the input file"),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
println!("part 1: {}", part1(&input)?);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -61,8 +52,6 @@ ababab
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn part1_real() {
|
fn part1_real() {
|
||||||
let input = include_str!("../input/input.txt");
|
assert_eq!(part1(INPUT).unwrap(), 5750);
|
||||||
|
|
||||||
assert_eq!(part1(input).unwrap(), 5750);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
4
aoc2018/src/lib.rs
Normal file
4
aoc2018/src/lib.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod day01;
|
||||||
|
pub mod day02;
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
19
aoc2018/src/main.rs
Normal file
19
aoc2018/src/main.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use aoc2018::day01;
|
||||||
|
use aoc2018::day02;
|
||||||
|
use aoc2018::Result;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let days = [day01::run, day02::run];
|
||||||
|
|
||||||
|
let mut args = env::args();
|
||||||
|
args.next();
|
||||||
|
|
||||||
|
let day = args
|
||||||
|
.next()
|
||||||
|
.expect("Please provide a day to launch")
|
||||||
|
.parse::<usize>()?;
|
||||||
|
|
||||||
|
days[day - 1]()
|
||||||
|
}
|
Loading…
Reference in a new issue