Skip to content

Instantly share code, notes, and snippets.

@marioaquino
Created March 4, 2016 15:51
Show Gist options
  • Save marioaquino/66a404c203b8ac7e6e5c to your computer and use it in GitHub Desktop.
Save marioaquino/66a404c203b8ac7e6e5c to your computer and use it in GitHub Desktop.
Rust Roman Numeral Kata (Lambda Lounge 3/16)
// use std::io;
fn main() {
// println!("What is your favorite color?");
println!("{}", 5);
}
fn get_input()->i32{
2951
}
fn romanize(input:i32) -> String {
if input > 0 && input <= 3000 {
let mut result = String::new();
let m = 1000;
let d = 500;
//let c = 100;
//let l = 50;
//let x = 10;
//let v = 5;
//let i = 1;
let (ms, remainder) = how_many(m, input);
let (ds, remainder) = how_many(d, remainder);
lotta_letters(ms, "M", &mut result);
lotta_letters(ds, "D", &mut result);
result.to_string()
} else {
"Give me a number between 0 and 3000".to_string()
}
}
fn how_many(divisor : i32, number : i32) -> (i32, i32) {
let ms = number / divisor;
let remainder = number - (ms * divisor);
(ms, remainder)
}
fn lotta_letters(how_many : i32, what : &str, result:&mut String) {
for _ in 0..how_many {
result.push_str(what);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment