File tree Expand file tree Collapse file tree 1 file changed +7
-18
lines changed
Check if The Number is Fascinating Expand file tree Collapse file tree 1 file changed +7
-18
lines changed Original file line number Diff line number Diff line change @@ -2,37 +2,26 @@ package kata
2
2
3
3
func isFascinating (n int ) bool {
4
4
var stats = [9 ]int {}
5
+ var tracker int = 0
5
6
for i := 1 ; i <= 3 ; i ++ {
6
- ok := countDigits (n * i , & stats )
7
+ ok := countDigits (n * i , & stats , & tracker )
7
8
if ! ok {
8
9
return false
9
10
}
10
11
}
11
- return assert ( & stats )
12
+ return true
12
13
}
13
14
14
- func countDigits (n int , stats * [9 ]int ) bool {
15
+ func countDigits (n int , stats * [9 ]int , tracker * int ) bool {
15
16
for n > 0 {
16
17
var digit = n % 10
17
18
n = n / 10
18
- if digit == 0 {
19
- return false
20
- }
21
19
digit = digit - 1
22
- currentCount := stats [digit ]
23
- if currentCount > 0 {
20
+ if digit == - 1 || stats [digit ] > 0 {
24
21
return false
25
22
}
26
23
stats [digit ]++
24
+ * tracker ++
27
25
}
28
- return true
29
- }
30
-
31
- func assert (stats * [9 ]int ) bool {
32
- for _ , count := range stats {
33
- if count == 0 || count > 1 {
34
- return false
35
- }
36
- }
37
- return true
26
+ return * tracker % 3 == 0
38
27
}
You can’t perform that action at this time.
0 commit comments