Skip to content
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

Good luck #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module somename

go 1.17
29 changes: 22 additions & 7 deletions solution.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package square

// Define custom int type to hold sides number and update CalcSquare signature by replacing #yourTypeNameHere#

// Define constants to represent 0, 3 and 4 sides. Test uses mnemos: SidesTriangle(==3), SidesSquare(==4), SidesCircle(==0)
// it's like:
// CalcSquare(10.0, SidesTriangle)
// CalcSquare(10.0, SidesSquare)
// CalcSquare(10.0, SidesCircle)
import (
"math"
)

func CalcSquare(sideLen float64, sidesNum #yourTypeNameHere#) float64 {
type SidesNumber int

const (
SidesCircle SidesNumber = 0
SidesTriangle SidesNumber = 3
SidesSquare SidesNumber = 4
)

func CalcSquare(sideLen float64, sidesNum SidesNumber) float64 {
switch sidesNum {
case SidesTriangle:
return (sideLen * sideLen * math.Sqrt(3) / 4)
case SidesSquare:
return (sideLen * sideLen)
case SidesCircle:
return (math.Pi * sideLen * sideLen)
default:
return (0)
}
}