def calc(input) original = ("a".."z").to_a a = original.difference(input.chars).first b = input.chars.select { |it| input.chars.count(it) > 1 }.first "#{a}to#{b}" end def calc2(input) input.chars.zip(("a".."z")).select { |a, b| a != b }.first.then { |a, b| "#{b}to#{a}" } end # input = "abcdefghijklmnnpqrstuvwxyz" input = gets # puts calc(input) puts calc2(input)