From 2bae1659ba8eb742f737ccb31d9ad7f25f9599f7 Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 5 Sep 2018 00:56:09 +0200 Subject: Init commit --- p113/p113.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 p113/p113.go (limited to 'p113') diff --git a/p113/p113.go b/p113/p113.go new file mode 100644 index 0000000..fc61465 --- /dev/null +++ b/p113/p113.go @@ -0,0 +1,75 @@ +package main + +import "fmt" + +const ( + LIMITE = 0.99 +) + +func isBouncy( a int ) int { + if a < 101 { + return 0; + } + c, d := 0, 0 + + inc := 0 + + for c == d && a != 0 { + d = a % 10 + a /= 10 + c = a % 10 + } + if c == d { + return 2; + } + if c < d { + inc = 1 + for c <= d && a != 0 { + d = a % 10 + a /= 10 + c = a % 10 + } + } else { + inc = -1 + for c >= d && a != 0 { + d = a % 10 + a /= 10 + c = a % 10 + } + } + if( a == 0 ) { + return inc + } else { + return 0 + } +} + +func main() { + tot := 0 + i := 0 + + inc := 0 + dec := 0 + bon := 0 + + + for i = 0 ; i < 10000 ; i++ { + if isBouncy(i) < 0 { + dec++ + } else if isBouncy(i) == 0 { + bon++ + } else if isBouncy(i) == 1 { + inc++ + } else { + dec++ + inc++ + } + tot+=1. + } + + fmt.Println(dec); + fmt.Println(inc); + fmt.Println(bon); + fmt.Println(tot-bon); + fmt.Println(tot); +} -- cgit v1.2.3