def get_best_ranges(total_length, region_length):
  """
  Get the first packing that is valid.
  """
  max_num = 1000 # this should be enough for anyone ...
  num = 1
  while True:
    ranges = get_ranges(total_length, region_length, num)
    if check_ranges(total_length, ranges):
      return ranges
    else:
      if num > max_num:
        return None
    num = num + 1
  return None

  Get the first packing that is valid.
  
cnn_vis.py