Last active
March 18, 2016 18:40
-
-
Save mdk-aza/fa8fcbb4e8ce5cc96dee to your computer and use it in GitHub Desktop.
This file contains 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() { | |
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