Last active
January 18, 2022 13:50
-
-
Save oriapp/1aabc1d3e825016d943fae903e24c9d4 to your computer and use it in GitHub Desktop.
You can read more at: https://en.wikipedia.org/wiki/Collatz_conjecture
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
/* | |
Rules: | |
if the number is odd -> multiply by three and add 1 (one) | |
if the number is even -> divide by 2 (two) | |
*/ | |
func main() { | |
startPoint := 7 | |
for { | |
startPoint = RuleChecker(startPoint) | |
fmt.Println(startPoint) | |
time.Sleep(time.Second) | |
} | |
} | |
func RuleChecker(number int) int { | |
if number%2 != 0 { | |
return (number * 3) + 1 | |
} | |
return number / 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment