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.
Well... I didn't like the solution.
Too much of brute force. :(
Posted by: sandeep | August 12, 2008 at 06:42 AM
Do you really have that many spams .. to keep this word-verification? -- it's irritating.
Posted by: sandeep | August 12, 2008 at 06:43 AM
Infact variable `i' can be started at 40000000 instead of 10000000.
Solution is brute force partially, since some of the conditions that I check is based on initial round of elimination. But which takes more time, this program or doing it manually. You got the solution to the problem, what else do you want.
Let me see if I can remove that verification or at least make it simple.
Posted by: Hiran Ramankutty | August 12, 2008 at 07:44 AM
Well.. the thing is I would like a soution which says like - a, b, c, d, e, f are the values which would suit for N -- and if N is 'a', the values of E can be g, h, or k.
Here a - h being digits [0-9]
That would be a heuristic which would have some back tracking and real AI kind of stuff. :) [some heuristic + tree + back-tracking]
I am not complaining... I got the solution from you and I appreciate it.
Also, I am just sitting here and suggesting stuff.. instead of solving it. Enneyokke kettiyittu adikkanam ;)
Posted by: sandeep | August 14, 2008 at 12:17 PM