diff options
Diffstat (limited to 'p145/p_145.go')
-rw-r--r-- | p145/p_145.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/p145/p_145.go b/p145/p_145.go new file mode 100644 index 0000000..6fc832c --- /dev/null +++ b/p145/p_145.go @@ -0,0 +1,36 @@ +package main +import "fmt" + + +// 10^9 is the maximum ... So let's use uint64 ... +// It solves it in 16s ... Yeap brute force. + +func reverse( in uint64 ) (out uint64) { + + for ; in != 0 ; in /= 10 { + out *= 10 + out += in % 10 + } + + return +} +func hasOnlyOdd( in uint64 ) bool { + + for ; in != 0 ; in /= 10 { + if (in%10)&1 == 0 { + return false + } + } + return true +} + +func main() { + cmp := 0 + for i := uint64(0) ; i < 1000000000 ; i++ { + if i % 10 != 0 && // Check for leading zeroes + hasOnlyOdd( i + reverse(i) ) { + cmp++; + } + } + fmt.Println(cmp); +} |