From 88fb8f05552f3541be51f607be00c538d441d04f Mon Sep 17 00:00:00 2001 From: fluellenarman Date: Tue, 14 Jan 2025 22:26:00 -0800 Subject: [PATCH] fix(445-power_rule_differentiation should hide unnecessary powers): fixed by string.replace() Code is readable, but O(N*M) might be overkill for essentially a string parsing problem. Im assuming though that performance is not main priority --- mathgenerator/calculus.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mathgenerator/calculus.py b/mathgenerator/calculus.py index 42196c3..9eb411b 100644 --- a/mathgenerator/calculus.py +++ b/mathgenerator/calculus.py @@ -44,7 +44,11 @@ def power_rule_differentiation(max_coef=10, max_exp=10, max_terms=5): problem += f'{coefficient}x^{{{exponent}}}' solution += f'{coefficient * exponent}x^{{{exponent - 1}}}' - + + problem = problem.replace('x^{1}', 'x') + problem = problem.replace('x^{0}', '') + solution = solution.replace('x^{1}', 'x') + solution = solution.replace('x^{0}', '') return problem + '$', solution + '$'