Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Happy-numbers/Go/happy-numbers.go
Normal file
29
Task/Happy-numbers/Go/happy-numbers.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func happy(n int) bool {
|
||||
m := make(map[int]bool)
|
||||
for n > 1 {
|
||||
m[n] = true
|
||||
var x int
|
||||
for x, n = n, 0; x > 0; x /= 10 {
|
||||
d := x % 10
|
||||
n += d * d
|
||||
}
|
||||
if m[n] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func main() {
|
||||
for found, n := 0, 1; found < 8; n++ {
|
||||
if happy(n) {
|
||||
fmt.Print(n, " ")
|
||||
found++
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue