Last active
September 20, 2016 05:03
-
-
Save MaxPleaner/f5bef9a76ab77f29562917fb814f3989 to your computer and use it in GitHub Desktop.
priority merge example 7 (out of order)
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
a1 = 50.times.map { 1 } | |
a2 = 50.times.map { 2 } | |
puts "when priority is 1.0" | |
result = 50.times.map do | |
result = a1.priority_merge(1.0, a2) | |
result.select { |item| item == 2 }.count.to_f / a1.length.to_f | |
end | |
puts "results contain on average #{result.mean}% elements from the merged array" | |
# => will be around 50% | |
puts "when priority is 0.5" | |
result = 50.times.map do | |
result = a1.priority_merge(0.5, a2) | |
result.select { |item| item == 2 }.count.to_f / a1.length.to_f | |
end | |
puts "results contain on average #{result.mean}% elements from the merged array" | |
puts result.mean | |
# => will be around 25% | |
puts "when priority is 0" | |
result = 50.times.map do | |
result = a1.priority_merge(0.0, a2) | |
result.select { |item| item == 2 }.count / a1.length.to_f | |
end | |
puts "results contain on average #{result.mean}% elements from the merged array" | |
# => will be zero |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment