forked from exercism/odin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simpler error return value for collatz-conjecture
- Loading branch information
Showing
3 changed files
with
15 additions
and
22 deletions.
There are no files selected for viewing
13 changes: 4 additions & 9 deletions
13
exercises/practice/collatz-conjecture/.meta/collatz_conjecture_example.odin
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,20 +1,15 @@ | ||
package collatz_conjecture | ||
|
||
Error :: enum { | ||
None, | ||
IllegalArgument, | ||
} | ||
|
||
steps :: proc(start: int) -> (int, Error) { | ||
if (start <= 0) do return 0, .IllegalArgument | ||
steps :: proc(start: int) -> (result: int, ok: bool) { | ||
if (start <= 0) do return 0, false | ||
|
||
n := start | ||
result := 0 | ||
result = 0 | ||
|
||
for n > 1 { | ||
n = n / 2 if n % 2 == 0 else 3 * n + 1 | ||
result += 1 | ||
} | ||
|
||
return result, .None | ||
return result, true | ||
} |
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,8 +1,6 @@ | ||
package collatz_conjecture | ||
|
||
Error :: enum {} // Please inspect the tests to see which error states to enumerate here. | ||
|
||
// Returns the number of steps to get to a value of 1. | ||
steps :: proc(start: int) -> (int, Error) { | ||
steps :: proc(start: int) -> (result: int, ok: bool) { | ||
#panic("Please implement the `steps` procedure.") | ||
} |
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