Skip to content

Commit 89580d5

Browse files
committed
2729. Check if The Number is Fascinating v3
1 parent 8abb738 commit 89580d5

File tree

1 file changed

+7
-18
lines changed
  • Check if The Number is Fascinating

1 file changed

+7
-18
lines changed

Check if The Number is Fascinating/kata.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,26 @@ package kata
22

33
func isFascinating(n int) bool {
44
var stats = [9]int{}
5+
var tracker int = 0
56
for i := 1; i <= 3; i++ {
6-
ok := countDigits(n*i, &stats)
7+
ok := countDigits(n*i, &stats, &tracker)
78
if !ok {
89
return false
910
}
1011
}
11-
return assert(&stats)
12+
return true
1213
}
1314

14-
func countDigits(n int, stats *[9]int) bool {
15+
func countDigits(n int, stats *[9]int, tracker *int) bool {
1516
for n > 0 {
1617
var digit = n % 10
1718
n = n / 10
18-
if digit == 0 {
19-
return false
20-
}
2119
digit = digit - 1
22-
currentCount := stats[digit]
23-
if currentCount > 0 {
20+
if digit == -1 || stats[digit] > 0 {
2421
return false
2522
}
2623
stats[digit]++
24+
*tracker++
2725
}
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
3827
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy