Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Перенёс задания А и Б в свои функции, добавил тесты программы при запуске main функции #152

Open
wants to merge 32 commits into
base: Chadov_Sergej_Vadimovich
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cd08682
Переменные А и Б теперь в main, задания А и Б разделены по функциям
fagirton Nov 16, 2022
4339ac5
Merge branch 'Chadov_Sergej_Vadimovich' of https://github.com/fagirto…
fagirton Nov 16, 2022
d78dc16
Merge branch 'Chadov_Sergej_Vadimovich' of https://github.com/fagirto…
fagirton Nov 16, 2022
b6c0e76
Попытка в импровизированные тесты заданий А и Б
fagirton Nov 17, 2022
19b4f2f
Решение заданий с Codewars, также убрал повторяющиеся выводы в консоль
fagirton Nov 23, 2022
379dbb0
Перенес функции из main.go
fagirton Nov 23, 2022
58c9e06
Неужели нормальные тесты? + Нерабочая реализация Game of Life
fagirton Nov 28, 2022
024edad
Пока без gameOfLife потому что cognitive complexity 57 ((
fagirton Nov 28, 2022
08048ae
Снова исправления, чтобы порадовать линтер
fagirton Nov 28, 2022
c03f80c
Разделение тестов по заданиям
fagirton Nov 28, 2022
1343c2d
Проблемы с параллельностью?
fagirton Nov 28, 2022
af70f57
Тесты, тесты и снова доделываем тесты
fagirton Nov 30, 2022
877752e
Линтер, снова
fagirton Nov 30, 2022
38f0853
Гитигнор не хотел игнорить настройки VSC
fagirton Nov 30, 2022
efa2b1d
Добавил решения последних двух задач с codewars
fagirton Dec 1, 2022
18abfc8
Merge branch 'Chadov_Sergej_Vadimovich' of https://github.com/fagirto…
fagirton Dec 1, 2022
1a7e4aa
А вот и первое задание с codewars с польской коровой
fagirton Dec 1, 2022
b52c100
- Ненужные комментарии
fagirton Dec 2, 2022
2997edc
Исправил, но ещё не всё (есть код в комментах)
fagirton Dec 2, 2022
8a3b48b
Штуки с тестами
fagirton Dec 3, 2022
dd3fcea
Game Of Life (пока не готов - с проблемами)
fagirton Dec 3, 2022
71aa1a6
Linter moment
fagirton Dec 3, 2022
babd06e
Linter moment 2
fagirton Dec 3, 2022
52aa7f4
СКОБКИ. ВСЕМУ ВИНОЙ БЫЛИ СКОБКИ.
fagirton Dec 17, 2022
2384469
Опять не понял почему не работает
fagirton Dec 17, 2022
6806f27
GAME OF LIFE РАБОТАЕТ??? Не окончательная версия
fagirton Dec 24, 2022
1b07799
Линтер не хочет признавать мою победу
fagirton Dec 24, 2022
6a32963
Простая внутренняя проверка сетки для Game of Life
fagirton Dec 24, 2022
7a6bf05
Небольшие исправления в GoL
fagirton Dec 24, 2022
527741c
ОНО ПРАВДА РАБОТАЕТ, КАК НАДО (осталось переделать функцию проверки с…
fagirton Dec 28, 2022
fdb6a1f
Небольшой Clean-up в main, так и не сделал проверку сетки в GoL
fagirton Dec 28, 2022
5748713
Чайник с функцией Dead Inside
fagirton Jan 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang/.vscode/
golang/пускай подумает о своем поведении/
jskonst marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 0 additions & 4 deletions golang/.vscode/settings.json

This file was deleted.

2 changes: 2 additions & 0 deletions golang/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module isuct.ru/informatics2022

go 1.16

require github.com/stretchr/testify v1.8.1 // indirect
17 changes: 17 additions & 0 deletions golang/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
96 changes: 96 additions & 0 deletions golang/internal/codewars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package internal

import (
"fmt"
"math"
"strings"
)

func EvenOrOdd(num int) string {
if num%2 == 0 {
return "Even"
} else {
return "Odd"
}
}

func CountingSheep(arr []bool) int {
var res int
var i int
for ; i < len(arr); i++ {
if arr[i] && (arr[i] || !arr[i]) {
res++
}
}
return res
}

func MonkeysCount(num int) []int {
var res []int
for n := 1; n <= num; n++ {
res = append(res, n)
}
return res
}

func PaperworkCount(n int, m int) int {
if n < 0 || m < 0 {
return 0
}
return n * m
}

func HeroWithGunShootsDragons(ammo int, dragons int) bool {
return ammo/2 >= dragons
}

//Codewars 2: Возвращение

func PolishCow(text string) string {
var symbols = [][]string{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔕 используйте словарь

{"ą", "a"},
{"ć", "c"},
{"ę", "e"},
{"ł", "l"},
{"ń", "n"},
{"ó", "o"},
{"ź", "z"},
{"ż", "z"},
}
for i := 0; i < len(symbols); i++ {
text = strings.Replace(text, symbols[i][0], symbols[i][1], -1)
}
return text
}

func FindAll(arr []string, search string) []int {
var res []int
for i := 0; i < len(arr); i++ {
if arr[i] == search {
res = append(res, i)
}
}
return res
}

func SumOfMin(arr [][]int, m int, n int) int {
var res int
for i := 0; i < m; i++ {
min := math.Inf(1)
for a := 0; a < n; a++ {
if float64(arr[i][a]) < min {
min = float64(arr[i][a])
}
}
res = res + int(min)
}
return res
}

func PrintDeadInside() {
x := 1000
for x > 0 {
fmt.Print(x, "-7", "\n")
x -= 7
}
}
94 changes: 94 additions & 0 deletions golang/internal/gameOfLIfe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package internal

import (
"fmt"
)

func GameOfLife(grid [][]byte, step int) {
printGrid(grid, 0)
for i := 1; i <= step; i++ {
grid = printGrid(gol_Step(grid), i)
}
}

func printGrid(grid [][]byte, step int) [][]byte {
fmt.Println("Step ", step)
for x := 0; x < len(grid); x++ {
for y := 0; y < len(grid[0]); y++ {
switch grid[x][y] {
case 2:
fmt.Print("# ")
case 0:
fmt.Print("+ ")
case 1:
fmt.Print("0 ")
default:
fmt.Print("? ")
}
}
fmt.Println()
}
return grid
}

func checkNeighbors(grid [][]byte, PosX int, PosY int) int {
var nb_list [][]int8 = [][]int8{
{-1, -1},
{-1, 0},
{-1, 1},
{0, -1},
{0, 1},
{1, -1},
{1, 0},
{1, 1},
}
nb := 0
for nb_list_c := 0; nb_list_c < 8; nb_list_c++ {
if grid[PosX+int(nb_list[nb_list_c][0])][PosY+int(nb_list[nb_list_c][1])] == 1 {
nb++
}
}
return nb
}

func gol_Step(grid [][]byte) [][]byte {
overwrite_grid := make([][]byte, len(grid))
for i := range grid {
overwrite_grid[i] = make([]byte, len(grid[i]))
copy(overwrite_grid[i], grid[i])
}
for PosX := 1; PosX < len(grid)-1; PosX++ {
for PosY := 1; PosY < len(grid[0])-1; PosY++ {
nb := checkNeighbors(grid, PosX, PosY)
switch grid[PosX][PosY] {
case 0:
if nb == 3 {
overwrite_grid[PosX][PosY] = 1
} else {
overwrite_grid[PosX][PosY] = 0
}
case 1:
if nb == 2 || nb == 3 {
overwrite_grid[PosX][PosY] = 1
} else {
overwrite_grid[PosX][PosY] = 0
}
}
}
}
return overwrite_grid
}

func IsGridCorrect(grid [][]byte) bool {
for i := 0; i < len(grid[0])-1; i++ {
if grid[0][i] != byte(2) && grid[len(grid)-1][i] != byte(2) {
return false
}
}
for t := 1; t < len(grid)-2; t++ {
if grid[t][0] != byte(2) && grid[t][len(grid[0])-1] != byte(2) {
return false
}
}
return true
}
5 changes: 0 additions & 5 deletions golang/internal/sample.go

This file was deleted.

23 changes: 23 additions & 0 deletions golang/internal/tasks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package internal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Принято - все ок


import "math"

func Formula(x float64, a float64, b float64) float64 {
var y float64 = ((a*a*a)*(math.Cbrt(x)) - b*(math.Log10(x)/math.Log10(5))) / (math.Pow(math.Log10(x-1), 3))
return y
}

func TaskA(a float64, b float64, xn float64, xk float64, xd float64) []float64 {
var res []float64
for i := xn; i < xk; i = i + xd {
res = append(res, Formula(i, a, b))
}
return res
}
func TaskB(a float64, b float64, x []float64) []float64 {
var res []float64
for i := 0; i < len(x); i++ {
res = append(res, Formula(x[i], a, b))
}
return res
}
64 changes: 47 additions & 17 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,56 @@ package main

import (
"fmt"
"math"
"strconv"

"isuct.ru/informatics2022/internal"
)

func main() {
fmt.Println("Задание А")
var i float64 = 1.5
for ; i < 3.5; i = i + 0.4 {
fmt.Println(formula(i))
const a float64 = 4.1
const b float64 = 2.7
const xn float64 = 1.5
const xk float64 = 3.5
const xd float64 = 0.4

fmt.Println(internal.TaskA(a, b, xn, xk, xd))
fmt.Println(internal.TaskB(a, b, []float64{1.9, 2.15, 2.34, 2.74, 3.16}))

fmt.Println("\n Задания с Codewars")
fmt.Println(internal.EvenOrOdd(16))
fmt.Println(internal.CountingSheep([]bool{true, false, true, true, true}))
fmt.Println(internal.MonkeysCount(19))
fmt.Println(internal.PaperworkCount(23, 2))
fmt.Println(internal.HeroWithGunShootsDragons(37, 20))

//fmt.Println(internal.PolishCow("Gdzie jest biały węgorz?"))

//Code to convert []int to []string
nums := []int{6, 9, 3, 4, 3, 82, 11}
sNums := make([]string, len(nums))
for i, x := range nums {
sNums[i] = strconv.Itoa(x)
}

fmt.Println(internal.FindAll(sNums, fmt.Sprint(3)))

var exampleArr = [][]int{
{1, 2, 3, 4, 5},
{5, 6, 7, 8, 9},
{20, 21, 34, 56, 100},
}

fmt.Println(internal.SumOfMin(exampleArr, 3, 5))
fmt.Println("\n Game of Life")
sample_grid := [][]byte{
{2, 2, 2, 2, 2, 2, 2},
{2, 0, 0, 0, 0, 0, 2},
{2, 0, 0, 1, 0, 0, 2},
{2, 1, 0, 1, 0, 0, 2},
{2, 0, 1, 1, 0, 0, 2},
{2, 0, 0, 0, 0, 0, 2},
{2, 2, 2, 2, 2, 2, 2},
}
fmt.Println("Задание В")
fmt.Println(formula(1.9))
fmt.Println(formula(2.15))
fmt.Println(formula(2.34))
fmt.Println(formula(2.74))
fmt.Println(formula(3.16))
}

func formula(x float64) float64 {
var a float64 = 4.1
var b float64 = 2.7
var y float64 = (a*(math.Cbrt(x)) - b*(math.Log10(x)/math.Log10(5))) / (math.Pow(math.Log10(x-1), 3))
return y
internal.GameOfLife(sample_grid, 4)
}
14 changes: 0 additions & 14 deletions golang/tests/sample_test.go

This file was deleted.

Loading