Skip to content

Commit

Permalink
Added example of Collatz conjecture on golang
Browse files Browse the repository at this point in the history
  • Loading branch information
k8s4 committed Oct 15, 2024
1 parent 263ddea commit 4ccf208
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/golang/collatzconjecture.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"
// "time"
)

func collatzSequence(x int) {
// fmt.Printf("Collatz sequence for %d\n: ", n)
n := x
for n != 1 {
// fmt.Printf("%d ", n)
if n % 2 == 0 {
n = n / 2
} else {
n = 3 * n + 1
}
}
fmt.Printf("Finish for %d, last num 1\n", x)
}

func main() {
var number int = 1000000
for i := number; i != 1; i-- {
go collatzSequence(i)
}
}

0 comments on commit 4ccf208

Please sign in to comment.