Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,33 +1,29 @@
package main
import (
"fmt"
"strconv"
)
import "fmt"
func happy(n int) bool {
m := make(map[int]int)
for n > 1 {
m[n] = 0
s := strconv.Itoa(n)
n = 0
for _, d := range s {
x := int(d) - '0'
n += x * x
}
if _, ok := m[n]; ok {
return false
}
}
return true
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("")
for found, n := 0, 1; found < 8; n++ {
if happy(n) {
fmt.Print(n, " ")
found++
}
}
fmt.Println()
}