Skip to content

Instantly share code, notes, and snippets.

@gerep
Last active December 27, 2015 12:09
Show Gist options
  • Save gerep/7323281 to your computer and use it in GitHub Desktop.
Save gerep/7323281 to your computer and use it in GitHub Desktop.
Arithmetic Progression
@n = 3
@sequence = '0 8 12'.split(' ').map(&:to_i).sort
def ratio
(@sequence[-1] - @sequence[0])/@n.to_i
end
def missing(n, sequence, diff)
numbers = []
n.times do |c|
numbers << sequence[0] + ((c+1) - 1)*diff
end
puts numbers - sequence
end
missing(@n, @sequence, ratio)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment