Skip to content

Instantly share code, notes, and snippets.

@LordRahl90
Last active March 5, 2019 12:32
Show Gist options
  • Save LordRahl90/af632fc75134b89fa04475e8d03b5370 to your computer and use it in GitHub Desktop.
Save LordRahl90/af632fc75134b89fa04475e8d03b5370 to your computer and use it in GitHub Desktop.
Biggest Palindrome, Project Euler #4
package main
import "fmt"
func flip(n int) int {
var v int
for n != 0 { //to make it cater for negative numbers
remainder := n % 10
v = v*10 + remainder
n /= 10
}
return v
}
func main() {
var p int
for i := 100; i < 1000; i++ {
for j := 100; j < 1000; j++ {
m := i * j
f := flip(m)
if m == f {
if f > p {
p = f
}
}
}
}
fmt.Println("Largest Palindrom is: ", p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment