2
$\begingroup$

A 4-digit number for example 1234 when circular shifted by 1 digit to for example 4123 should be 4 times higher than the initial number.

I tried this code in MATLAB:

for i = 1000:1:9999
    first = i;
    second = str2double(circshift(num2str(first)',1)');
    if (second/first) == 4
        break;
    end
end

But the value I get firstnumber is 9999. Is there any better method to find the number? Need some guidance..

$\endgroup$

2 Answers 2

1
$\begingroup$

You get firstnumber equal to $9999$ because there is no $4$-digit number that will satisfy your condition. The python code below would print such a number if there was one.

for i in range(1000, 10000):
    s = str(i)
    shift = int(s[-1] + s[:-1])
    if shift * 1.0 / i == 4:
        print i
        print shift
        break
$\endgroup$
1
$\begingroup$

You are seeking 2 numbers $x$ and $y$ such that: $1\leq y\leq 9$, $100\leq x\leq 999$ and $$ (y\times 1000+x)=4(10x+y)\implies 996y=39x. $$ But $39x$ is divisible by $13$ whereas $996y$ cannot be. So there are so such $x$ and $y$. That's why your loop runs into its final value ($9999$).

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .