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 /p145 |
Init commit
Diffstat (limited to 'p145')
-rwxr-xr-x | p145/p145 | bin | 0 -> 2011690 bytes | |||
-rw-r--r-- | p145/p_145.go | 36 |
2 files changed, 36 insertions, 0 deletions
diff --git a/p145/p145 b/p145/p145 Binary files differnew file mode 100755 index 0000000..9c01167 --- /dev/null +++ b/p145/p145 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); +} |