Created
March 14, 2016 02:17
-
-
Save nmenag/9ad62a9e2b85e4813470 to your computer and use it in GitHub Desktop.
verify arithmetic progression in ruby
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
| class Array | |
| <<-DOC | |
| 8, 3, -2, -7, -12, ... | |
| 3 - 8 = -5 | |
| -2 - 3 = -5 | |
| -7 - (-2) = -5 | |
| -12 - (-7) = -5 | |
| d = −5. | |
| FORMULA | |
| Interpolation of terms in an arithmetic progression: | |
| Interpolate differential or arithmetic means between two numbers, it is to build an arithmetic progression having at Extreme Numbers given . | |
| They are the ends A and B , and the number of media interpolating a m . | |
| d = b-a/m+1 | |
| DOC | |
| def arithmetic_progression? | |
| ((self.last - self.first) % (self.size-1)).zero? | |
| end | |
| end | |
| puts [1, 3, 5, 7, 9, 11, 13].arithmetic_progression? #true | |
| puts [1, 3, 5, 7, 9, 11, 12].arithmetic_progression? #false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment