Skip to content

Instantly share code, notes, and snippets.

@erikg
Created March 20, 2022 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikg/17d2815440096008831633297d08272b to your computer and use it in GitHub Desktop.
Save erikg/17d2815440096008831633297d08272b to your computer and use it in GitHub Desktop.
minimal program to sum values from stdin, in rust.
use std::{io, io::prelude::*};
pub fn main() {
let mut sum = 0;
for line in io::stdin().lock().lines() {
sum = sum + line.unwrap().parse::<i32>().unwrap();
}
println!("{}", sum);
}
@erikg
Copy link
Author

erikg commented Mar 20, 2022

awk
BEGIN{SUM=0}{SUM+=$1}END{print SUM}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment