-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
30 lines (27 loc) · 710 Bytes
/
generator.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
package algorithm
import (
"fmt"
"strconv"
"time"
)
func GeneratePeselsForDate(date time.Time, passChannel chan string) {
peselDate := date.Format("060102")
if date.Year() >= 2000 {
peselDate = peselDate[:2] + "2" + peselDate[3:]
}
for i := 0; i < 10000; i++ {
peselWithoutValidation := peselDate + fmt.Sprintf("%04d", i)
checksum := ControlSum(peselIntArray(peselWithoutValidation))
pesel := peselWithoutValidation + strconv.Itoa(checksum)
passChannel <- pesel
}
fmt.Println("Nothing found for: ", date)
close(passChannel)
}
func peselIntArray(pesel string) [10]int {
var peselArray [10]int
for idx, digit := range pesel {
peselArray[idx] = int(digit) - '0'
}
return peselArray
}