mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 18:34:42 +01:00
refactor 04
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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