diff --git a/cap3/common.go b/cap3/common.go new file mode 100644 index 0000000..378eeb4 --- /dev/null +++ b/cap3/common.go @@ -0,0 +1,21 @@ +package cap3 + +import "fmt" + +func _printMatrix(matrix [][]int) { + for _, row := range matrix { + for _, val := range row { + fmt.Printf("%d\t", val) + } + fmt.Println() + } +} + +func _makeMatrix(size int) [][]int { + matrix := make([][]int, size) + for i := range matrix { + matrix[i] = make([]int, size) + } + + return matrix +} diff --git a/cap3/ex20.go b/cap3/ex20.go new file mode 100644 index 0000000..f8d734f --- /dev/null +++ b/cap3/ex20.go @@ -0,0 +1,43 @@ +package cap3 + +// Ex20 趣味矩阵 +func Ex20(n int) [][]int { + matrix := make([][]int, n) + for i := 0; i < len(matrix); i++ { + matrix[i] = make([]int, n) + } + + for i := range n { + for j := range n { + // 对角线 + if i == j || i+j == n-1 { + matrix[i][j] = 0 + continue + } + + // 左上部分 + if i+j < n-1 { + if i < j { + // 上 + matrix[i][j] = 1 + } else { + // 左 + matrix[i][j] = 2 + } + } + + // 右下边部分 + if i+j > n-1 { + if i > j { + // 下 + matrix[i][j] = 3 + } else { + // 右 + matrix[i][j] = 4 + } + } + } + } + + return matrix +} diff --git a/cap3/ex21.go b/cap3/ex21.go new file mode 100644 index 0000000..1ec5b29 --- /dev/null +++ b/cap3/ex21.go @@ -0,0 +1,66 @@ +package cap3 + +// Ex21 螺旋阵 +func Ex21(n int) [][]int { + matrix := _makeMatrix(n) + + // 逐层往里填充 + num := 1 + for layer := 0; layer < n/2; layer++ { + // 方阵左边 + for i := layer; i < n-layer; i++ { + matrix[i][layer] = num + num++ + } + + // 方阵下边 + for i := layer + 1; i < n-layer; i++ { + matrix[n-layer-1][i] = num + num++ + } + + // 方阵右边 + for i := n - layer - 2; i >= layer; i-- { + matrix[i][n-layer-1] = num + num++ + } + + // 方阵上边 + for i := n - layer - 2; i > layer; i-- { + matrix[layer][i] = num + num++ + } + } + + // 奇数阶中间位置需要手动设置 + if n%2 != 0 { + matrix[n/2][n/2] = n * n + } + + return matrix +} + +func Ex21type2(n int) [][]int { + matrix := _makeMatrix(n + 10) + + row, col, t := 0, 0, 1 + + for i := 0; i < n*n; { + for j := 0; j < 2*n; j++ { + i++ + matrix[row][col] = i + + switch (j + 1) / (n + 1) { + case 0: + row += t + case 1: + col += t + } + } + + n-- + t = -t + } + + return matrix +} diff --git a/cap3/ex22.go b/cap3/ex22.go new file mode 100644 index 0000000..7b87c2f --- /dev/null +++ b/cap3/ex22.go @@ -0,0 +1,43 @@ +package cap3 + +// Ex22 魔方阵,罗伯法 +func Ex22(n int) [][]int { + matrix := _makeMatrix(n) + if n%2 == 0 { + return matrix + } + + // 起始位置在第一行的中间 + i, j := 0, n/2 + + for num := 1; num <= n*n; num++ { + matrix[i][j] = num // 填充数字 + num++ // 下一个数字 + i-- // 向上移动 + j++ // 向右移动 + + // 如果移动后超出了上边界和右边界 + if i < 0 && j > n-1 { + i += 2 // 向下移动两格 + j-- // 向左移动一格 + } + + // 如果超出了上边界 + if i < 0 { + i = n - 1 // 移动到最下面一行 + } + + // 如果超出了右边界 + if j > n-1 { + j = 0 // 移动到最左边一列 + } + + // 如果当前位置已经填充了数字 + if matrix[i][j] != 0 { + i += 2 // 向下移动两格 + j-- // 向左移动一格 + } + } + + return matrix +} diff --git a/cap3/ex23.go b/cap3/ex23.go new file mode 100644 index 0000000..505a842 --- /dev/null +++ b/cap3/ex23.go @@ -0,0 +1,18 @@ +package cap3 + +type Pair struct { + first, second int +} + +func Ex23(nums []int) [][]int { + countMap := _makeMatrix(10) + + for _, num1 := range nums { + for _, num2 := range nums { + countMap[num1][num2]++ + countMap[num2][num1]++ + } + } + + return countMap +} diff --git a/cap3/ex24.go b/cap3/ex24.go new file mode 100644 index 0000000..c44fc23 --- /dev/null +++ b/cap3/ex24.go @@ -0,0 +1,5 @@ +package cap3 + +func Ex24(n int) int { + return 0 +} diff --git a/cap3/ex25.go b/cap3/ex25.go new file mode 100644 index 0000000..67481e0 --- /dev/null +++ b/cap3/ex25.go @@ -0,0 +1,20 @@ +package cap3 + +func Ex25(studentScore [][]int) int { + studentCount := 0 + for _, scores := range studentScore { + scoreCount := 0 + for _, score := range scores { + if score >= 90 { + scoreCount++ + } + + if scoreCount > 3 { + studentCount++ + break + } + } + } + + return studentCount +} diff --git a/cap3/ex26.go b/cap3/ex26.go new file mode 100644 index 0000000..e46fb7e --- /dev/null +++ b/cap3/ex26.go @@ -0,0 +1,22 @@ +package cap3 + +func Ex26(n int) []int { + lights := make([]bool, n) + // 默认值false,实际上意味着第一个人已经把所有灯关了,没必要再操作一遍 + // 第i个人,从第二个人开始 + for i := 2; i <= n; i++ { + // 编号为i的倍数的灯状态取反 + for j := 1; i*j <= n; j++ { + lights[i*j-1] = !lights[i*j-1] + } + } + + result := make([]int, 0, n) + for light, on := range lights { + if on { + result = append(result, light+1) + } + } + + return result +} diff --git a/cap3/ex27.go b/cap3/ex27.go new file mode 100644 index 0000000..24298a3 --- /dev/null +++ b/cap3/ex27.go @@ -0,0 +1,40 @@ +package cap3 + +type Ex27Condition int + +const ( + Ex27ConditionMin Ex27Condition = iota + Ex27ConditionMax +) + +func Ex27(nums []int) (max1, max2, min1, min2 int) { + size := len(nums) + if size < 3 { + return + } + + // 最大的乘积 + maxProd := nums[size-1] * nums[1] + max1, max2 = nums[size-1], nums[1] + + // 最小的乘积 + minProd := nums[size-1] * nums[1] + min1, min2 = nums[size-1], nums[1] + + for i := 1; i < size; i++ { + first, second := (size+i-1)%size, (i+1)%size + // 当前的乘积 + currentProd := nums[first] * nums[second] + + // 找出最大最小的乘积 + if currentProd > maxProd { + maxProd = currentProd + max1, max2 = nums[first], nums[second] + } else if currentProd < minProd { + minProd = currentProd + min1, min2 = nums[first], nums[second] + } + } + + return max1, max2, min1, min2 +} diff --git a/cap3/ex28.go b/cap3/ex28.go new file mode 100644 index 0000000..2b62001 --- /dev/null +++ b/cap3/ex28.go @@ -0,0 +1,20 @@ +package cap3 + +func Ex28(nums []int) { + n := len(nums) + for i := 0; i < n-1; i++ { + swapped := false + for j := 0; j < n-1-i; j++ { + if nums[j] < nums[j+1] { + tmp := nums[j] + nums[j] = nums[j+1] + nums[j+1] = tmp + swapped = true + } + } + + if !swapped { + break + } + } +} diff --git a/cap3/ex29.go b/cap3/ex29.go new file mode 100644 index 0000000..e8d8490 --- /dev/null +++ b/cap3/ex29.go @@ -0,0 +1,13 @@ +package cap3 + +func Ex29(nums []int) bool { + for _, num1 := range nums { + for _, num2 := range nums { + if num1 == num2 { + return false + } + } + } + + return true +} diff --git a/cap3/ex30.go b/cap3/ex30.go new file mode 100644 index 0000000..0a468f1 --- /dev/null +++ b/cap3/ex30.go @@ -0,0 +1,37 @@ +package cap3 + +import "math" + +type Ex30TriangleType int + +const ( + Ex30TriangleTypeNone Ex30TriangleType = iota // 不是三角形 + Ex30TriangleTypeNormal Ex30TriangleType = iota // 普通三角形 + Ex30TriangleTypeIsosceles Ex30TriangleType = iota // 等腰三角形 + Ex30TriangleTypeEquilateral Ex30TriangleType = iota // 等边三角形 + Ex30TriangleTypeRight Ex30TriangleType = iota // 直角三角形 +) + +func Ex30(nums []float64) Ex30TriangleType { + a, b, c := nums[0], nums[1], nums[2] + + if a <= 0 || b <= 0 || c <= 0 || a+b <= c || a+c <= b || b+c <= a { + return Ex30TriangleTypeNone + } + + if a == b && b == c { + return Ex30TriangleTypeEquilateral + } + + if a == b || a == c || b == c { + return Ex30TriangleTypeIsosceles + } + + if math.Pow(a, 2)+math.Pow(b, 2) == math.Pow(c, 2) || + math.Pow(a, 2)+math.Pow(c, 2) == math.Pow(b, 2) || + math.Pow(b, 2)+math.Pow(c, 2) == math.Pow(a, 2) { + return Ex30TriangleTypeRight + } else { + return Ex30TriangleTypeNormal + } +} diff --git a/cap3/ex31.go b/cap3/ex31.go new file mode 100644 index 0000000..177e00e --- /dev/null +++ b/cap3/ex31.go @@ -0,0 +1,34 @@ +package cap3 + +func Ex31(a, b, c int) int { + lcm, maxNum := 0, 0 + maxNum = max(a, b, c) + for i := 2; i <= maxNum; i++ { + hasDivisible := true + for hasDivisible { + hasDivisible = false + if a%i == 0 { + a = a / i + hasDivisible = true + } + + if b%i == 0 { + b = b / i + hasDivisible = true + } + + if c%i == 0 { + c = c / i + hasDivisible = true + } + + if hasDivisible { + lcm = lcm * i + } + } + + maxNum = max(a, b, c) + } + + return lcm +} diff --git a/cap3/ex32.go b/cap3/ex32.go new file mode 100644 index 0000000..97eaa83 --- /dev/null +++ b/cap3/ex32.go @@ -0,0 +1,28 @@ +package cap3 + +func Ex32() int { + for x := 1; x <= 4; x++ { + count := 0 + if x != 1 { + count++ + } + + if x == 3 { + count++ + } + + if x == 4 { + count++ + } + + if x != 4 { + count++ + } + + if count == 3 { + return x + } + } + + return 0 +} diff --git a/cap3/ex33.go b/cap3/ex33.go new file mode 100644 index 0000000..5d22ab7 --- /dev/null +++ b/cap3/ex33.go @@ -0,0 +1,5 @@ +package cap3 + +func Ex33() { + +} diff --git a/cap3/ex34.go b/cap3/ex34.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex34.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/ex35.go b/cap3/ex35.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex35.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/ex36.go b/cap3/ex36.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex36.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/ex37.go b/cap3/ex37.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex37.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/ex38.go b/cap3/ex38.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex38.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/ex39.go b/cap3/ex39.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex39.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/ex40.go b/cap3/ex40.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex40.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/ex41.go b/cap3/ex41.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/ex41.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/example_test.go b/cap3/example_test.go index e07f382..9ea1c81 100644 --- a/cap3/example_test.go +++ b/cap3/example_test.go @@ -1,217 +1,247 @@ package cap3 import ( - "fmt" - "strconv" - "testing" + "fmt" + "strconv" + "testing" ) func TestEx1(t *testing.T) { - fmt.Println(Ex1(1)) - fmt.Println(Ex1(2)) - fmt.Println(Ex1(3)) - fmt.Println(Ex1(4)) - fmt.Println(Ex1(5)) - fmt.Println(Ex1(6)) - fmt.Println(Ex1(7)) - fmt.Println(Ex1(8)) - fmt.Println(Ex1(9)) + fmt.Println(Ex1(1)) + fmt.Println(Ex1(2)) + fmt.Println(Ex1(3)) + fmt.Println(Ex1(4)) + fmt.Println(Ex1(5)) + fmt.Println(Ex1(6)) + fmt.Println(Ex1(7)) + fmt.Println(Ex1(8)) + fmt.Println(Ex1(9)) } func TestEx2(t *testing.T) { - result := Ex2() - for num, factors := range result { - fmt.Printf("%d's factors are %+v\n", num, factors) - } + result := Ex2() + for num, factors := range result { + fmt.Printf("%d's factors are %+v\n", num, factors) + } } func TestEx3(t *testing.T) { - matrix := [][]int{ - {1, 4, 5, 1}, - {8, 9, 6, 7}, - {1, 1, 4, 2}, - {0, 8, 2, 9}, - } - - row, col, val := Ex3(matrix) - if row != -1 && col != -1 { - fmt.Printf("(%d,%d): %d\n", row, col, val) - } + matrix := [][]int{ + {1, 4, 5, 1}, + {8, 9, 6, 7}, + {1, 1, 4, 2}, + {0, 8, 2, 9}, + } + + row, col, val := Ex3(matrix) + if row != -1 && col != -1 { + fmt.Printf("(%d,%d): %d\n", row, col, val) + } } func TestEx5(t *testing.T) { - beadsNum := 5 - step := 0 - - fmt.Println("NoneRecursive: ") - Ex5(beadsNum, AlgoTypeNoneRecursion, func(from string, to string) { - step++ - fmt.Printf("step %d: %s -> %s\n", step, from, to) - }) - - fmt.Println("----------------") - - step = 0 - fmt.Println("Recursive: ") - Ex5(beadsNum, AlgoTypeRecursion, func(from string, to string) { - step++ - fmt.Printf("step %d: %s -> %s\n", step, from, to) - }) + beadsNum := 5 + step := 0 + + fmt.Println("NoneRecursive: ") + Ex5(beadsNum, AlgoTypeNoneRecursion, func(from string, to string) { + step++ + fmt.Printf("step %d: %s -> %s\n", step, from, to) + }) + + fmt.Println("----------------") + + step = 0 + fmt.Println("Recursive: ") + Ex5(beadsNum, AlgoTypeRecursion, func(from string, to string) { + step++ + fmt.Printf("step %d: %s -> %s\n", step, from, to) + }) } func TestEx6(t *testing.T) { - prev := 0 - Ex6RecursionOutput(6, func(dividedNums []int) { - for i, num := range dividedNums { - if i == 0 { - if prev != num { - prev = num - fmt.Println() - } - fmt.Printf("%d", num) - } else { - fmt.Printf("+%d", num) - } - } - - fmt.Print("\t\t\t") - }) - - fmt.Println() - fmt.Println("------------") - - result := Ex6Recursion(6) - fmt.Println(result) - - result = Ex6NoneRecursion(6) - fmt.Println(result) + prev := 0 + Ex6RecursionOutput(6, func(dividedNums []int) { + for i, num := range dividedNums { + if i == 0 { + if prev != num { + prev = num + fmt.Println() + } + fmt.Printf("%d", num) + } else { + fmt.Printf("+%d", num) + } + } + + fmt.Print("\t\t\t") + }) + + fmt.Println() + fmt.Println("------------") + + result := Ex6Recursion(6) + fmt.Println(result) + + result = Ex6NoneRecursion(6) + fmt.Println(result) } func TestEx7(t *testing.T) { - num := uint64(123456) - Ex7(num, AlgoTypeNoneRecursion, func(digit uint8) { - fmt.Printf("%d ", digit) - }) - fmt.Println() - - Ex7(num, AlgoTypeRecursion, func(digit uint8) { - fmt.Printf("%d ", digit) - }) - fmt.Println() + num := uint64(123456) + Ex7(num, AlgoTypeNoneRecursion, func(digit uint8) { + fmt.Printf("%d ", digit) + }) + fmt.Println() + + Ex7(num, AlgoTypeRecursion, func(digit uint8) { + fmt.Printf("%d ", digit) + }) + fmt.Println() } func TestEx8(t *testing.T) { - num := uint64(123456) - Ex8(num, AlgoTypeNoneRecursion, func(digit uint8) { - fmt.Printf("%d ", digit) - }) - fmt.Println() - - Ex8(num, AlgoTypeRecursion, func(digit uint8) { - fmt.Printf("%d ", digit) - }) - fmt.Println() + num := uint64(123456) + Ex8(num, AlgoTypeNoneRecursion, func(digit uint8) { + fmt.Printf("%d ", digit) + }) + fmt.Println() + + Ex8(num, AlgoTypeRecursion, func(digit uint8) { + fmt.Printf("%d ", digit) + }) + fmt.Println() } func TestEx9(t *testing.T) { - bits := Ex9t1(137) - fmt.Printf("%d=", 137) - for i, bit := range bits { - if bit { - fmt.Printf("2^%d + ", i) - } - } - - println() - - pows := Ex9t2(137) - fmt.Printf("%d=", 137) - for _, pow := range pows { - fmt.Printf("2^%d + ", pow) - } - - println() + bits := Ex9t1(137) + fmt.Printf("%d=", 137) + for i, bit := range bits { + if bit { + fmt.Printf("2^%d + ", i) + } + } + + println() + + pows := Ex9t2(137) + fmt.Printf("%d=", 137) + for _, pow := range pows { + fmt.Printf("2^%d + ", pow) + } + + println() } func TestEx10(t *testing.T) { - Ex10(5, 3, func(nums []int) { - fmt.Printf("%+v\n", nums) - }) + Ex10(5, 3, func(nums []int) { + fmt.Printf("%+v\n", nums) + }) } func TestEx14(t *testing.T) { - num := uint64(8734112) - Ex14StrInput(strconv.FormatUint(num, 10), func(str string) { - fmt.Printf("%s-", str) - }) - fmt.Println() - - Ex14NumInput(num, func(str string) { - fmt.Printf("%s-", str) - }) - fmt.Println() + num := uint64(8734112) + Ex14StrInput(strconv.FormatUint(num, 10), func(str string) { + fmt.Printf("%s-", str) + }) + fmt.Println() + + Ex14NumInput(num, func(str string) { + fmt.Printf("%s-", str) + }) + fmt.Println() } func TestEx15(t *testing.T) { - result := Ex15(60, 70) - for cash, cashNum := range result { - fmt.Printf("%d->%d, ", cashes[cash], cashNum) - } - fmt.Println() - - result = Ex15(60, 100) - for cash, cashNum := range result { - fmt.Printf("%d->%d, ", cashes[cash], cashNum) - } - fmt.Println() - - result = Ex15(60, 74) - for cash, cashNum := range result { - fmt.Printf("%d->%d, ", cashes[cash], cashNum) - } - fmt.Println() - - result = Ex15(60, 130) - for cash, cashNum := range result { - fmt.Printf("%d->%d, ", cashes[cash], cashNum) - } - - fmt.Println() + result := Ex15(60, 70) + for cash, cashNum := range result { + fmt.Printf("%d->%d, ", cashes[cash], cashNum) + } + fmt.Println() + + result = Ex15(60, 100) + for cash, cashNum := range result { + fmt.Printf("%d->%d, ", cashes[cash], cashNum) + } + fmt.Println() + + result = Ex15(60, 74) + for cash, cashNum := range result { + fmt.Printf("%d->%d, ", cashes[cash], cashNum) + } + fmt.Println() + + result = Ex15(60, 130) + for cash, cashNum := range result { + fmt.Printf("%d->%d, ", cashes[cash], cashNum) + } + + fmt.Println() } func TestEx16(t *testing.T) { - count := 0 - Ex16(func(x, x2 int) { - count++ - fmt.Printf("%d: %d, x^2=%d\n", count, x, x2) - }) + count := 0 + Ex16(func(x, x2 int) { + count++ + fmt.Printf("%d: %d, x^2=%d\n", count, x, x2) + }) } func TestEx17(t *testing.T) { - n, k := 10, 2 - result := Ex17Normal(n, k) - fmt.Println(result) + n, k := 10, 2 + result := Ex17Normal(n, k) + fmt.Println(result) - result = Ex17Math(n, k) - fmt.Println(result) + result = Ex17Math(n, k) + fmt.Println(result) } func TestEx18(t *testing.T) { - fmt.Println(Ex18("6451", "6637") == "42815287") - fmt.Println(Ex18("1111", "2") == "2222") + fmt.Println(Ex18("6451", "6637") == "42815287") + fmt.Println(Ex18("1111", "2") == "2222") + + // 来个夸张点的 + ans := "59431035264803873745814101793588195732295068254603339623610036212240642359886400430165726959529476600423448130231213495885200101414878403047792277609642" + fmt.Println(Ex18( + "953249582974085793083245237450927435989430572386540298743509843545728475284751234", + "62345723854798175908734905872984724974984398572942345324535728479275413") == ans, + ) + + result := Ex18type3([]uint8{6, 4, 5, 1}, 6637) + fmt.Println(DigitSlice2String(result) == "42815287") +} - // 来个夸张点的 - ans := "59431035264803873745814101793588195732295068254603339623610036212240642359886400430165726959529476600423448130231213495885200101414878403047792277609642" - fmt.Println(Ex18( - "953249582974085793083245237450927435989430572386540298743509843545728475284751234", - "62345723854798175908734905872984724974984398572942345324535728479275413") == ans, - ) +func TestEx19(t *testing.T) { + fmt.Println(Ex19(10)) + fmt.Println(Ex19(100)) +} - result := Ex18type3([]uint8{6, 4, 5, 1}, 6637) - fmt.Println(DigitSlice2String(result) == "42815287") +func TestEx20(t *testing.T) { + matrix := Ex20(5) + _printMatrix(matrix) } -func TestEx19(t *testing.T) { - fmt.Println(Ex19(10)) - fmt.Println(Ex19(100)) +func TestEx21(t *testing.T) { + matrix := Ex21(3) + _printMatrix(matrix) + + fmt.Println("----------------") + + matrix = Ex21(4) + _printMatrix(matrix) + + fmt.Println("================") + + matrix = Ex21type2(3) + _printMatrix(matrix) + + fmt.Println("----------------") + + matrix = Ex21type2(4) + _printMatrix(matrix) +} + +func TestEx22(t *testing.T) { + m := Ex22(3) + _printMatrix(m) } diff --git a/cap3/genfile.sh b/cap3/genfile.sh new file mode 100644 index 0000000..7fcaf6c --- /dev/null +++ b/cap3/genfile.sh @@ -0,0 +1,5 @@ +# shellcheck disable=SC2006 +for count in `seq 20 41` +do + echo 'package cap3' >> ex$count.go +done diff --git a/cap3/work10.go b/cap3/work10.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work10.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work11.go b/cap3/work11.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work11.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work12.go b/cap3/work12.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work12.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work13.go b/cap3/work13.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work13.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work14.go b/cap3/work14.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work14.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work15.go b/cap3/work15.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work15.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work16.go b/cap3/work16.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work16.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work17.go b/cap3/work17.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work17.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work18.go b/cap3/work18.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work18.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work19.go b/cap3/work19.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work19.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work20.go b/cap3/work20.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work20.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work21.go b/cap3/work21.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work21.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work22.go b/cap3/work22.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work22.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work23.go b/cap3/work23.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work23.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work24.go b/cap3/work24.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work24.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work25.go b/cap3/work25.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work25.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work26.go b/cap3/work26.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work26.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work27.go b/cap3/work27.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work27.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work6.go b/cap3/work6.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work6.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work7.go b/cap3/work7.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work7.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work8.go b/cap3/work8.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work8.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work9.go b/cap3/work9.go new file mode 100644 index 0000000..17e9fed --- /dev/null +++ b/cap3/work9.go @@ -0,0 +1 @@ +package cap3 diff --git a/cap3/work_test.go b/cap3/work_test.go index da45d14..331d1d1 100644 --- a/cap3/work_test.go +++ b/cap3/work_test.go @@ -1,64 +1,55 @@ package cap3 import ( - "fmt" - "testing" + "fmt" + "testing" ) func TestWork1(t *testing.T) { - result := Work1(100) - for _, b := range result { - fmt.Print(b) - } + result := Work1(100) + for _, b := range result { + fmt.Print(b) + } - fmt.Println() -} - -func _printMatrix(matrix [][]int) { - for _, row := range matrix { - for _, element := range row { - fmt.Printf("%d\t", element) - } - fmt.Println() - } + fmt.Println() } func TestWork2(t *testing.T) { - matrix := Work2([]int{5, 7, 4, 8, 9, 1}) - _printMatrix(matrix) + matrix := Work2([]int{5, 7, 4, 8, 9, 1}) + _printMatrix(matrix) - println("----------------") + println("----------------") - matrix = Work2type2([]int{5, 7, 4, 8, 9, 1}) - _printMatrix(matrix) + matrix = Work2type2([]int{5, 7, 4, 8, 9, 1}) + _printMatrix(matrix) } func TestWork3(t *testing.T) { - matrix := Work3(7) - _printMatrix(matrix) + matrix := Work3(7) + _printMatrix(matrix) - fmt.Println("----------------") + fmt.Println("----------------") - matrix = Work3(6) - _printMatrix(matrix) + matrix = Work3(6) + _printMatrix(matrix) } func TestWork4(t *testing.T) { - matrix := Work4(5) - _printMatrix(matrix) + matrix := Work4(5) + _printMatrix(matrix) } func TestWork5(t *testing.T) { - matrix := Work5(6) - _printMatrix(matrix) + matrix := Work5(6) + _printMatrix(matrix) - fmt.Println("----------------") + fmt.Println("----------------") - matrix = Work5(5) - _printMatrix(matrix) + matrix = Work5(5) + _printMatrix(matrix) - fmt.Println("----------------") + fmt.Println("----------------") - matrix = Work5(10) - _printMatrix(matrix) + matrix = Work5(10) + _printMatrix(matrix) } diff --git a/package.sh b/package.sh new file mode 100644 index 0000000..e69de29