Skip to content

Instantly share code, notes, and snippets.

@macabreb0b
Last active August 29, 2015 14:09
Show Gist options
  • Save macabreb0b/f90d5f38a4fdf4c75d5b to your computer and use it in GitHub Desktop.
Save macabreb0b/f90d5f38a4fdf4c75d5b to your computer and use it in GitHub Desktop.
# for all numbers between 1 and a number,
# which can you add to the number infinitely
# (wrapping around when you hit the number)
# such that every number is stopped at once
def check_intervals(num)
best_intervals = []
current_max = 0
1.upto(num).each do |interval|
picked_already = [0]
next_color = interval
until picked_already.include?(next_color)
picked_already << next_color
next_color += interval
next_color = next_color % 255
end
num_colors = picked_already.length
if num_colors > current_max
best_intervals = [[interval, num_colors]]
current_max = num_colors
elsif num_colors == current_max
best_intervals << [interval, num_colors]
end
end
best_intervals
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment