Last active
March 5, 2019 12:32
-
-
Save LordRahl90/af632fc75134b89fa04475e8d03b5370 to your computer and use it in GitHub Desktop.
Biggest Palindrome, Project Euler #4
This file contains hidden or 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 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