More polishing
This commit is contained in:
parent
e854a29491
commit
2108b8b22b
|
@ -6,7 +6,7 @@ version = "0.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rustlang-fibonnaci"
|
||||
name = "fibonnaci_kreyren"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"die 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "rustlang-fibonnaci"
|
||||
name = "fibonnaci_kreyren"
|
||||
version = "0.1.0"
|
||||
authors = ["Kreyren <KostWarCZE@RiXotStudio.cz>"]
|
||||
edition = "2018"
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
use std::io;
|
||||
use std::string::String;
|
||||
use die::Die;
|
||||
|
||||
use fibonnaci_kreyren::fib;
|
||||
|
||||
macro_rules! fixme {
|
||||
($msg:expr) => ( println!("FIXME: {}", $msg);)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[allow(non_snake_case)] // Makes it more readable
|
||||
let mut userInput = String::new();
|
||||
|
||||
// Process userInput
|
||||
io::stdin().read_line(&mut userInput)
|
||||
.die_code("Unexpected input 'fixme_input_value' has been parsed", 256);
|
||||
let n: f64 = userInput.trim_end_matches("\n").parse()
|
||||
.die_code("Invalid argument 'fixme_argument' has been parsed", 2);
|
||||
|
||||
// FIXME: Optimize better for numbers greater then 41
|
||||
if n > 41.0 {
|
||||
fixme!("Function 'fib' takes too long to process numbers greater then 41");
|
||||
}
|
||||
|
||||
// Output
|
||||
println!("{}", fib(n));
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
use die::die;
|
||||
|
||||
// Fibonnaci sequence
|
||||
pub fn fib(n: f64) -> f64 {
|
||||
if n == 0.0 {
|
||||
return 0.0;
|
||||
} else if n == 1.0 {
|
||||
return 1.0;
|
||||
} else if n > 1.0 {
|
||||
return fib(n-1.0) + fib(n-2.0);
|
||||
} else {
|
||||
die!(256; "Unexpected happend while processing number '{}'", n);
|
||||
}
|
||||
}
|
29
src/main.rs
29
src/main.rs
|
@ -1,29 +0,0 @@
|
|||
use die::Die;
|
||||
use die::die;
|
||||
use std::io;
|
||||
use std::string::String;
|
||||
|
||||
// Fibonnaci sequence
|
||||
fn fib(n: f64) -> f64 {
|
||||
if n == 0.0 {
|
||||
return 0.0;
|
||||
} else if n == 1.0 {
|
||||
return 1.0;
|
||||
} else if n > 1.0 {
|
||||
return fib(n-1.0) + fib(n-2.0);
|
||||
} else {
|
||||
die!(256; "Unexpected happend while processing number '{}'", n);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[allow(non_snake_case)]
|
||||
let mut userInput = String::new();
|
||||
|
||||
// Process userInput
|
||||
io::stdin().read_line(&mut userInput).die_code("Unexpected input 'fixme_input_value' has been parsed", 256);
|
||||
let n: f64 = userInput.trim_end_matches("\n").parse().die_code("Invalid argument 'fixme_argument' has been parsed", 2);
|
||||
|
||||
// Output
|
||||
println!("{}", fib(n));
|
||||
}
|
Loading…
Reference in New Issue