refactor: make not ugly

This commit is contained in:
Stevan Freeborn
2025-12-11 10:33:58 -06:00
parent 9b53e28a19
commit e931b515a2
3 changed files with 70 additions and 60 deletions
+37
View File
@@ -0,0 +1,37 @@
// Package problem provides models and methods for representing a problem.
package problem
type Problem interface {
Solve() int
}
type problem struct {
operator string
operands []int
}
func From(operator string, operands []int) Problem {
return problem{
operator: operator,
operands: operands,
}
}
func (p problem) Solve() int {
result := 0
switch p.operator {
case "+":
for _, operand := range p.operands {
result += operand
}
case "*":
result = 1
for _, operand := range p.operands {
result *= operand
}
}
return result
}