Skip to content

Instantly share code, notes, and snippets.

@nerdyworm
Created August 6, 2013 16:57
Show Gist options
  • Save nerdyworm/6166365 to your computer and use it in GitHub Desktop.
Save nerdyworm/6166365 to your computer and use it in GitHub Desktop.
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