title: Recursively generate non-overlapping schedule
body: <p>I'm working through some careercup.com questions and I'm stumped on <a href="https://www.careercup.com/question?id=5682055978418176" rel="nofollow noreferrer">this one</a> in trying to recursively implement it in Ruby.  Basically, the goal is to generate non-overlapping schedules given a set of hour long movies and their showtimes.</p>
  
  <pre><code>def recursive_scheduler(movies, schedule = {})
    movie, showtimes = movies.first
  
    showtimes.each do |showtime|
      if !schedule.has_key?(showtime)
        schedule[showtime] = movie
        if movies.length &gt; 1
          if recursive_scheduler((movies.reject { |m| m==movie }), schedule)
            return true
          end
        else
          puts "found schedule: #{schedule}"
          return true
        end
      end
    end
    return false
  end
  
  movies = { "The Shining" =&gt; [14, 15, 16],
             "Kill Bill"  =&gt; [14, 15],
             "Pulp Fiction" =&gt; [14, 15] }
  
  recursive_scheduler(movies)
  </code></pre>