Created
April 30, 2014 18:30
-
-
Save potomak/d8408c7583b5cc02b31c to your computer and use it in GitHub Desktop.
Rainforest QA
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
-- accounts | |
-- ======== | |
-- id | |
-- | |
-- pricing_plans | |
-- =========== | |
-- id | |
-- price_in_cents | |
-- | |
-- account_pricing_plans | |
-- ================== | |
-- id | |
-- account_id | |
-- pricing_plan_id | |
-- start_time | |
-- end_time | |
SELECT accounts.id | |
FROM accounts | |
JOIN account_pricing_plans ON accounts.id = account_pricing_plans.account_id | |
JOIN pricing_plans ON pricing_plans.id = account_pricing_plans.pricing_plan_id | |
WHERE pricing_plans.price_in_cents = 100; |
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
def unique_pairs(array) | |
output = [] | |
array = array.uniq | |
array.each_with_index do |n, i| | |
array.each_with_index do |m, j| | |
if i != j && n + m == 100 | |
result = [] | |
result[0] = [n, m].min | |
result[1] = [n, m].max | |
output << result | |
end | |
end | |
end | |
output.uniq | |
end | |
#> input = [1, 27, 50, 49, 51, 99, 51, 51] | |
#> unique_pairs(input) | |
# => [[1, 99], [49, 51]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment