def sqrt_enum(n) return to_enum(:sqrt_enum,n) unless block_given? list=[] while n>0 list << n%100 n/=100 end list.reverse carry=0 subcarry=0 while list[0]||carry!=0 n=(list.shift||0)+carry*100 a=(1..10).find{|i|(subcarry*10+i)*i>n}-1 yield a carry=n-(subcarry*10+a)*a subcarry=subcarry*10+a*2 end end x=gets.chomp.chars.map(&:to_i) p sqrt_enum(2).each_cons(3).find_index(x)