Solution to yesterday's problem:
45818999 x 2 -------- 91637998
and the corresponding ruby code:
i = 10000000
while(i < 50000000)
i_str = i.to_s
product = (i*2).to_s
ight = [product[1].chr, product[2].chr, product[3].chr, product[4].chr]
if( (i_str[2].chr == i_str[4].chr) and
(i_str[2].chr != "9") and
(i_str[3].chr == product[1].chr) and
(i_str[2].chr == product[-1].chr) and
(product[0].chr == product[-2].chr) and
(product[0].chr == product[-3].chr) and
(i_str[-3].chr == product[-2].chr) and
(ight.uniq.length == ight.length) and
(ight & [product[-1].chr]).empty?
)
p [i, product.to_i]
end
i += 1
end
The logic is pretty much straight forward.