def tobase(n, base) arr = [] while n > 0 arr << n % base n /= base end arr end $<.map(&:to_i).each do |n| b = 15 while true r = tobase(n, b) if r.count(14)>1 && r.count(11)>0 && r.each_cons(3).any? { |s| s == [14, 14, 11]} puts b break end b+=1 end end

Note that non-ascii characters in the above source code will be escaped (such as \x9f).