Skip to content
Open
Show file tree
Hide file tree
Changes from all 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.

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

import (
"fmt"
"math"
)

func main() {
// Example usage
celsius := 25.0
fahrenheit := CelsiusToFahrenheit(celsius)
fmt.Printf("%.2f°C is equal to %.2f°F\n", celsius, fahrenheit)

fahrenheit = 68.0
celsius = FahrenheitToCelsius(fahrenheit)
fmt.Printf("%.2f°F is equal to %.2f°C\n", fahrenheit, celsius)
}

// CelsiusToFahrenheit converts a temperature from Celsius to Fahrenheit
// Formula: F = C × 9/5 + 32
func CelsiusToFahrenheit(celsius float64) float64 {
c := celsius
return Round(c*1.8+32, 2)
}

// FahrenheitToCelsius converts a temperature from Fahrenheit to Celsius
// Formula: C = (F - 32) × 5/9
func FahrenheitToCelsius(fahrenheit float64) float64 {
f := (fahrenheit - 32) * 5 / 9
return Round(f, 2)
}

// Round rounds a float64 value to the specified number of decimal places
func Round(value float64, decimals int) float64 {
precision := math.Pow10(decimals)
return math.Round(value*precision) / precision
}
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
}
64 changes: 64 additions & 0 deletions challenge-22/submissions/Gorbushka3000/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"fmt"
)

func main() {
// Standard U.S. coin denominations in cents
denominations := []int{1, 5, 10, 25, 50}

// Test amounts
amounts := []int{87, 42, 99, 33, 7}

for _, amount := range amounts {
// Find minimum number of coins
minCoins := MinCoins(amount, denominations)

// Find coin combination
coinCombo := CoinCombination(amount, denominations)

// Print results
fmt.Printf("Amount: %d cents\n", amount)
fmt.Printf("Minimum coins needed: %d\n", minCoins)
fmt.Printf("Coin combination: %v\n", coinCombo)
fmt.Println("---------------------------")
}
}

// MinCoins returns the minimum number of coins needed to make the given amount.
// If the amount cannot be made with the given denominations, return -1.
func MinCoins(amount int, denominations []int) int {
var l int
for i := len(denominations); i > 0; i-- {
for amount-denominations[i-1] >= 0 {
amount = amount - denominations[i-1]
l++
}
}
if amount < 0 {
return -1
} else if amount > 0 {
return -1
}
return l
}

// CoinCombination returns a map with the specific combination of coins that gives
// the minimum number. The keys are coin denominations and values are the number of
// coins used for each denomination.
// If the amount cannot be made with the given denominations, return an empty map.
func CoinCombination(amount int, denominations []int) map[int]int {
coinCombination := make(map[int]int)
for i := len(denominations); i > 0; i-- {
for amount-denominations[i-1] >= 0 {
amount = amount - denominations[i-1]
coinCombination[denominations[i-1]]++
}
}
if amount < 0 {
combination := make(map[int]int)
return combination
}
return coinCombination
}
Comment on lines +51 to +64
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 | 🟠 Major

Same greedy algorithm limitation applies.

This function has the same greedy algorithm issue as MinCoins - it won't produce optimal results for arbitrary denominations. The core logic (lines 53-58) is nearly identical to lines 33-37 in MinCoins, suggesting an opportunity to refactor and share the logic.

Consider extracting the shared greedy logic into a helper function, or having MinCoins call CoinCombination and sum the values:

func MinCoins(amount int, denominations []int) int {
	combo := CoinCombination(amount, denominations)
	total := 0
	for _, count := range combo {
		total += count
	}
	if len(combo) == 0 && amount > 0 {
		return -1
	}
	return total
}

25 changes: 20 additions & 5 deletions challenge-3/solution-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,38 @@ type Manager struct {

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

// RemoveEmployee removes an employee by ID from the manager's list.
func (m *Manager) RemoveEmployee(id int) {
// TODO: Implement this method
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

Fix the slice assignment inside the loop.

Line 30 assigns m.Employees = removeValue inside the loop, which means it gets executed on every iteration. This will corrupt the employee list and cause incorrect behavior.

Apply this diff to move the assignment outside the loop and simplify the logic:

 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
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (m *Manager) RemoveEmployee(id int) {
// TODO: Implement this method
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
}
}
func (m *Manager) RemoveEmployee(id int) {
var removeValue []Employee
for i := 0; i < len(m.Employees); i++ {
if m.Employees[i].ID == id {
continue
}
removeValue = append(removeValue, m.Employees[i])
}
m.Employees = removeValue
}
🤖 Prompt for AI Agents
In challenge-3/solution-template.go around lines 22 to 32, the code assigns
m.Employees = removeValue inside the loop which mutates the slice on every
iteration causing incorrect results; move the assignment so that m.Employees =
removeValue is executed only once after the loop completes and keep the loop
body to simply append non-matching employees to removeValue (remove the
else/continue complexity), ensuring the final filtered slice replaces
m.Employees after the loop.


// GetAverageSalary calculates the average salary of all employees.
func (m *Manager) GetAverageSalary() float64 {
// TODO: Implement this method
return 0
var aveSal float64
for i := 0; i < len(m.Employees); i++ {
aveSal += m.Employees[i].Salary
}
return aveSal / float64(len(m.Employees))
}
Comment on lines 35 to 41
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 | 🟠 Major

Add division by zero check.

If there are no employees, line 40 will panic due to division by zero.

Apply this diff to add a guard:

 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))
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (m *Manager) GetAverageSalary() float64 {
// TODO: Implement this method
return 0
var aveSal float64
for i := 0; i < len(m.Employees); i++ {
aveSal += m.Employees[i].Salary
}
return aveSal / float64(len(m.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))
}
🤖 Prompt for AI Agents
In challenge-3/solution-template.go around lines 35 to 41, the function
GetAverageSalary divides by float64(len(m.Employees)) and will panic when
len(m.Employees) == 0; add a guard at the start of the function that returns 0
(or another sensible default) when len(m.Employees) == 0 to avoid division by
zero, then proceed to sum salaries and divide by float64(len(m.Employees)).


// FindEmployeeByID finds and returns an employee by their ID.
func (m *Manager) FindEmployeeByID(id int) *Employee {
// TODO: Implement this method
for i := 0; i < len(m.Employees); i++ {
if m.Employees[i].ID == id {
return &m.Employees[i]
}
}
return nil
}
Comment on lines 44 to 51
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 | 🟠 Major

Avoid returning pointers to slice elements.

Line 47 returns &m.Employees[i], a pointer to a slice element. This pointer can become invalid if the slice is modified later (e.g., via RemoveEmployee or when the slice grows and reallocates). Consider returning a copy of the Employee value instead.

Apply this diff to return a copy:

-func (m *Manager) FindEmployeeByID(id int) *Employee {
+func (m *Manager) FindEmployeeByID(id int) (Employee, bool) {
 	for i := 0; i < len(m.Employees); i++ {
 		if m.Employees[i].ID == id {
-			return &m.Employees[i]
+			return m.Employees[i], true
 		}
 	}
-	return nil
+	return Employee{}, false
 }

Then update the caller in main:

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

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In challenge-3/solution-template.go around lines 44 to 51, the function
currently returns a pointer to a slice element (&m.Employees[i]) which can
become invalid if the slice is modified or reallocated; change the function to
return an Employee (a copy) instead of *Employee and return m.Employees[i] (the
value) when found; update the function signature and all call sites (e.g., in
main) to accept an Employee return value or a (Employee, bool) pattern for
not-found handling, and adjust callers to use the value semantics accordingly.


Expand Down
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)
}
}