Created
August 6, 2013 16:57
-
-
Save nerdyworm/6166365 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" | |
"math" | |
"strconv" | |
) | |
func main() { | |
smallest, _ := strconv.ParseInt("aaaaaaaaa", 16, 0) | |
firstTriangle := nThTriangle(smallest) | |
for i := firstTriangle; true ; i++ { | |
x := triangle(i) | |
str := fmt.Sprintf("%x", x) | |
if len(str) >= 9 && isAllLetters(str) { | |
fmt.Println(x) | |
break | |
} | |
} | |
} | |
func isAllLetters(s string) bool { | |
for i := range s { | |
if '0' <= s[i] && s[i] <= '9' { | |
return false | |
} | |
} | |
return true | |
} | |
func triangle(n int64) int64 { | |
return int64(n * (n + 1) / 2); | |
} | |
func nThTriangle(x int64) int64 { | |
return int64((math.Sqrt(float64(8*x+1)) - 1 ) / 2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment