Use include_str for input files
This commit is contained in:
parent
d513b4fc0b
commit
d2ecca394d
@ -1,6 +1,3 @@
|
|||||||
use std::error::Error;
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
fn get_elves(raw: &str) -> Vec<Vec<u32>> {
|
fn get_elves(raw: &str) -> Vec<Vec<u32>> {
|
||||||
raw.split("\n\n")
|
raw.split("\n\n")
|
||||||
.map(|raw_elf| {
|
.map(|raw_elf| {
|
||||||
@ -25,8 +22,8 @@ fn get_elf_totals(elves: &Vec<Vec<u32>>) -> Vec<u32> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() {
|
||||||
let file_str = fs::read_to_string("input.txt")?;
|
let file_str = include_str!("input.txt"); //fs::read_to_string("input.txt")?;
|
||||||
let elves = get_elves(&file_str);
|
let elves = get_elves(&file_str);
|
||||||
|
|
||||||
let mut totals: Vec<u32> = get_elf_totals(&elves);
|
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 1: Most calories for one elf: {}", most);
|
||||||
println!("Part 2: Calories for top three elves: {}", top3);
|
println!("Part 2: Calories for top three elves: {}", top3);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
use std::error::Error;
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
enum Calculation {
|
enum Calculation {
|
||||||
ByMove,
|
ByMove,
|
||||||
@ -137,8 +134,8 @@ fn get_total(lines: &Vec<&str>, score_type: Calculation) -> u32 {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() {
|
||||||
let file_str = fs::read_to_string("input.txt")?;
|
let file_str = include_str!("input.txt");
|
||||||
let lines: Vec<&str> = file_str.lines().collect();
|
let lines: Vec<&str> = file_str.lines().collect();
|
||||||
|
|
||||||
let part1_total = get_total(&lines, ByMove);
|
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 1: Final score: {}", part1_total);
|
||||||
println!("Part 2: Final score: {}", part2_total);
|
println!("Part 2: Final score: {}", part2_total);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user