Created
May 17, 2020 14:27
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://play.golang.org/p/_h14fwBD0xY