Last active
March 7, 2018 02:16
-
-
Save selfup/3dc051b6165888a2ed856bc723e420ce to your computer and use it in GitHub Desktop.
diffing_algos
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
big_arr = (0..900_000).to_a | |
sm_arr = (0..700_000).to_a | |
def diff(big, sm) | |
(big - sm) | |
end | |
def similarities(big, sm) | |
(big & sm) | |
end | |
File.open('./diff.csv', 'w') do |f| | |
results = diff(big_arr, sm_arr) | |
f.write(results.join(",\n")) | |
end | |
File.open('./similarities.csv', 'w') do |f| | |
results = similarities(big_arr, sm_arr) | |
f.write(results.join(",\n")) | |
end |
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 group_by_existance(big, sm) | |
big.group_by do |e| | |
sm.include?(e) | |
end | |
end | |
big_arr = (0..9_000).to_a | |
sm_arr = (0..7_000).to_a | |
result = group_by_existance(big_arr, sm_arr) | |
File.open('./results.csv', 'w') do |f| | |
f.write(result[false].join(",\n")) | |
end |
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
const fs = require('fs'); | |
const bg = createArr(9000); | |
const sm = createArr(7000); | |
function createArr(length) { | |
return Array.from({ length }, (_, i) => i); | |
} | |
function groupByExistance(ba, sa) { | |
const group = { | |
[false]: [], | |
[true]: [], | |
}; | |
ba.forEach((e) => { | |
group[sm.includes(e)].push(e); | |
}); | |
return group; | |
} | |
const result = groupByExistance(bg, sm); | |
const csv = result[false].join(',\n'); | |
fs.writeFileSync('jsresults.csv', csv, 'utf-8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment