Last active
December 26, 2015 04:19
-
-
Save gpaulu/7092194 to your computer and use it in GitHub Desktop.
Reddit Daily Programmer [09/17/13] Challenge #138 [Easy] Repulsion-Force
http://www.reddit.com/r/dailyprogrammer/comments/1ml669/091713_challenge_138_easy_repulsionforce/
This file contains hidden or 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
data Particle = Particle { mass :: Float, xPos :: Float, yPos :: Float} | |
--probably silly | |
delta z a b = z a - z b | |
deltaX = delta xPos | |
deltaY = delta yPos | |
dist a b = sqrt (deltaX a b ** 2 + deltaY a b ** 2) | |
--note: this isn't the most efficient solution because we are calling sqrt and then squaring | |
force a b = mass a * mass b / dist a b ** 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment