From f94507758c5786099025a82056c251ed9c9b8b17 Mon Sep 17 00:00:00 2001 From: Skye Im Date: Tue, 15 Nov 2022 17:56:43 +0100 Subject: skairunner: More comments --- entries/skairunner/src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) 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 { let mut memo = HashMap::new(); memo.insert(0, 0); @@ -23,6 +24,8 @@ fn init_memo() -> HashMap { memo } +/// Generate the fibonacci sequence number of f(n), +/// referencing the memo and updating it if needed. fn fib(n: i32, memo: &mut HashMap) -> Option { if let Some(number) = memo.get(&n) { return Some(*number); @@ -33,6 +36,7 @@ fn fib(n: i32, memo: &mut HashMap) -> Option { Some(f_n) } +/// Format prev and prevprev fn format_submessage(n: i32, memo: &mut HashMap, name: &str) -> String { let number = fib(n, memo); match number { @@ -47,6 +51,7 @@ fn format_submessage(n: i32, memo: &mut HashMap, name: &str) -> String } } +/// Generate a Fibonacci message. fn message_frame(n: i32, memo: &mut HashMap) -> String { let n_0 = fib(n, memo) .map(|number| { -- cgit v1.2.3-70-g09d2