func problem62() *big.Int { cubes := make(map[string]*entry) one, three := big.NewInt(1), big.NewInt(3) for i := big.NewInt(0); ; i.Add(i, one) { x := new(big.Int).Exp(i, three, nil) // x := i**3 // Sort the digits to produce a 'canonical' representation. key := tools.SortedString(x.String()) e, ok := cubes[key] if !ok { cubes[key] = &entry{1, x} } else { e.count++ if x.Cmp(e.min) == -1 { // x < e.min e.min = x } if e.count == 5 { return e.min } } } }
// sameDigits checks whether two ints contain the same digits. func sameDigits(x, y int) bool { a := tools.SortedString(strconv.Itoa(x)) b := tools.SortedString(strconv.Itoa(y)) return a == b }
func isPerm(x, y int) bool { a := strconv.Itoa(x) b := strconv.Itoa(y) return tools.SortedString(a) == tools.SortedString(b) }