From 7267986bf52d7fa8a8a426ce5b1122d903cc4da9 Mon Sep 17 00:00:00 2001 From: mms Date: Wed, 4 Dec 2024 11:58:10 +0100 Subject: feat: 2024@4a+b= --- 2024/04b/run.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 2024/04b/run.rb (limited to '2024/04b/run.rb') 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 -- cgit v1.2.3