Skip to content

Madina Bimakanova exercise 7 #234

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

Open
wants to merge 39 commits into
base: exercise7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5dd2909
Мадина Бимаканова add solutions for problems 1-5
Jul 30, 2024
7106bc9
Мадина Бимаканова add solution for problem 6
Madinab99999 Jul 30, 2024
a42d395
Мадина Бимаканова add solutions for problems 7-10
Jul 30, 2024
0be058c
Merge branch 'main' of github.com:talgat-ruby/exercises-go
Sep 24, 2024
ba4a0a9
Madina Bimakanova add solution for exercise2/problem1
Sep 25, 2024
4541d7f
Madina Bimakanova add solution for exercise2/problem2
Sep 25, 2024
11d06cb
Madina Bimakanova add solution for exercise2/problem4
Sep 25, 2024
06c8f21
Madina Bimakanova add solution for exercise2/problem5
Sep 25, 2024
126aceb
Madina Bimakanova add solution for exercise2/problem3
Sep 25, 2024
08b6a67
Madina Bimakanova add solution for exercise2/problem7
Sep 25, 2024
291220b
Madina Bimakanova add solution for exercise2/problem8
Sep 25, 2024
e1711a9
Madina Bimakanova add solution for exercise2/problem9
Sep 25, 2024
2900ae5
Madina Bimakanova add solution for exercise2/problem10
Sep 25, 2024
7514e5b
Madina Bimakanova add solution for exercise2/problem6
Sep 25, 2024
899c151
Madina Bimakanova add solution for exercise2/problem11
Sep 25, 2024
b99d2d6
Madina Bimakanova add solution for exercise2/problem12
Sep 25, 2024
bdfe3ca
Merge branch 'main' of github.com:talgat-ruby/exercises-go
Oct 2, 2024
4bd7da4
Madina Bimakanova add solution for exercise 3 problems 1-3
Oct 4, 2024
480ea03
Madina Bimakanova add solutions for exercise 3 problems 4-7
Oct 5, 2024
ca6fc35
Merge branch 'main' of github.com:talgat-ruby/exercises-go
Oct 10, 2024
6c12fec
Merge branch 'main' of github.com:talgat-ruby/exercises-go
Oct 20, 2024
0d1cea5
Add pkg
Oct 20, 2024
580e48d
Add player
Oct 20, 2024
8892d27
Add handler
Oct 20, 2024
e65cb35
Add server
Oct 20, 2024
f162366
Modified main.go and add joingame
Oct 20, 2024
c37b11a
Add ping and move
Oct 20, 2024
2afa7b7
Add logic for move
ArnurKabdylkak Oct 20, 2024
09d5d69
Add same change
Madinab99999 Oct 20, 2024
437d76f
Change port for judge in joingame.go
Madinab99999 Oct 21, 2024
ba84965
Merge branch 'main' of github.com:talgat-ruby/exercises-go
Oct 26, 2024
4f7efb7
Madina Bimakanova add all solutions for exercise 5
Nov 2, 2024
8125fb4
Merge branch 'main' of github.com:talgat-ruby/exercises-go
Nov 8, 2024
1887fe9
Merge branch 'main' of github.com:talgat-ruby/exercises-go into main
Nov 17, 2024
e83d557
Madina Bimakanova add all solutions for exercise 6
Nov 18, 2024
a6474f9
Merge pull request #227 from talgat-ruby/exercise7
talgat-ruby Nov 26, 2024
89a3f67
Merge branch 'main' of github.com:talgat-ruby/exercises-go into main
Nov 27, 2024
8405b1b
Madina Bimakanova add solution for exercise 7
Dec 5, 2024
bd6c3f9
Update function UpdateTags() in exercise 7
Dec 5, 2024
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
4 changes: 3 additions & 1 deletion exercise1/problem1/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package main

func addUp() {}
func addUp(n int) int {
return n * (n + 1) / 2
}
17 changes: 16 additions & 1 deletion exercise1/problem10/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
package main

func sum() {}
import "strconv"

func sum(s1, s2 string) (string, error) {
n1, err := strconv.Atoi(s1)
if err != nil {
return "", err
}

n2, err := strconv.Atoi(s2)
if err != nil {
return "", err
}

n3 := n1 + n2
return strconv.Itoa(n3), nil
}
16 changes: 15 additions & 1 deletion exercise1/problem2/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
package main

