Use include_str for input files

This commit is contained in:
Timothy Warren 2022-12-03 16:07:06 -05:00
parent d513b4fc0b
commit d2ecca394d
4 changed files with 4 additions and 14 deletions

View File

@ -1,6 +1,3 @@
use std::error::Error;
use std::fs;
fn get_elves(raw: &str) -> Vec<Vec<u32>> {
raw.split("\n\n")
.map(|raw_elf| {
@ -25,8 +22,8 @@ fn get_elf_totals(elves: &Vec<Vec<u32>>) -> Vec<u32> {
.collect()
}
fn main() -> Result<(), Box<dyn Error>> {
let file_str = fs::read_to_string("input.txt")?;
fn main() {
let file_str = include_str!("input.txt"); //fs::read_to_string("input.txt")?;
let elves = get_elves(&file_str);
let mut totals: Vec<u32> = get_elf_totals(&elves);
@ -38,6 +35,4 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("Part 1: Most calories for one elf: {}", most);
println!("Part 2: Calories for top three elves: {}", top3);
Ok(())
}

View File

@ -1,6 +1,3 @@
use std::error::Error;
use std::fs;
#[derive(Debug, Copy, Clone)]
enum Calculation {
ByMove,
@ -137,8 +134,8 @@ fn get_total(lines: &Vec<&str>, score_type: Calculation) -> u32 {
.unwrap()
}
fn main() -> Result<(), Box<dyn Error>> {
let file_str = fs::read_to_string("input.txt")?;
fn main() {
let file_str = include_str!("input.txt");
let lines: Vec<&str> = file_str.lines().collect();
let part1_total = get_total(&lines, ByMove);
@ -146,6 +143,4 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("Part 1: Final score: {}", part1_total);
println!("Part 2: Final score: {}", part2_total);
Ok(())
}