From e2e7175147c8b037f9cbd374f50a029d847d28fd Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Fri, 20 Aug 2021 09:31:10 -0500 Subject: [PATCH] updates after codewars submission... change logic from 'divisible by' to 'greater than divisor' deconstruct tuple for better readability --- src/main.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index ff60b2c..2c8fd6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,14 +27,11 @@ fn func(num: i32) -> String { let mut num = num; - while let Some(div) = stack.pop() { - while num/div.0 > 0 { - out.push(div.1); - num -= div.0; + while let Some((divisor, numeral)) = stack.pop() { + while num > divisor { + out.push(numeral); + num -= divisor; } - if num == 0 { - break - } } out.join("")