Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created September 17, 2012 15:57
Show Gist options
  • Save arn-e/3738169 to your computer and use it in GitHub Desktop.
Save arn-e/3738169 to your computer and use it in GitHub Desktop.
solve_combinations
class SpeedDialPermutations
def average_time(set,iterations,perm,target = get_combinations(set).sample)
avg_arr = []
for i in 0..iterations
avg_arr.push get_combinations(set).shuffle.index(target)
end
return ((avg_arr.inject(:+).to_f / avg_arr.size)*4)/60
end
def get_combinations(set, perm = 4)
results = set.repeated_permutation(perm).to_a
end
def simulate(set,delay,perm,target = get_combinations(set).sample)
set,start,att = get_combinations(set).shuffle, Time.now,1
set.each do |i|
return "Attempt #{att} Successful : #{i} : Elapsed : #{Time.now - start}" if i == target
puts "Attempt #{att} Unsuccessful : #{i} : Elapsed time : #{Time.now - start}"
att += 1
sleep delay
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment