My first time writing in Golang, managed to figure out the basic syntax.
package main func gcd(a int, b int) int { if b == 0 { return a } return gcd(b, a%b) } func properFractions(denom int) int { results := 0 for i := 1; i < denom; i++ { if gcd(denom, i) == 1 { results++ } } return results } func main() { }
For testing
package main import "testing" func TestProperFractions(t *testing.T) { params := map[int]int{ 1: 0, 2: 1, 5: 4, 15: 8, 25: 20, } for key, value := range params { result := properFractions(key) if result != value { t.Errorf("Incorrect answer for %d, expected: %d, got: %d", key, value, result) } } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My first time writing in Golang, managed to figure out the basic syntax.
For testing