Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

double the number

 
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This one is quick and interesting.
Natural number ends with 2.If we remove this 2 and place it at the beginning, the number gets doubled.Find the smallest possible original number.
(e.g. number is say 142. New number will be 214. 214 is not twice 142 so 142 is not such number).
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried all the possible way. This is the only number coming very nearer but not as per your expected result.
1052:2105.

I am suspecting whether that question has any answer.
 
Rancher
Posts: 3373
31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

palanisamy subramani wrote:I tried all the possible way.


Really? All of them?
 
Arjun Shastry
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the number.Its quite big.Let others try.
 
Ranch Hand
Posts: 41
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Arjun,

I tried out the problem and found the answer as:105263157894736842

Not sure whether it is the smallest one.....is it right...?

 
Arjun Shastry
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

anirudh jagithyala wrote:Hey Arjun,

I tried out the problem and found the answer as:105263157894736842

Not sure whether it is the smallest one.....is it right...?


i too found the same number but not sure its smallest one.Waiting for others.
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to wait... the title of this forum is Programming Diversions. While the question is certainly diverting, I haven't seen any programming yet.
 
lowercase baba
Posts: 12768
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:No need to wait... the title of this forum is Programming Diversions. While the question is certainly diverting, I haven't seen any programming yet.


Maybe you could interpret the title as 'diversions AWAY from programming', thus no programming required.
 
Mike Simmons
Rancher
Posts: 3373
31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This gives all solutions up to 100 digits:

The result is

The pattern is clear.

Obviously, what I was solving for was all the digits other than the 2, which moves.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to say, this is impressive!
I have reached the same code:

x = ( 2*(10^n) - 4 ) / 19

And it was a pleasure getting here!

Cheers, Eugene
 
Sheriff
Posts: 3034
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eugene Rabii wrote:I have to say, this is impressive!
I have reached the same code:

x = ( 2*(10^n) - 4 ) / 19

And it was a pleasure getting here!

Cheers, Eugene



-4? -2 surely?

My thinking runs this way:

2 * (10^n) + (x-2)/10 = 2x
2 * (10^(n+1)) + x - 2 = 20x
2 * (10^(n+1)) - 2 = 19x
x = (2 * (10^(n+1)) - 2 ) / 19

So, we just look for a value of n that makes x an integer ending with 2. The n vs (n+1) doesn't matter, but the -4 vs -2 will produce different answers.

OK, code time:


Results:

2, 10, 8
3, 105, 3
4, 1052, 10
5, 10526, 4
6, 105263, 1
7, 1052631, 9
8, 10526315, 13
9, 105263157, 15
10, 1052631578, 16
11, 10526315789, 7
12, 105263157894, 12
13, 1052631578947, 5
14, 10526315789473, 11
15, 105263157894736, 14
16, 1052631578947368, 6
17, 10526315789473684, 2
18, 105263157894736842, 0

So the answer is 105263157894736842. The check for the last digit being 2 turned out to be unnecessary, but I think that's a coincidence.

ETA: In reading through Mike's solution, I see the -4 makes sense if you declare x to be the number without the final 2. Sorry about that!

I wonder if we can prove we don't have to check the final digit, as both Mike and I discovered?


 
Mike Simmons
Rancher
Posts: 3373
31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eugene is quoting the same formula I used above. And we got the same answer - except that as I noted above, my 'x' represented all the digits other than the 2. So I got

10526315789473684

and you got

105263157894736842
 
Greenhorn
Posts: 28
1
Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried some thing very simple and may sound very stupid....


BigInteger i,a,b;
for(i=0;i<100000000000000;i++)
{
String x,y;
String num = Integer.toString(i);
x = num+"2";
y = "2"+num;
int a = Integer.parseInt(x);
int b = Integer.parseInt(y);

if(a==(b/2))
System.out.println(a+" "+b);
}

did not get any no...though....

 
Mike Simmons
Rancher
Posts: 3373
31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rohini Sahuji wrote:did not get any no...though....


It's possible this is caused by the fact that your code does not compile. That's just a guess though.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!