summaryrefslogtreecommitdiff
path: root/p145/p_145.go
blob: 6fc832c034c034804a7b6ccf348e038faa281feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
}