-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ✏️ decrease the number of lines
- Loading branch information
1 parent
7826c0c
commit a8178f3
Showing
1 changed file
with
5 additions
and
9 deletions.
There are no files selected for viewing
14 changes: 5 additions & 9 deletions
14
exercises/practice/collatz-conjecture/.approaches/recursion/snippet.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
def count_steps(conjecture_steps, number): | ||
if number <= 1: | ||
return conjecture_steps | ||
return count_steps( | ||
conjecture_steps + 1, number * 3 + 1 if number % 2 else number / 2 | ||
) | ||
|
||
def steps(number): | ||
def steps(number, conjecture_steps = 0): | ||
if number < 1: | ||
raise ValueError("Only positive integers are allowed") | ||
|
||
return count_steps(0, number) | ||
if number == 1: | ||
return conjecture_steps | ||
|
||
return steps(number * 3 + 1 if number % 2 else number / 2, conjecture_steps + 1) |