Created
October 24, 2020 13:49
-
-
Save ROki1988/8b60d26282f4ad6241ee77dd2da6935b to your computer and use it in GitHub Desktop.
sliding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::env::{args, args_os}; | |
use std::io; | |
use std::io::Read; | |
/// $ seq 1 4 | sliding | |
/// > 1 2 | |
/// > 2 3 | |
/// > 3 4 | |
fn main() -> Result<(), io::Error> { | |
let d = args().enumerate().find(|(_, x)| x == "-d").map_or_else( | |
|| " ".to_string(), | |
|(i, _)| { | |
args_os() | |
.nth(i + 1) | |
.expect("need value") | |
.to_str() | |
.unwrap() | |
.to_string() | |
}, | |
); | |
let io = io::stdin(); | |
let mut handle = io.lock(); | |
let mut buff = String::new(); | |
handle.read_to_string(&mut buff)?; | |
let iter = buff.lines().zip(buff.lines().skip(1)); | |
for x in iter { | |
println!("{}{}{}", x.0, d, x.1); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment