Skip to content

Aray Mankenov Solved ex6 #233

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 27 commits into
base: exercise6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a0fda46
solved exercise1
ArayMankenov Jul 28, 2024
75d79c2
solved 2,3,9 problems
ArayMankenov Jul 30, 2024
e71d277
exercise 2
ArayMankenov Sep 25, 2024
d1fd924
Delete exercise2 directory
ArayMankenov Sep 26, 2024
8b0f1bc
Merge branch 'main' of github.com:talgat-ruby/exercises-go into aray-…
ArayMankenov Sep 26, 2024
5613211
solved exercise 2
ArayMankenov Sep 26, 2024
a9f427d
change problems
ArayMankenov Oct 9, 2024
5a81af1
delete cli
ArayMankenov Oct 9, 2024
8833227
added 3 & 4 exericses
ArayMankenov Oct 20, 2024
fe9f215
exercise3
ArayMankenov Oct 20, 2024
24ad91a
Merge remote-tracking branch 'upstream/exercise5' into aray-mankenov
ArayMankenov Nov 3, 2024
3d15fd2
ex 4
ArayMankenov Nov 3, 2024
e5870cb
solved ex 5
ArayMankenov Nov 3, 2024
af335e1
Merge pull request #208 from talgat-ruby/exercise6
talgat-ruby Nov 7, 2024
4fbcbfe
Merge pull request #212 from talgat-ruby/exercise6
talgat-ruby Nov 17, 2024
b4e7e89
add lesson7
talgat-ruby Nov 26, 2024
a6474f9
Merge pull request #227 from talgat-ruby/exercise7
talgat-ruby Nov 26, 2024
68016e8
Merge remote-tracking branch 'teacher/exercise6' into aray-mankenov
ArayMankenov Dec 4, 2024
17e3cd2
solved ex6
ArayMankenov Dec 4, 2024
0775bd4
add exercise9
Jan 23, 2025
80a13f5
Merge pull request #240 from talgat-ruby/exercise9
talgat-ruby Jan 23, 2025
753fb05
update exercise9
Jan 27, 2025
cb75c49
Merge pull request #241 from talgat-ruby/exercise9
talgat-ruby Jan 27, 2025
180a533
Merge branch 'main' of https://github.com/ArayMankenov/exercises-go i…
ArayMankenov Apr 13, 2025
4172622
Merge branch 'main' of https://github.com/talgat-ruby/exercises-go in…
ArayMankenov Apr 13, 2025
bb52981
solved exe7
ArayMankenov Apr 13, 2025
623571e
changed
ArayMankenov Apr 13, 2025
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
8 changes: 7 additions & 1 deletion exercise1/problem1/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package main

func addUp() {}
func addUp(num int) int {
res := 0
for i := 1; i <= num; i++ {
res = res + i
}
return res
}
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(a, b string) (string, error) {

n1, err := strconv.Atoi(a)
if err != nil {
return "", err
}
n2, err := strconv.Atoi(b)
if err != nil {
return "", err
}
res:=n1+n2
return strconv.Itoa(res),nil
}

18 changes: 17 additions & 1 deletion exercise1/problem2/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
package main

func binary() {}
import "fmt"

func binary(num int) string {
if num == 0 {
return "0"
}
var binaryStr string
for num > 0 {
remainder := num % 2

binaryStr = fmt.Sprintf("%d", remainder) + binaryStr

num /= 2
}

return binaryStr
}
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(num int) int {
totalSquares := 0
for k := 1; k <= num; k++ {
totalSquares += (num - k + 1) * (num - k + 1)
}
return totalSquares
}
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() {}
func detectWord(str string) string {
res := ""

for i := 0; i < len(str); i++ {
if str[i] >= 'a' && str[i] <= 'z' {
res = res + string(str[i])
}
}

return res
}
15 changes: 14 additions & 1 deletion exercise1/problem5/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
package main

func potatoes() {}
func potatoes(input string) int {

str := "potato"
strLength := len(str)
count := 0

for i := 0; i <= len(input)-strLength; i++ {
if input[i:i+strLength] == str {
count++
}
}

return count
}
26 changes: 25 additions & 1 deletion exercise1/problem6/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
package main

func emojify() {}
func emojify(input string) string {
runes := []rune(input)
result := make([]rune, 0, len(runes))

for i := 0; i < len(runes); {
if i+4 < len(runes) && string(runes[i:i+5]) == "smile" {
result = append(result, '🙂')
i += 5
} else if i+2 < len(runes) && string(runes[i:i+3]) == "sad" {
result = append(result, '😥')
i += 3
} else if i+3 < len(runes) && string(runes[i:i+4]) == "grin" {
result = append(result, '😀')
i += 4
} else if i+2 < len(runes) && string(runes[i:i+3]) == "mad" {
result = append(result, '😠')
i += 3
} else {
result = append(result, runes[i])
i++
}
}

return string(result)
}
17 changes: 16 additions & 1 deletion exercise1/problem7/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
package main

