parent
d8651623f8
commit
bf79c7262e
@ -0,0 +1 @@
|
||||
**/rust/target
|
@ -0,0 +1,4 @@
|
||||
[[package]]
|
||||
name = "advent_of_code_2018"
|
||||
version = "0.1.0"
|
||||
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "advent_of_code_2018"
|
||||
version = "0.1.0"
|
||||
authors = ["Alpha Chen <alpha.chen@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,22 @@
|
||||
use std::io::{self, Read};
|
||||
|
||||
fn day_1(input: &str, delimiter: &str) -> String {
|
||||
let sum: i32 = input
|
||||
.split(delimiter)
|
||||
.flat_map(|change| change.parse::<i32>().ok())
|
||||
.sum();
|
||||
sum.to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_day_1() {
|
||||
assert_eq!(day_1("+1, -2, +3, +1", ", "), "3");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
io::stdin().read_to_string(&mut input).unwrap();
|
||||
|
||||
let output = day_1(&input, "\n");
|
||||
println!("{}", output);
|
||||
}
|
Loading…
Reference in new issue