Numbers with same digit set in base 10 and base 16: Difference between revisions

Added Go
(added AWK)
(Added Go)
Line 269:
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481
</pre>
 
=={{header|Go}}==
{{trans|Wren}}
<lang go>package main
 
import (
"fmt"
"rcu"
"strconv"
)
 
func equalSets(s1, s2 map[rune]bool) bool {
if len(s1) != len(s2) {
return false
}
for k, _ := range s1 {
_, ok := s2[k]
if !ok {
return false
}
}
return true
}
 
func main() {
const limit = 100_000
count := 0
fmt.Println("Numbers under 100,000 which use the same digits in decimal or hex:")
for n := 0; n < limit; n++ {
h := strconv.FormatInt(int64(n), 16)
hs := make(map[rune]bool)
for _, c := range h {
hs[c] = true
}
ns := make(map[rune]bool)
for _, c := range strconv.Itoa(n) {
ns[c] = true
}
if equalSets(hs, ns) {
count++
fmt.Printf("%6s ", rcu.Commatize(n))
if count%10 == 0 {
fmt.Println()
}
}
}
fmt.Printf("\n\n%d such numbers found.\n", count)
}</lang>
 
{{out}}
<pre>
Numbers under 100,000 which use the same digits in decimal or hex:
0 1 2 3 4 5 6 7 8 9
53 371 913 1,040 2,080 2,339 4,100 5,141 5,412 5,441
6,182 8,200 9,241 13,593 13,665 13,969 16,406 20,530 26,946 30,979
32,803 33,638 33,840 33,841 33,842 33,843 33,844 33,845 33,846 33,847
33,848 33,849 34,883 37,943 38,931 38,966 38,995 66,310 71,444 71,497
71,511 75,120 75,121 75,122 75,123 75,124 75,125 75,126 75,127 75,128
75,129 75,621 86,150 88,165 91,465 91,769 96,617 98,711 99,481
 
69 such numbers found.
</pre>
 
9,485

edits