Skip to content

Instantly share code, notes, and snippets.

@mdk-aza
Last active March 18, 2016 18:40
Show Gist options
  • Save mdk-aza/fa8fcbb4e8ce5cc96dee to your computer and use it in GitHub Desktop.
Save mdk-aza/fa8fcbb4e8ce5cc96dee to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
fmt.Println(calcPalindromicNumber(9))
fmt.Println(calcPalindromicNumber(10))
}
func reverse(str string) string {
runes := []rune(str)
for i, j := 0, len(runes) - 1; i < j; i, j = i + 1, j - 1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
func calcPalindromicNumber(num rune) rune {
for i := num;; i++ {
if (i % 2 == 0) {
continue;
}
decimal := fmt.Sprintf("%d", i)
octal := fmt.Sprintf("%o", i)
binary := fmt.Sprintf("%b", i)
if (decimal == reverse(decimal) && octal == reverse(octal) && binary == reverse(binary)) {
return i;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment