refactor 04

This commit is contained in:
VicRen
2020-10-21 09:24:32 +08:00
parent d90cbe600d
commit 8dfafee7ca
2 changed files with 32 additions and 2 deletions

View File

@@ -7,11 +7,15 @@ import (
)
func main() {
findMaxPalindrome(100, 999)
}
func findMaxPalindrome(start, end int) int {
var n int
var x int
var y int
for i := 100; i < 1000; i++ {
for j := 100; j < 1000; j++ {
for i := start; i < end+1; i++ {
for j := start; j < end+1; j++ {
tmp := i * j
if tmp > n && IsPalindrome(tmp) {
x = i
@@ -21,6 +25,7 @@ func main() {
}
}
fmt.Println(x, y, n)
return n
}
func IsPalindrome(n int) bool {

View File

@@ -46,3 +46,28 @@ func TestIsPalindrome(t *testing.T) {
})
}
}
func Test_findMaxPalindrome(t *testing.T) {
type args struct {
start int
end int
}
tests := []struct {
name string
args args
want int
}{
{
"1",
args{10, 99},
9009,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := findMaxPalindrome(tt.args.start, tt.args.end); got != tt.want {
t.Errorf("findMaxPalindrome() = %v, want %v", got, tt.want)
}
})
}
}