clearing = %w[a b c d e f 1 g h i j 1 k 2 l 2 2 m n o p q r s 1 t u v w x 1 y z].map do |ele| Integer(ele) rescue ele end expected = %w[a b c d e f l m n o p q r s] clearing << 2 iters = 0 while clearing.include? 1 from = clearing.index(1) to = clearing[from..-1].index(2) + from clearing.slice!(from..to) end clearing.delete(2) p clearing p expected puts "Matches!" if clearing == expected
Standard input is empty
["a", "b", "c", "d", "e", "f", "l", "m", "n", "o", "p", "q", "r", "s"] ["a", "b", "c", "d", "e", "f", "l", "m", "n", "o", "p", "q", "r", "s"] Matches!