-
Notifications
You must be signed in to change notification settings - Fork 0
/
78.rb
26 lines (21 loc) · 985 Bytes
/
78.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
File.open('78.txt').each_line do |line|
size_of_square = line.split(";")[0].to_i
number_in_square = line.split(';')[1].split(',').map(&:to_i)
first_check = number_in_square.each_slice(size_of_square).map{|a| a}
second_check = number_in_square.group_by.each_with_index {|item, index| index % size_of_square }
thirt_check = number_in_square.each_slice(size_of_square).
map{|a| a.each_slice(Math.sqrt(size_of_square)).map{|chunk| chunk}}.
transpose.flatten.each_slice(size_of_square).map{|a| a}
checklist = []
0.upto size_of_square - 1 do |i|
checklist.push((first_check[i].sort == (1..size_of_square).to_a),
(second_check[i].sort == (1..size_of_square).to_a),
(thirt_check[i].sort == (1..size_of_square).to_a))
end
if checklist.include?(false)
puts "False"
else
puts "True"
end
puts second_check
end