Last active
December 5, 2016 09:56
-
-
Save eltonsantos/27d1a3a98a443ccc2130eedd56108265 to your computer and use it in GitHub Desktop.
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
def pares(a, k) | |
count = 0 | |
a.combination(2).each{ |par| count += 1 if ((par[0] - par[1] == k) or (par[1] - par[0] == k)) } | |
count | |
end | |
puts "Digite o primeiro valor para N e o segundo valor para K, separados por espaço: (Exemplo: 5 3)" | |
a = gets.strip.split(" ").map! { |i| i.to_i } | |
k = a[1] | |
puts "Digite os valores de N começando por 1, separados por espaço: (Exemplo: 1 2 3 4 5)" | |
b = gets.strip.split(" ").map! { |i| i.to_i } | |
puts pares(b, k) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment