From 2bae1659ba8eb742f737ccb31d9ad7f25f9599f7 Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 5 Sep 2018 00:56:09 +0200 Subject: Init commit --- p145/p_145.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 p145/p_145.go (limited to 'p145/p_145.go') 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); +} -- cgit v1.2.3-54-g00ecf