Compare commits
No commits in common. "10e1908c2538c1277a80faf3bd807ef154af367c" and "d7e4816e050cf2dd8145815ab6cd71e5f59bef59" have entirely different histories.
10e1908c25
...
d7e4816e05
12
README.md
12
README.md
@ -32,18 +32,6 @@ And so they form a single vine.
|
|||||||
Greet them as we have before.
|
Greet them as we have before.
|
||||||
Watch the nibblers spin and snap.
|
Watch the nibblers spin and snap.
|
||||||
```
|
```
|
||||||
|
|
||||||
# Roman Numerals (WIP)
|
|
||||||
Converts numbers between Roman Numerls and Arabic Numerals<br/>
|
|
||||||
### Example:
|
|
||||||
```
|
|
||||||
# Currently no Arabic -> Roman support
|
|
||||||
$ cargo run
|
|
||||||
input: MMXXV
|
|
||||||
output: 2025
|
|
||||||
```
|
|
||||||
TO DO: Functionality to convert Arabic to Roman, currently only does Roman to Arabic :)
|
|
||||||
|
|
||||||
# Snake (WIP)
|
# Snake (WIP)
|
||||||
Classic Snake game<br/>
|
Classic Snake game<br/>
|
||||||
TO DO: all of it...
|
TO DO: all of it...
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "roman-numerals"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[dependencies]
|
|
@ -1,70 +0,0 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use std::io::{stdin,stdout,Write};
|
|
||||||
|
|
||||||
fn input() -> String{
|
|
||||||
let mut s=String::new();
|
|
||||||
let _=stdout().flush();
|
|
||||||
stdin().read_line(&mut s).expect("Did not enter a correct string");
|
|
||||||
if let Some('\n')=s.chars().next_back() {
|
|
||||||
s.pop();
|
|
||||||
}
|
|
||||||
if let Some('\r')=s.chars().next_back() {
|
|
||||||
s.pop();
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
fn main() {
|
|
||||||
let mut numerals: HashMap<String, u64> = HashMap::new();
|
|
||||||
|
|
||||||
numerals.insert("I".to_string(), 1);
|
|
||||||
numerals.insert("V".to_string(), 5);
|
|
||||||
numerals.insert("X".to_string(), 10);
|
|
||||||
numerals.insert("L".to_string(), 50);
|
|
||||||
numerals.insert("C".to_string(), 100);
|
|
||||||
numerals.insert("D".to_string(), 500);
|
|
||||||
numerals.insert("M".to_string(), 1000);
|
|
||||||
|
|
||||||
let number = input();
|
|
||||||
let mut value: u64 = 4000;
|
|
||||||
let mut sum: u64 = 0;
|
|
||||||
let mut iteration = 0;
|
|
||||||
|
|
||||||
let mut skip_next = false;
|
|
||||||
|
|
||||||
let mut vector: Vec<String> = Vec::new();
|
|
||||||
|
|
||||||
for char in number.chars() {
|
|
||||||
vector.push(char.to_string());
|
|
||||||
};
|
|
||||||
|
|
||||||
for digit in vector {
|
|
||||||
if let Some(next_value) = numerals.get(&digit) {
|
|
||||||
if iteration > 0 && skip_next == false {
|
|
||||||
//println!("{}", skip_next);
|
|
||||||
//print!("{}: ", iteration);
|
|
||||||
if *next_value > value {
|
|
||||||
sum = sum + (*next_value - value);
|
|
||||||
//println!("{} = sum + ({} - {})", sum, *next_value, value);
|
|
||||||
skip_next = true;
|
|
||||||
value = *next_value;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sum = sum + value;
|
|
||||||
//println!("{} = sum + {}", sum, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
value = *next_value;
|
|
||||||
if skip_next {
|
|
||||||
skip_next = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("digit {} does not exist (My roman numerals only go up to M)!", digit);
|
|
||||||
}
|
|
||||||
iteration += 1;
|
|
||||||
}
|
|
||||||
if skip_next == false {
|
|
||||||
sum = sum + value;
|
|
||||||
}
|
|
||||||
println!("{}",sum);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user