Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Last active August 29, 2015 14:22
Show Gist options
  • Save yohhoy/0a336d935439edd8b95a to your computer and use it in GitHub Desktop.
Save yohhoy/0a336d935439edd8b95a to your computer and use it in GitHub Desktop.
Problem 4, "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
// Problem 4 - https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
// https://play.rust-lang.org/
fn solve(list: &[u32]) -> String {
let mut list = list.iter()
.map(|&n| n.to_string())
.collect::<Vec<String>>();
list.sort_by(|a,b| {
format!("{:=<10}", b).cmp(&format!("{:=<10}", a))
// Ex) [420, 42, 423] --> "42=" > "423" > "420"
});
list.connect("")
}
fn main() {
println!("solve={}", solve(&[50, 2, 1, 9]));
println!("solve={}", solve(&[420, 42, 423]));
println!("solve={}", solve(&[1, 10, 11]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment