Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created June 20, 2018 02:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rust-play/4e2011ba1781c1fd7313fab9ca307018 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![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