diff options
Diffstat (limited to '2024/02a/run.rb')
-rwxr-xr-x | 2024/02a/run.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/2024/02a/run.rb b/2024/02a/run.rb new file mode 100755 index 0000000..2ba1060 --- /dev/null +++ b/2024/02a/run.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby + +data = File.read("data.txt") + +data = data.split("\n") +data = data.map(&:split) + +safe_arr = data.map do |row| + directions = [] + + row.each_with_index do |value, index| + next if index.zero? + distance = (value.to_i - row[index-1].to_i) + direction = if (distance.abs > 3 ) + :err + elsif distance > 0 + :up + elsif distance < 0 + :down + else + :err + end + + directions << direction + end + + directions.uniq.count == 1 ? 1 : 0 + + +end + +p safe_arr.sum |