Skip to content

Commit e25809b

Browse files
committed
2729. Check if The Number is Fascinating
1 parent f38e77b commit e25809b

File tree

1 file changed

+33
-0
lines changed
  • Check if The Number is Fascinating

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package kata
2+
3+
func isFascinating(n int) bool {
4+
var stats = [9]int{}
5+
for i := 1; i <= 3; i++ {
6+
ok := countDigits(n*i, &stats)
7+
if !ok {
8+
return false
9+
}
10+
}
11+
return assert(&stats)
12+
}
13+
14+
func countDigits(n int, stats *[9]int) bool {
15+
for n > 0 {
16+
var digit = n % 10
17+
n = n / 10
18+
if digit == 0 {
19+
return false
20+
}
21+
stats[digit-1]++
22+
}
23+
return true
24+
}
25+
26+
func assert(stats *[9]int) bool {
27+
for _, count := range stats {
28+
if count == 0 || count > 1 {
29+
return false
30+
}
31+
}
32+
return true
33+
}

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