Created
August 17, 2020 12:55
-
-
Save mrryanjohnston/919bbbcca5c1674d5243337d2cfd1e5d to your computer and use it in GitHub Desktop.
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
require 'durable' | |
Durable.ruleset :circle do | |
when_all( | |
c.point = (+m.x) & (+m.y), | |
c.circle = m.radius_squared == ( point.x * point.x ) + ( point.y * point.y ) | |
) do | |
puts "point (#{point.x}, #{point.y}) " \ | |
"is on the edge of circle #{circle.name}" | |
end | |
when_all( | |
c.point = (+m.x) & (+m.y), | |
c.circle = m.radius_squared < ( point.x * point.x ) + ( point.y * point.y ) | |
) do | |
puts "point (#{point.x}, #{point.y}) " \ | |
"is outside of circle #{circle.name}" | |
end | |
when_all( | |
c.point = (+m.x) & (+m.y), | |
c.circle = m.radius_squared > ( point.x * point.x ) + ( point.y * point.y ) | |
) do | |
puts "point (#{point.x}, #{point.y}) " \ | |
"is inside of circle #{circle.name}" | |
end | |
end | |
Durable.assert :circle, {name: :a, radius_squared: 25, x: 0, y: 0} | |
Durable.assert :circle, {x: 0, y: 0} | |
Durable.assert :circle, {x: 1, y: 1} | |
Durable.assert :circle, {x: -1, y: -1} | |
Durable.assert :circle, {x: 5, y: -5} | |
Durable.assert :circle, {x: 5, y: 0} | |
Durable.assert :circle, {x: 0, y: 5} | |
Durable.assert :circle, {x: 2, y: 2} | |
Durable.assert :circle, {x: 3, y: 3} |
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
$ ruby index.rb | |
point (0, 0) is inside of circle a | |
point (1, 1) is inside of circle a | |
point (-1, -1) is inside of circle a | |
point (5, -5) is outside of circle a | |
point (5, 0) is on the edge of circle a | |
point (0, 5) is on the edge of circle a | |
point (2, 2) is inside of circle a | |
point (3, 3) is inside of circle a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment