diff options
author | Skye Im | 2022-11-15 16:56:43 +0000 |
---|---|---|
committer | Skye Im | 2022-11-15 16:56:43 +0000 |
commit | f94507758c5786099025a82056c251ed9c9b8b17 (patch) | |
tree | d6d81a76f86940161b80ec141c8e20e2b5d1756d /entries/skairunner/src/main.rs | |
parent | f1009cb1163dbbfae1be2eb99d6232d55017e458 (diff) |
skairunner: More comments
Diffstat (limited to 'entries/skairunner/src/main.rs')
-rw-r--r-- | entries/skairunner/src/main.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/entries/skairunner/src/main.rs b/entries/skairunner/src/main.rs index 704c66a..f9a5b4f 100644 --- a/entries/skairunner/src/main.rs +++ b/entries/skairunner/src/main.rs @@ -16,6 +16,7 @@ fn field_number_is_illegal(n: i32) -> bool { 19000 <= n && n <= 19999 || n <= 0 } +/// Create a valid memo object initialized with f(0) and f(1) fn init_memo() -> HashMap<i32, i32> { let mut memo = HashMap::new(); memo.insert(0, 0); @@ -23,6 +24,8 @@ fn init_memo() -> HashMap<i32, i32> { memo } +/// Generate the fibonacci sequence number of f(n), +/// referencing the memo and updating it if needed. fn fib(n: i32, memo: &mut HashMap<i32, i32>) -> Option<i32> { if let Some(number) = memo.get(&n) { return Some(*number); @@ -33,6 +36,7 @@ fn fib(n: i32, memo: &mut HashMap<i32, i32>) -> Option<i32> { Some(f_n) } +/// Format prev and prevprev fn format_submessage(n: i32, memo: &mut HashMap<i32, i32>, name: &str) -> String { let number = fib(n, memo); match number { @@ -47,6 +51,7 @@ fn format_submessage(n: i32, memo: &mut HashMap<i32, i32>, name: &str) -> String } } +/// Generate a Fibonacci message. fn message_frame(n: i32, memo: &mut HashMap<i32, i32>) -> String { let n_0 = fib(n, memo) .map(|number| { |