Closed tpphu closed 5 years ago
Hi @tpphu , em submit bai a
func Solution(num int) int {
result := 1
for i := 1; i < num; i++ {
result += 5 * i
}
return result
}
func TestSolution(t *testing.T) {
cases := []struct {
name string
input int
expect int
}{
{"Test case 1", 2, 6},
{"Test case 2", 5, 51},
}
for _, testcase := range cases {
t.Run(testcase.name, func(t *testing.T) {
got := Solution(testcase.input)
if !reflect.DeepEqual(got, testcase.expect) {
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
testcase.expect, got, testcase.input)
}
})
}
}
Có chứng minh gì ở chương trình đó không, sao nhìn đơn giản vậy :)
Da em de y thay la tong so cham xanh trong cai hinh pentagonal
thi minh dua vao cai iteration * 5 roi cong cho tong cai so cham xanh trong lan iteration truoc. Iteration la cai input do anh @tpphu
Challenge
Have the function PentagonalNumber(num) read num which will be a positive integer and determine how many dots exist in a pentagonal shape around a center dot on the Nth iteration. For example, in the image below you can see that on the first iteration there is only a single dot, on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots.
Your program should return the number of dots that exist in the whole pentagon on the Nth iteration.
Sample Test Cases
Credits: https://www.coderbyte.com/editor/guest:Pentagonal%20Number:Go