Sunday, April 28, 2024
HomeSoftware EngineeringHow you can Discover the Sum of Angles in Golang

How you can Discover the Sum of Angles in Golang


The problem

Discover the overall sum of inner angles (in levels) in an n-sided easy polygon.

N might be larger than 2.

The answer in Golang

Choice 1:

bundle resolution
func Angle(n int) int {
    return (n - 2) * 180
}

Choice 2:

bundle resolution
func Angle(n int) (r int) {
    r = (n-2)*180
    return
}

Choice 3:

bundle resolution
func Angle(n int) int {
    return (n/2-1) * 360 + npercent2 * 180
}

Take a look at instances to validate our resolution

bundle solution_test
import (
  . "github.com/onsi/ginkgo"
  . "github.com/onsi/gomega"
)
var _ = Describe("Fundamental checks", func() {
    It("Angle(3)", func() { Count on(Angle(3)).To(Equal(180)) })
    It("Angle(4)", func() { Count on(Angle(4)).To(Equal(360)) })
})
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments