Skip to content

Instantly share code, notes, and snippets.

@jig
Created May 17, 2020 14:27
Show Gist options
  • Save jig/5ee2d413418a529fc392c5fa29d3d3f8 to your computer and use it in GitHub Desktop.
Save jig/5ee2d413418a529fc392c5fa29d3d3f8 to your computer and use it in GitHub Desktop.
List numbers of 4 and 5 digits that one is the double of the other and all use the 9 digits from 1 to 9 without repiting.
package main
import "fmt"
func main() {
for j := 6234; j < 9876; j++ {
i := 2 * j
if nineChars(i, j) {
fmt.Printf("%d\t%d\n", i, j)
}
}
}
func nineChars(i, j int) bool {
str := fmt.Sprintf("%d%d", i, j)
digit := [9]bool{}
for _, c := range str {
if c == '0' {
return false
}
if digit[c-'1'] {
return false
}
digit[c-'1'] = true
}
return true
}
@jig
Copy link
Author

jig commented May 17, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment