Created
September 19, 2013 09:31
-
-
Save go-ive/6621165 to your computer and use it in GitHub Desktop.
Reddit DailyProgrammer Challenge #138 Repulsion Force
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"math" | |
"os" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
reader := bufio.NewReader(os.Stdin) | |
p1info, _ := reader.ReadString('\n') | |
p2info, _ := reader.ReadString('\n') | |
p1 := strings.Fields(p1info) | |
p2 := strings.Fields(p2info) | |
p1M, _ := strconv.ParseFloat(p1[0], 64) | |
p1X, _ := strconv.ParseFloat(p1[1], 64) | |
p1Y, _ := strconv.ParseFloat(p1[2], 64) | |
p2M, _ := strconv.ParseFloat(p2[0], 64) | |
p2X, _ := strconv.ParseFloat(p2[1], 64) | |
p2Y, _ := strconv.ParseFloat(p2[2], 64) | |
dx := p1X - p2X | |
dy := p1Y - p2Y | |
distance := math.Sqrt(dx*dx + dy*dy) | |
force := p1M * p2M / (distance * distance) | |
fmt.Printf("%.4f\n", force) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment