forked from GolangUnited/golang-united-school-homework-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.go
32 lines (26 loc) · 758 Bytes
/
solution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package square
import "math"
// 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)
type Figurine int
const (
SidesCircle = 0
SidesTriangle = 3
SidesSquare = 4
)
func CalcSquare(sideLen float64, sidesNum Figurine) float64 {
switch sidesNum {
case SidesCircle:
return math.Pow(sideLen, 2) * math.Pi
case SidesTriangle:
return (math.Sqrt(3) / 4) * math.Pow(sideLen, 2)
case SidesSquare:
return math.Pow(sideLen, 2)
default:
return 0
}
}