Created
June 20, 2018 02:16
Star
You must be signed in to star a gist
Code shared from the Rust Playground
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
#![allow(unused_imports)] | |
use std::borrow::*; | |
use std::cmp::*; | |
use std::collections::*; | |
use std::iter::*; | |
use std::mem::*; | |
use std::*; | |
fn main() { | |
// CODEGOLF | |
use std::io::stdout as o; | |
use std::io::*; | |
macro_rules! print{($($a:tt)*)=>{($($a)*)}} | |
let mut v = vec!["".to_string()]; | |
let mut g = |a| { | |
v.push(a); | |
if v.len() == 27 { | |
let mut s = v.clone(); | |
s.sort(); | |
write!(o(), "["); | |
for i in 1..v.len() { | |
if i > 1 { | |
write!(o(), ","); | |
} | |
write!( | |
o(), | |
"{:?}", | |
s[s.iter().position(|x| x == &v[i]).unwrap() - 1] | |
); | |
} | |
write!(o(), "]"); | |
} | |
"" | |
}; | |
// ENDCODEGOLF | |
// Test harness. | |
let arg0 = [ | |
"Beggars can't be choosers", | |
"Do unto others as you would have them do to you", | |
]; | |
print!("["); | |
for i in 0..arg0.len() { | |
if i > 0 { | |
print!(","); | |
} | |
print!("{:?}", g(arg0[i].to_string())); | |
} | |
print!("]"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment