Skip to content

Commit

Permalink
Compress day1
Browse files Browse the repository at this point in the history
Using the new `compress` member. Also ignore any future `input.txt`s.
  • Loading branch information
mlodato517 committed Feb 1, 2022
1 parent 57a4153 commit 94e72b8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
**/input.txt
1 change: 1 addition & 0 deletions day1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
compress = { path = "../compress" }

[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] }
Expand Down
7 changes: 4 additions & 3 deletions day1/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn criterion_benchmark(c: &mut Criterion) {
let input = include_str!("../input.txt");
c.bench_function("part1", |b| b.iter(|| day1::part1(black_box(input))));
c.bench_function("part2", |b| b.iter(|| day1::part2(black_box(input))));
let input = include_bytes!("../input.compressed").to_vec();
let input = compress::decompress(input);
c.bench_function("part1", |b| b.iter(|| day1::part1(black_box(&input))));
c.bench_function("part2", |b| b.iter(|| day1::part2(black_box(&input))));
}

criterion_group!(benches, criterion_benchmark);
Expand Down
Binary file added day1/input.compressed
Binary file not shown.
1 change: 0 additions & 1 deletion day1/input.txt

This file was deleted.

10 changes: 6 additions & 4 deletions day1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ mod tests {

#[test]
fn test_part_1_chris_input() {
let input = include_str!("../input.txt");
assert_eq!(part1(input), 280);
let input = include_bytes!("../input.compressed").to_vec();
let input = compress::decompress(input);
assert_eq!(part1(&input), 280);
}

#[test]
fn test_part_2_chris_input() {
let input = include_str!("../input.txt");
assert_eq!(part2(input), 1797);
let input = include_bytes!("../input.compressed").to_vec();
let input = compress::decompress(input);
assert_eq!(part2(&input), 1797);
}
}
5 changes: 2 additions & 3 deletions day1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fs::read_to_string;

fn main() {
let input = read_to_string("input.txt").unwrap();
let input = include_bytes!("../input.compressed").to_vec();
let input = compress::decompress(input);
println!("part1: {}", day1::part1(&input));
println!("part2: {}", day1::part2(&input));
}

0 comments on commit 94e72b8

Please sign in to comment.