func binary() {}
import "strconv"

func binary(decNumber int) string {
if decNumber == 0 {
return "0"
}
binaryNumber := ""
for decNumber > 0 {
binaryNumber = strconv.Itoa(decNumber%2) + binaryNumber
decNumber = decNumber / 2
}

return binaryNumber

}
8 changes: 7 additions & 1 deletion exercise1/problem3/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package main

func numberSquares() {}
func numberSquares(number int) int {
squares := 0
for i := 1; i <= number; i++ {
squares += i * i
}
return squares
}
12 changes: 11 additions & 1 deletion exercise1/problem4/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
package main

func detectWord() {}
import "unicode"

func detectWord(s string) string {
word := ""
for _, char := range s {
if unicode.IsLower(char) {
word += string(char)
}
}
return word
}
6 changes: 5 additions & 1 deletion exercise1/problem5/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package main

func potatoes() {}
import "strings"

func potatoes(s string) int {
return strings.Count(s, "potato")
}
10 changes: 9 additions & 1 deletion exercise1/problem6/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
package main

func emojify() {}
import "strings"

func emojify(s string) string{
s = strings.ReplaceAll(s, "smile", "🙂")
s = strings.ReplaceAll(s, "grin", "😀")
s = strings.ReplaceAll(s, "sad", "😥")
s = strings.ReplaceAll(s, "mad", "😠")
return s
}
12 changes: 11 additions & 1 deletion exercise1/problem7/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
package main

func highestDigit() {}
func highestDigit(number int) int {
maxDigit := 0
for number != 0 {
digit := number % 10
if digit > maxDigit {
maxDigit = digit
}
number = number / 10
}
return maxDigit
}
13 changes: 12 additions & 1 deletion exercise1/problem8/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
package main

func countVowels() {}
func countVowels(word string) int {
vowels := []string{"a", "e", "i", "o", "u"}
count := 0
for _, i := range word {
for _, j := range vowels {
if string(i) == j {
count++
}
}
}
return count
}
12 changes: 9 additions & 3 deletions exercise1/problem9/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package main

func bitwiseAND() {}
func bitwiseAND(n1, n2 int) int {
return n1 & n2
}

func bitwiseOR() {}
func bitwiseOR(n1, n2 int) int {
return n1 | n2
}

func bitwiseXOR() {}
func bitwiseXOR(n1, n2 int) int {
return n1 ^ n2
}
15 changes: 14 additions & 1 deletion exercise2/problem1/problem1.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
package problem1

func isChangeEnough() {
func isChangeEnough(change [4]int, amount float32) bool {
var (
is_pay bool = false
summa int = 0
nominals = [4]int{25, 10, 5, 1}
)
for i, v := range change {
summa += nominals[i] * v
}
amount_int := int(amount * 100)
if summa >= amount_int {
is_pay = true
}
return is_pay
}
11 changes: 10 additions & 1 deletion exercise2/problem10/problem10.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
package problem10

func factory() {}
func factory() (map[string]int, func(string) func(int)) {
brands := make(map[string]int)
makeBrand := func(brand string) func(int) {
brands[brand] = 0
return func(count int) {
brands[brand] += count
}
}
return brands, makeBrand
}
12 changes: 11 additions & 1 deletion exercise2/problem11/problem11.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
package problem11

func removeDups() {}
func removeDups[T comparable](slc []T) []T {
new_slc := make([]T, 0, len(slc))
proverka_slc := make(map[any]struct{})
for _, v := range slc {
if _, ok := proverka_slc[v]; !ok {
proverka_slc[v] = struct{}{}
new_slc = append(new_slc, v)
}
}
return new_slc
}
32 changes: 31 additions & 1 deletion exercise2/problem12/problem12.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
package problem11

func keysAndValues() {}
import "fmt"

func keysAndValues[K comparable, V any](map_keysAndValues map[K]V) ([]K, []V) {
mas_keys := make([]K, 0, len(map_keysAndValues))
mas_values := make([]V, 0, len(map_keysAndValues))

for k, v := range map_keysAndValues {
mas_keys = append(mas_keys, k)
mas_values = append(mas_values, v)
}

sort_keys(mas_keys)

sortedValues := make([]V, len(mas_keys))
for i, k := range mas_keys {
sortedValues[i] = map_keysAndValues[k]
}

return mas_keys, sortedValues
}

func sort_keys[K comparable](keys []K) {
n := len(keys)
for i := 0; i < n; i++ {
for j := 0; j < n-i-1; j++ {
if fmt.Sprintf("%v", keys[j]) > fmt.Sprintf("%v", keys[j+1]) {
keys[j], keys[j+1] = keys[j+1], keys[j]
}
}
}
}
16 changes: 15 additions & 1 deletion exercise2/problem2/problem2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package problem2

func capitalize() {
func capitalize(names []string) []string {
var capitalizeNames []string
for _, name := range names {
var capitalizeName string
for i, char := range name {
if i == 0 && (char >= 'a' && char <= 'z') {
char -= 'a' - 'A'
} else if i != 0 && (char >= 'A' && char <= 'Z') {
char += 'a' - 'A'
}
capitalizeName += string(char)
}
capitalizeNames = append(capitalizeNames, capitalizeName)
}
return capitalizeNames
}
18 changes: 17 additions & 1 deletion exercise2/problem3/problem3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@ const (
lr dir = "lr"
)

func diagonalize() {
func diagonalize(number int, diagonal dir) [][]int {
matrix := make([][]int, number)
for i := 0; i < number; i++ {
matrix[i] = make([]int, number)
for j := 0; j < number; j++ {
if diagonal == ul {
matrix[i][j] = i + j
} else if diagonal == ur {
matrix[i][j] = number + i - j - 1
} else if diagonal == ll {
matrix[i][j] = number - i + j - 1
} else {
matrix[i][j] = 2*number - i - j - 2
}
}
}
return matrix
}
7 changes: 6 additions & 1 deletion exercise2/problem4/problem4.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package problem4

func mapping() {
func mapping(masLetters []string) map[string]string {
mapLetters := make(map[string]string)
for _, v := range masLetters {
mapLetters[v] = string(v[0] - 32)
}
return mapLetters
}
22 changes: 21 additions & 1 deletion exercise2/problem5/problem5.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
package problem5

func products() {
func products(pricesProducts map[string]int, minPrice int) []string {
var result []string
for i, v := range pricesProducts {
if v > minPrice {
result = append(result, i)
}
}
sortProducts(result, pricesProducts)
return result
}
func sortProducts(products []string, prices map[string]int) []string {
n := len(products)
for i := 0; i < n; i++ {
for j := 0; j < n-i-1; j++ {
if prices[products[j]] < prices[products[j+1]] ||
(prices[products[j]] == prices[products[j+1]] && products[j] > products[j+1]) {
products[j], products[j+1] = products[j+1], products[j]
}
}
}
return products
}
12 changes: 11 additions & 1 deletion exercise2/problem6/problem6.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package problem6

func sumOfTwo() {
func sumOfTwo(slc1 []int, slc2 []int, number int) bool {
var is_sum bool
for _, v1 := range slc1 {
for _, v2 := range slc2 {
if (v1 + v2) == number {
is_sum = true
break
}
}
}
return is_sum
}
3 changes: 2 additions & 1 deletion exercise2/problem7/problem7.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package problem7

func swap() {
func swap(a, b *int) {
*a, *b = *b, *a
}
11 changes: 5 additions & 6 deletions exercise2/problem8/problem8.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package problem8

func simplify(list []string) map[string]int {
var indMap map[string]int
indMap := make(map[string]int)

indMap = make(map[string]int)
load(&indMap, &list)
load(indMap, list)

return indMap
}

func load(m *map[string]int, students *[]string) {
for i, name := range *students {
(*m)[name] = i
func load(m map[string]int, students []string) {
for i, name := range students {
m[name] = i
}
}
9 changes: 8 additions & 1 deletion exercise2/problem9/problem9.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
package problem9

func factory() {}
func factory(number int) func(...int) []int {
return func(mas ...int) []int {
for i := 0; i < len(mas); i++ {
mas[i] = mas[i] * number
}
return mas
}
}
Loading