Skip to content

Instantly share code, notes, and snippets.

@ChristianSiegert
Created June 16, 2012 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristianSiegert/2942682 to your computer and use it in GitHub Desktop.
Save ChristianSiegert/2942682 to your computer and use it in GitHub Desktop.
Solution written in Go for challenge 2012-03-16 on ProgrammingPraxis.com
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)
}
@ChristianSiegert
Copy link
Author

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