blob: 5fa5f4e233be18ef76c93a547978c8b2ecdcc8bb (
plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/usr/bin/env ruby
@letters = {}
data = File.read("data.txt")
data = data.split("\n")
data = data.map(&:chars)
data.each_with_index do |row, y|
row.each_with_index do |letter, x|
@letters[[x,y]] = letter
end
end
found = 0
potential_starts = @letters.select{|key, val| val == "A" }
potential_starts.each do |key, value|
score = 0
if @letters[[key[0] - 1, key[1] - 1]] == "M" && @letters[[key[0] + 1, key[1] + 1]] == "S"
score = score + 1
end
if @letters[[key[0] - 1, key[1] - 1]] == "S" && @letters[[key[0] + 1, key[1] + 1]] == "M"
score = score + 1
end
if @letters[[key[0] + 1, key[1] - 1]] == "M" && @letters[[key[0] - 1, key[1] + 1]] == "S"
score = score + 1
end
if @letters[[key[0] + 1, key[1] - 1]] == "S" && @letters[[key[0] - 1, key[1] + 1]] == "M"
score = score + 1
end
found += 1 if score >= 2
end
p found
|