From f4b1c9ac1e16498a54c276640d08cb5ee4b3e817 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 24 Dec 2024 01:09:59 -0500 Subject: [PATCH] Part 2 that will never finish --- 21/main.rb | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/21/main.rb b/21/main.rb index 180f49e..dd1a4bb 100755 --- a/21/main.rb +++ b/21/main.rb @@ -281,25 +281,34 @@ directional_map = { [">", "v"]=>["<"] } -robot_1 = input -robot_2 = robot_1 +@robot_1 = input +@robot_2 = @robot_1 .map { ["A"] + _1 } .map { _1.each_cons(2).to_a } .map { _1.map { |move| numeric_map[move].first }.join("A") } .map { _1 + "A" } -robot_3 = robot_2 - .map { _1.chars } - .map { ["A"] + _1 } - .map { _1.each_cons(2).to_a } - .map do - _1.map do |move| - directional_map[move].nil? ? "" : directional_map[move].first - end.join("A") - end - .map { _1 + "A" } +(3..25).each do |num| + puts "Robot #{num}" + prev_robot = instance_variable_get(:"@robot_#{num - 1}") -me = robot_3 + robot = prev_robot + .map { _1.chars } + .map { ["A"] + _1 } + .map { _1.each_cons(2).to_a } + .map do + _1.map do |move| + directional_map[move].nil? ? "" : directional_map[move].first + end.join("A") + end + .map { _1 + "A" } + instance_variable_set(:"@robot_#{num}", robot) + + @last_num = num +end + +last_robot = instance_variable_get(:"@robot_#{@last_num}") +me = last_robot .map { _1.chars } .map { ["A"] + _1 } .map { _1.each_cons(2).to_a } @@ -315,12 +324,6 @@ me.each_with_index do |entry, i| end p me.map.with_index { |entry, i| entry.length * input[i].join.to_i }.sum -puts me.first -puts robot_3.first -puts robot_2.first -puts robot_1.first.join - - __END__ 029A 980A