A little contest about logic & programming

  • 9
Problem:
find an integer that multiplied by 4 gives a number that has the same digits, but with opposite order compared to the original number.
Example with n digits:
X1X2...Xn-1Xn  *  4  =  XnXn-1...X2X1
where X1 is the  first digit, X2 the second digit....Xn the n-th digit.
Pay attention: we don't know how many digits compose the number.
If you have the solution, post it in the comment.

The next step is to write a simple algorithm that would be able to find the solution by itself. I'm trying to do it using the C++...or maybe I should just go out. 
Definitely, I need to go out.
Bye.

9 comments:

  1. Here we are with a couple of solutions.
    In the first solution, the dumb one, I simply check if property you gave in the statement is verified: is x1x2..xn * 4 equal to xn..x2x1? http://ideone.com/HlTZQ
    It works, slowly but it works.
    However we can study the output in order to devise a clever algorithm which produces this fastest solution: http://ideone.com/yUh2R

    Regards,
    Matteo

    ReplyDelete
  2. @Matteo
    Of course the solution is right and as i have always said....you're fucking brilliant!

    ReplyDelete
  3. Surely it is not the best solution, but it works.
    http://ideone.com/CUpP6

    ReplyDelete
  4. @kinglizad
    Oh you're a clever little bastard too...in a good way :)
    See guys what great Python minds!

    ReplyDelete
  5. You are very STRINATI

    ReplyDelete
  6. and for information i have solved without cpu, only with my mind prrrrrr

    ReplyDelete
  7. @Silvio
    Gnè gnè gnè...envious!

    ReplyDelete
  8. @Silvio:
    You're #1: pencil and sheet of paper is the way!

    Matteo

    ReplyDelete