Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Gapful-numbers/Go/gapful-numbers.go
Normal file
41
Task/Gapful-numbers/Go/gapful-numbers.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func commatize(n uint64) string {
|
||||
s := fmt.Sprintf("%d", n)
|
||||
le := len(s)
|
||||
for i := le - 3; i >= 1; i -= 3 {
|
||||
s = s[0:i] + "," + s[i:]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func main() {
|
||||
starts := []uint64{1e2, 1e6, 1e7, 1e9, 7123}
|
||||
counts := []int{30, 15, 15, 10, 25}
|
||||
for i := 0; i < len(starts); i++ {
|
||||
count := 0
|
||||
j := starts[i]
|
||||
pow := uint64(100)
|
||||
for {
|
||||
if j < pow*10 {
|
||||
break
|
||||
}
|
||||
pow *= 10
|
||||
}
|
||||
fmt.Printf("First %d gapful numbers starting at %s:\n", counts[i], commatize(starts[i]))
|
||||
for count < counts[i] {
|
||||
fl := (j/pow)*10 + (j % 10)
|
||||
if j%fl == 0 {
|
||||
fmt.Printf("%d ", j)
|
||||
count++
|
||||
}
|
||||
j++
|
||||
if j >= 10*pow {
|
||||
pow *= 10
|
||||
}
|
||||
}
|
||||
fmt.Println("\n")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue