f = -> n { (0..n).lazy.map {|i| [n - i, n + i].select {|x| x.to_s.reverse.to_i == x}}.find(&:any?).uniq}p [0, 17, 100].map {|n| [n, f.(n)]}
Standard input is empty
[[0, [0]], [17, [22]], [100, [99, 101]]]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!