diff options
author | ache <ache@ache.one> | 2018-09-05 00:56:09 +0200 |
---|---|---|
committer | ache <ache@ache.one> | 2018-09-05 00:56:09 +0200 |
commit | 2bae1659ba8eb742f737ccb31d9ad7f25f9599f7 (patch) | |
tree | d8ad2b75cefbcc70f9c31f154682a44299958f67 /p125 |
Init commit
Diffstat (limited to 'p125')
-rw-r--r-- | p125/p_125.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/p125/p_125.go b/p125/p_125.go new file mode 100644 index 0000000..31baaca --- /dev/null +++ b/p125/p_125.go @@ -0,0 +1,61 @@ +package main +import "fmt" + + +// 10^8 is the maximum ... So let's use uint64 ... + +const LIMIT_MAX = uint64(100000000) + +func reverse( in uint64 ) (out uint64) { + + for ; in != 0 ; in /= 10 { + out *= 10 + out += in % 10 + } + + return +} +func isPalindromic( in uint64 ) bool { + return in == reverse(in) +} + +func showPile( slice []uint64 ) { + for i := 0 ; i < len(slice) ; i++ { + fmt.Printf("[%d]", slice[i]) + } + fmt.Println("") +} + +func main() { + + pile := []uint64{5}; + mem := [LIMIT_MAX]bool{}; + + for cmp := uint64(3) ; ; cmp++ { + + tmp := []uint64{}; + + for _,v := range pile { + mem[v] = true + if v+cmp*cmp < LIMIT_MAX { + tmp = append(tmp, v+cmp*cmp); + } + } + + pile = append(tmp, cmp*cmp+(cmp-1)*(cmp-1)) + + if len(tmp) == 0 { + break + } + + } + + cmp := 0 + for i,v := range mem { + if v && isPalindromic(uint64(i)) { + cmp+=i + } + } + + fmt.Println(cmp) +} |