Skip to content

Instantly share code, notes, and snippets.

@potomak
Created April 30, 2014 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potomak/d8408c7583b5cc02b31c to your computer and use it in GitHub Desktop.
Save potomak/d8408c7583b5cc02b31c to your computer and use it in GitHub Desktop.
Rainforest QA
-- accounts
-- ========
-- id
-- email
--
-- 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;
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