class RotationDecoder def initialize(file_path) @file_path = file_path @mapping = { 'L' => :-, 'R' => :+ } end def decode(debug: false) code = 0 current_num = 50 puts "The dial starts by pointing at #{current_num}" if debug File.readlines(@file_path, chomp: true).map do |line| next if line.nil? || line.empty? direction, *number_arr = line.split('') number = Integer(number_arr.join) current_num = current_num.send(@mapping[direction], number) % 100 code += 1 if current_num == 0 puts "The dial is rotaded #{line} to point at #{current_num}" if debug end code end end rd = RotationDecoder.new('input.txt') puts "The code is: #{rd.decode}"