Created
October 8, 2019 18:24
-
-
Save Prigin/4e5c8795a929ea40899e05b01885c8d7 to your computer and use it in GitHub Desktop.
repeating bad
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
mas = [] | |
doc = "movies.txt" | |
syms = [:link, :title, :year, :country, | |
:date, :genre, :duration, | |
:rating, :director, :stars] | |
buff = {} | |
i = 0 | |
File.foreach(doc) do |line| | |
line.chomp! | |
line = line.split("|") | |
line.each do |info| | |
buff.merge!({syms[i] => info}) | |
i += 1 | |
end | |
mas.append(buff) | |
buff = {} | |
i = 0 | |
end | |
def DateCompare(unit_1, unit_2) | |
unit_1 = unit_1.split("-").join | |
unit_1 = unit_1 + "0" * (8 - unit_1.size) if unit_1.size < 8 | |
unit_2 = unit_2.split("-").join | |
unit_2 = unit_2 + "0" * (8 - unit_2.size) if unit_2.size < 8 | |
return true if unit_1.to_i > unit_2.to_i | |
return false | |
end | |
def DurationCompare(unit_1, unit_2) | |
unit_1 = unit_1.split(" ") | |
unit_2 = unit_2.split(" ") | |
return true if unit_1[0].to_i > unit_2[0].to_i | |
return false | |
end | |
buff = Array.new(5, nil) | |
mas.each do |comp| | |
buff.each_index do |n| | |
if buff[n] == nil | |
buff[n] = comp | |
break | |
elsif DurationCompare(comp[:duration],buff[n][:duration]) | |
buff.insert(n, comp) | |
buff.pop | |
break | |
end | |
end | |
end | |
buff.each{|unit| print unit[:title] + " "; puts unit[:duration]} | |
puts"**************************************" | |
buff = Array.new(10, nil) | |
mas.each do |comp| | |
buff.each_index do |n| | |
if buff[n] == nil and comp[:genre].include?("Comedy") | |
buff[n] = comp | |
break | |
elsif comp[:genre].include?("Comedy") and DateCompare(buff[n][:date], comp[:date]) | |
buff.insert(n, comp) | |
buff.pop | |
break | |
end | |
end | |
end | |
buff.each{|unit| print unit[:title] + " "; puts unit[:genre]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment