Skip to content

Instantly share code, notes, and snippets.

@angch
Last active March 24, 2016 12:08
Show Gist options
  • Save angch/371615c3c126df971900 to your computer and use it in GitHub Desktop.
Save angch/371615c3c126df971900 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
terms := make([]int16, 1000001)
maxterms := int16(0)
maxtermsNum := 0
for i := range terms {
c := int64(i)
count := int16(1)
for c > 1 {
if c%2 == 0 {
c = c / 2
} else {
c = c*3 + 1
}
if c < int64(i) {
count = count + terms[c]
break
}
count++
}
terms[i] = count
if count > maxterms {
maxterms = count
maxtermsNum = i
}
}
fmt.Println(maxtermsNum, maxterms)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment