Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- def get_array number, recurring
- (1..number-recurring).map {|i| [i, i]} + (number-recurring..number).map {|i| [i, i-recurring]}
- end
- def simons array
- hash = array.reduce({}) {|hash, pair| (hash[pair.last] ||= []).push pair.first; hash}
- hash.keys.combination(16).each do |array|
- arrays = array.map {|parent| hash[parent]}
- arrays.first.product(*arrays.drop(1)).each {|a| yield a}
- end
- end
- size = 0
- puts Benchmark.measure do
- simons(get_array(33, 1)) do |x|
- size += 1 # or do something more interesting
- end
- end
- p size
Add Comment
Please, Sign In to add comment