func highestDigit() {}
func highestDigit(num int) int {

res := 0

for num > 0 {

n := num % 10

if n > res {

res = n
}
num = num / 10
}
return res
}
10 changes: 9 additions & 1 deletion exercise1/problem8/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
package main

func countVowels() {}
func countVowels(input string) int {
count := 0
for i := 0; i < len(input); i++ {
if input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i] == 'u' {
count++
}
}
return count
}
14 changes: 9 additions & 5 deletions exercise1/problem9/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package main

func bitwiseAND() {}

func bitwiseOR() {}

func bitwiseXOR() {}
func bitwiseAND(a, b int) int {
return a & b
}
func bitwiseOR(a, b int) int {
return a | b
}
func bitwiseXOR(a, b int) int {
return a ^ b
}
5 changes: 4 additions & 1 deletion exercise2/problem1/problem1.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package problem1

func isChangeEnough() {
func isChangeEnough(arr [4]int, coast float32) bool {
sum := arr[0]*25 + arr[1]*10 + arr[2]*5 + arr[3]*1
cena := coast * 100
return sum >= int(cena)
}
16 changes: 15 additions & 1 deletion exercise2/problem10/problem10.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
package problem10

func factory() {}
func factory() (map[string]int, func(brand string) func(int)) {
brands := make(map[string]int)

makeBrand := func(brand string) func(int) {
if _, exists := brands[brand]; !exists {
brands[brand] = 0
}

return func(count int) {
brands[brand] += count
}
}

return brands, makeBrand
}
14 changes: 13 additions & 1 deletion exercise2/problem11/problem11.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
package problem11

func removeDups() {}
func removeDups[T comparable](list []T) []T {
seen := map[T]struct{}{}
output := make([]T, 0, len(list))
for _, v := range list {
if _, ok := seen[v]; ok {
continue
}
output = append(output, v)
seen[v] = struct{}{}
}

return output
}
22 changes: 21 additions & 1 deletion exercise2/problem12/problem12.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
package problem11

func keysAndValues() {}
import "sort"

func keysAndValues[K string | int, V comparable](mp map[K]V) ([]K, []V) {

keys := make([]K, 0, len(mp))
values := make([]V, 0, len(mp))

for k := range mp {
keys = append(keys, k)
}

sort.Slice(keys, func(i, j int) bool {
return keys[i] < keys[j]
})

for _, k := range keys {
values = append(values, mp[k])
}

return keys, values
}
12 changes: 11 additions & 1 deletion exercise2/problem2/problem2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package problem2

func capitalize() {
import (
"strings"
)

func capitalize(names []string) []string {
capitalizedNames := make([]string, len(names))
for i, name := range names {

capitalizedNames[i] = strings.Title(strings.ToLower(name))
}
return capitalizedNames
}
21 changes: 20 additions & 1 deletion exercise2/problem3/problem3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,24 @@ const (
lr dir = "lr"
)

func diagonalize() {
func diagonalize(n int, d dir) [][]int {
matrix := make([][]int, n)
for i := range matrix {
matrix[i] = make([]int, n)
}
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
switch d {
case ul:
matrix[i][j] = i + j
case ur:
matrix[i][j] = i + (n - 1 - j)
case ll:
matrix[i][j] = (n - 1 - i) + j
case lr:
matrix[i][j] = (n - 1 - i) + (n - 1 - j)
}
}
}
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(letters []string) map[string]string {
result := make(map[string]string)
for _, letter := range letters {
result[letter] = string(letter[0] - 32)
}
return result
}
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() {
import (
"sort"
)

func products(productMap map[string]int, minPrice int) []string {
var filteredProducts []string

for product, price := range productMap {
if price >= minPrice {
filteredProducts = append(filteredProducts, product)
}
}

sort.Slice(filteredProducts, func(i, j int) bool {
if productMap[filteredProducts[i]] == productMap[filteredProducts[j]] {
return filteredProducts[i] < filteredProducts[j]
}
return productMap[filteredProducts[i]] > productMap[filteredProducts[j]]
})

return filteredProducts
}
10 changes: 9 additions & 1 deletion exercise2/problem6/problem6.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
package problem6

func sumOfTwo() {
func sumOfTwo(a []int, b []int, c int) bool {
for _, i := range a {
for _, j := range b {
if i+j == c {
return true
}
}
}
return false
}
13 changes: 12 additions & 1 deletion exercise2/problem7/problem7.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package problem7

func swap() {
import (
"fmt"
)

func swap(x *int, y *int) {
*x, *y = *y, *x
}

func main() {
a, b := 1, 2
swap(&a, &b)
fmt.Println(a, b)
}
11 changes: 4 additions & 7 deletions exercise2/problem8/problem8.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package problem8

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

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

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

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

func factory() {}
func factory(a int) func(nums ...int) []int {
return func(nums ...int) []int {
res := make([]int, len(nums))
for i, num := range nums {
res[i] = num * a
}
return res
}
}
Loading