January 23rd, 2018, 02:56 PM  #11  
Newbie Joined: Jan 2018 From: somewhere Posts: 14 Thanks: 2 Math Focus: Algebraic Number Theory / Differential Fork Theory  Quote:
 
January 23rd, 2018, 11:42 PM  #12 
Senior Member Joined: Apr 2014 From: UK Posts: 898 Thanks: 329 
Yeah, you're right, I don't think I'm the only one who somehow missed that! You'd have to keep dividing by 10 until you get the last (first) digit then multiply that digit by 10^n where n is the number of divide by 10 you did to get the digit. Clearly, the original x/(x/10) always gives 10. So, in the original example 685757: int(685757/10/10/10/10/10) = 6 6*100000 = 600000 685757  600000 = 85757 a simple while loop would do this quickly. Alternatively, it may be quicker to pull out the leftmost character and convert it to an integer then mutiply by 10^("length of string"1) The original code posted looks like it might work fine, I just wonder how slow it is. 
January 24th, 2018, 08:04 AM  #13 
Member Joined: Jan 2016 From: Athens, OH Posts: 92 Thanks: 47 
weirdave The Java code as posted by the OP is not quite correct. If the input is a single digit positive integer, his code generates a NumberFormatError. This can be easily fixed by adding a check to see if the input is such a single digit. The problem is so small that any correct solution will execute very quickly. The only way efficiency could become an issue is if the algorithm is executed numerous times. I can' t think of any possible problem that would need this. 
January 26th, 2018, 01:44 AM  #14 
Senior Member Joined: Apr 2014 From: UK Posts: 898 Thanks: 329 
It might slow down (relatively!) if a very large number is used. I agree that as the problem stands, it will be fast enough for human interaction. If the input was replaced by a huge data set then it might prove to be a bit sluggish, but then, I wouldn't use Java for that 
April 20th, 2018, 05:56 AM  #15 
Newbie Joined: Sep 2013 From: Reno,NV Posts: 14 Thanks: 1 Math Focus: Number Theory 
n is the original number a = integer part(log(n)) d = integer part(n\(10^a)) 

Tags 
challenge problem, equation, java, math, weird 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Weird correlation. Need equation.  OTheB  Math  4  July 19th, 2016 12:16 AM 
Java  gaussrelatz  Computer Science  3  April 6th, 2014 08:33 AM 
weird differential equation  helloprajna  Differential Equations  2  July 16th, 2013 11:25 PM 
java problem  cire09  Computer Science  1  October 9th, 2010 05:54 AM 
Java versus C++  johnny  Computer Science  17  October 21st, 2007 07:12 PM 