Created
February 3, 2017 16:35
-
-
Save thegreyfellow/4cf7bc78ffb5b3ee181dd37488c8f438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
puts '****************************************' | |
availability = (8..12) | |
puts "looking for availability in this interval:\n #{availability}" | |
puts '****************************************' | |
rb1 = (6..9) | |
puts rb1 | |
rb2 = (10..11) | |
puts rb2 | |
rb3 = (12..14) | |
puts rb3 | |
puts '****************************************' | |
bookings = [rb1, rb2, rb3] | |
av = [] | |
bookings.each do |b| | |
if availability.include?(b.first) | |
if availability.first != b.first && availability.last != b.last | |
av << (availability.first..b.first) | |
availability = (b.last..availability.last) | |
next | |
elsif availability.first == b.first && availability.last != b.last | |
availability = (b.last..availability.last) | |
next | |
elsif availability.first != b.first && availability.last == b.last | |
av << (availability.first..b.first) | |
availability = (b.last..availability.last) | |
next | |
else | |
break | |
end | |
elsif availability.include?(b.last) | |
availability = (b.last..availability.last) | |
next | |
end | |
end | |
av << (bookings.last.last..availability.last) if bookings.last.last < availability.last | |
puts "Room available only in these houres:\n #{av.inspect}" | |
puts '****************************************' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment