summaryrefslogtreecommitdiff
path: root/p112/p112.go
blob: 91e5961b1d30620238bd11b90ebab40e0d2a550f (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main

import "fmt"

const (
  LIMITE = 0.99
)

func isBouncy( a int ) bool {
  if a < 101  {
    return false;
  }
  c, d := 0, 0

  for c == d && a != 0 {
    d = a % 10
    a /= 10
    c = a % 10
  }
  if c == d {
    return false;
  }
  if c < d {
    for c <= d && a != 0 {
      d = a % 10
      a /= 10
      c = a % 10
    }
  } else {
    for c >= d && a != 0 {
      d = a % 10
      a /= 10
      c = a % 10
    }
  }
  return a != 0
}

func main() {
  num := 0.
  tot := 10.
  i := 0

  for i = 11 ; num/tot < LIMITE ; i++ {
    if isBouncy(i) {
      num+=1.
    }
    tot+=1.
  }

  fmt.Println(i-1);
}