3 ms·
As long as we're posting code/golfing (and since I've been lots of file parsing lately and it's fresh): use std::io::prelude::*; use std::fs::File;
by Crespyl 10y ago
As long as we're posting code/golfing (and since I've been lots of file parsing lately and it's fresh):
use std::io::prelude::*;
use std::fs::File;
fn main() {
let mut s = String::new();
File::open("numbers.txt")
.unwrap()
.read_to_string(&mut s);
let sum = s.lines()
.map(|l| l.parse::<i32>().unwrap())
.fold(0, |acc, i| acc+i);
println!("{}", sum);
}