Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
25 changes: 25 additions & 0 deletions challenge-1/submissions/Gorbushka3000/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"
)

func main() {
var a, b int
// Read two integers from standard input
_, err := fmt.Scanf("%d, %d", &a, &b)
if err != nil {
fmt.Println("Error reading input:", err)
return
}

// Call the Sum function and print the result
result := Sum(a, b)
fmt.Println(result)
}

// Sum returns the sum of a and b.
func Sum(a int, b int) int {
// TODO: Implement the function
return a+b
}
Comment on lines +21 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove the TODO comment or the implementation.

The TODO comment indicates the function needs to be implemented, but the implementation already exists. This creates confusion about whether the function is complete.

Additionally, consider using the more idiomatic Go function signature style:

 // Sum returns the sum of a and b.
-func Sum(a int, b int) int {
-	// TODO: Implement the function
-	return a+b
+func Sum(a, b int) int {
+	return a + b
 }
🤖 Prompt for AI Agents
In challenge-1/submissions/Gorbushka3000/solution-template.go around lines 21 to
25, remove the outdated TODO comment because the function is already
implemented, and optionally change the function signature to the idiomatic Go
form by combining parameter types (e.g., func Sum(a, b int) int) to improve
readability; keep the existing return implementation intact.

29 changes: 29 additions & 0 deletions challenge-2/submissions/Gorbushka3000/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"bufio"
"fmt"
"os"
)

func main() {
// Read input from standard input
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
input := scanner.Text()

// Call the ReverseString function
output := ReverseString(input)

// Print the result
fmt.Println(output)
}
}

// ReverseString returns the reversed string of s.
func ReverseString(s string) (result string) {
for _, c := range s{
result = string(c) + result
}
return result
}
68 changes: 68 additions & 0 deletions challenge-3/submissions/Gorbushka3000/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import "fmt"

type Employee struct {
ID int
Name string
Age int
Salary float64
}

type Manager struct {
Employees []Employee
}

// AddEmployee adds a new employee to the manager's list.
func (m *Manager) AddEmployee(e Employee) {
m.Employees = append(m.Employees, e)
}

// RemoveEmployee removes an employee by ID from the manager's list.
func (m *Manager) RemoveEmployee(id int) {
var removeValue []Employee
for i := 0; i < len(m.Employees); i++ {
if m.Employees[i].ID == id {
continue
} else {
removeValue = append(removeValue, m.Employees[i])
}
m.Employees = removeValue
}
}
Comment on lines +22 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical bug: assignment inside loop causes incorrect removal.

Line 30 assigns m.Employees = removeValue inside the loop, which executes on every iteration. This corrupts the employee list during traversal and produces incorrect results.

Apply this diff to move the assignment outside the loop:

 func (m *Manager) RemoveEmployee(id int) {
 	var removeValue []Employee
 	for i := 0; i < len(m.Employees); i++ {
 		if m.Employees[i].ID == id {
 			continue
-		} else {
-			removeValue = append(removeValue, m.Employees[i])
 		}
-		m.Employees = removeValue
+		removeValue = append(removeValue, m.Employees[i])
 	}
+	m.Employees = removeValue
 }
🤖 Prompt for AI Agents
In challenge-3/submissions/Gorbushka3000/solution-template.go around lines 22 to
32, the code assigns m.Employees = removeValue inside the for loop which mutates
the slice while iterating and corrupts traversal; move the assignment so it runs
once after the loop completes (declare removeValue, append non-matching
employees during iteration, then set m.Employees = removeValue after the loop)
so the original slice is not modified mid-iteration.


// GetAverageSalary calculates the average salary of all employees.
func (m *Manager) GetAverageSalary() float64 {
if len(m.Employees) == 0 {
return 0
}
var aveSal float64
for i := 0; i < len(m.Employees); i++ {
aveSal += m.Employees[i].Salary
}
return aveSal / float64(len(m.Employees))
}

// FindEmployeeByID finds and returns an employee by their ID.
func (m *Manager) FindEmployeeByID(id int) *Employee {
for i := 0; i < len(m.Employees); i++ {
if m.Employees[i].ID == id {
return &m.Employees[i]
}
}
return nil
}

func main() {
manager := Manager{}
manager.AddEmployee(Employee{ID: 1, Name: "Alice", Age: 30, Salary: 70000})
manager.AddEmployee(Employee{ID: 2, Name: "Bob", Age: 25, Salary: 65000})
manager.RemoveEmployee(1)
averageSalary := manager.GetAverageSalary()
employee := manager.FindEmployeeByID(2)

fmt.Printf("Average Salary: %f\n", averageSalary)
if employee != nil {
fmt.Printf("Employee found: %+v\n", *employee)
}
}