Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Solution written in Go for challenge 2012-03-16 on ProgrammingPraxis.com

View challenge-2012-03-16.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
package main
 
import (
"fmt"
"math"
)
 
func main() {
fmt.Println("Exercise from: http://programmingpraxis.com/2012/03/16/sum-of-squares-of-two-largest-of-three-values/")
fmt.Println("Exercise: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.")
fmt.Println("sum_of_squares_of_largest_two_numbers(2, 3, 1):", sum_of_squares_of_largest_two_numbers(2, 3, 1))
}
 
func sum_of_squares_of_largest_two_numbers(a, b, c float64) float64 {
return math.Pow(math.Max(a, b), 2) + math.Pow(math.Max(math.Min(a, b), c), 2)
}

Console output:

$ go run challenge-2012-03-16.go 
Exercise from: http://programmingpraxis.com/2012/03/16/sum-of-squares-of-two-largest-of-three-values/
Exercise: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
sum_of_squares_of_largest_two_numbers(2, 3, 1): 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.