mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-30 18:08:40 +01:00
refactor 04
This commit is contained in:
@@ -7,11 +7,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
findMaxPalindrome(100, 999)
|
||||||
|
}
|
||||||
|
|
||||||
|
func findMaxPalindrome(start, end int) int {
|
||||||
var n int
|
var n int
|
||||||
var x int
|
var x int
|
||||||
var y int
|
var y int
|
||||||
for i := 100; i < 1000; i++ {
|
for i := start; i < end+1; i++ {
|
||||||
for j := 100; j < 1000; j++ {
|
for j := start; j < end+1; j++ {
|
||||||
tmp := i * j
|
tmp := i * j
|
||||||
if tmp > n && IsPalindrome(tmp) {
|
if tmp > n && IsPalindrome(tmp) {
|
||||||
x = i
|
x = i
|
||||||
@@ -21,6 +25,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(x, y, n)
|
fmt.Println(x, y, n)
|
||||||
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPalindrome(n int) bool {
|
func IsPalindrome(n int) bool {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user