diff options
Diffstat (limited to '2024/04b/run.rb')
-rwxr-xr-x | 2024/04b/run.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/2024/04b/run.rb b/2024/04b/run.rb new file mode 100755 index 0000000..5fa5f4e --- /dev/null +++ b/2024/04b/run.rb @@ -0,0 +1,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 |