Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e61a27f

Browse files
author
Leo Silva Souza
committed
03/2 - Ruby
1 parent 74c601d commit e61a27f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2018/03_2/ruby/leovano.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
begin
4+
input = File.readlines(ARGV[0])
5+
6+
claims = Hash.new 0
7+
8+
input.map! do |claim|
9+
claim.split(/[#@,:x]/)
10+
.reject(&:empty?)
11+
.map(&:to_i)
12+
end
13+
14+
input.each do |claim|
15+
(claim[1]...claim[1] + claim[3]).each do |x|
16+
(claim[2]...claim[2] + claim[4]).each do |y|
17+
claims[[x, y]] += 1
18+
end
19+
end
20+
end
21+
22+
overlap = lambda do |claim|
23+
(claim[1]...claim[1] + claim[3]).each do |x|
24+
(claim[2]...claim[2] + claim[4]).each do |y|
25+
return false if claims[[x, y]] != 1
26+
end
27+
end
28+
true
29+
end
30+
31+
puts input.find(&overlap)[0]
32+
rescue TypeError
33+
STDERR.puts 'Arg1'
34+
rescue StandardError => e
35+
STDERR.puts e
36+
end

0 commit comments

Comments
 (0)