Skip to content

Instantly share code, notes, and snippets.

@maxjacobson
Created December 28, 2014 14:27
Show Gist options
  • Select an option

  • Save maxjacobson/8b7981370c4cbd5d32a9 to your computer and use it in GitHub Desktop.

Select an option

Save maxjacobson/8b7981370c4cbd5d32a9 to your computer and use it in GitHub Desktop.
package main
import(
"fmt"
"strconv"
"sort"
"strings"
)
func main() {
palindromes := []int{}
for i := 100; i <= 999; i++ {
for j := 100; j <= 999; j++ {
product := i * j
str := strconv.FormatInt(int64(product), 10)
if isPalindrome(str) {
palindromes = append(palindromes, product)
}
}
}
sort.Ints(palindromes)
fmt.Println(palindromes[ len(palindromes) - 1 ])
}
func isPalindrome(str string) bool {
chars := strings.Split(str, "")
for i := 0; i < len(chars); i++ {
if chars[i] != chars[ len(chars) - i - 1] {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment