Skip to content

Instantly share code, notes, and snippets.

@gpaulu
Last active December 26, 2015 04:19
Show Gist options
  • Save gpaulu/7092194 to your computer and use it in GitHub Desktop.
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/
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