Read some input strings

wip
Alpha Chen 9 years ago
parent 763665c05a
commit af554e7bc8

@ -1,10 +1,25 @@
use std::fs::File;
use std::io::prelude::*;
use std::io;
use std::path::PathBuf;
extern crate advent_of_code; extern crate advent_of_code;
use advent_of_code::*; use advent_of_code::*;
fn main() { fn read_input(filename: &str) -> Result<String, io::Error> {
let day = Day01::new("".to_string()); let mut path = PathBuf::from(".");
match day.solve() { path.push("input");
Ok(n) => println!("{}", n), path.push(filename);
Err(e) => println!("{}", e), path.set_extension("txt");
let mut f = try!(File::open(path));
let mut s = String::new();
try!(f.read_to_string(&mut s));
Ok(s)
} }
fn main() {
let input = read_input("day_01").unwrap();
let day = Day01::new(input);
println!("{}", day.solve().unwrap());
} }

Loading…
Cancel
Save