-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler038.go
52 lines (48 loc) · 876 Bytes
/
euler038.go
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"
"github.com/blevz/euler/common"
"strconv"
)
func Is19Pandigital(numstr string) bool {
if len(numstr) != 9 {
return false
}
digits := make([]bool, 9, 9)
for _, r := range numstr {
if r-'0' == 0 {
return false
}
v := digits[int(r-'1')]
if v {
return false
}
digits[int(r-'1')] = true
}
return true
}
func CheckForPandigMulti(x int) string {
numDigits := common.NumDigits(x)
numStr := strconv.Itoa(x)
for a := 2; numDigits < 9; a++ {
nextNum := x * a
numDigits += common.NumDigits(nextNum)
numStr = numStr + strconv.Itoa(nextNum)
}
if Is19Pandigital(numStr) {
fmt.Println(numStr)
return numStr
}
return ""
}
func main() {
for x := 90; x < 100; x++ {
CheckForPandigMulti(x)
}
for x := 900; x < 1000; x++ {
CheckForPandigMulti(x)
}
for x := 9000; x < 10000; x++ {
CheckForPandigMulti(x)
}
}