My Math Forum A weird equation? Java

 Computer Science Computer Science Forum

January 23rd, 2018, 03:56 PM   #11
Newbie

Joined: Jan 2018
From: somewhere

Posts: 14
Thanks: 2

Math Focus: Algebraic Number Theory / Differential Fork Theory
Quote:
 Originally Posted by weirddave Post #2 gets my vote, it's simple to understand and easy for a cpu to do quickly. However, since the input will be a string before it is converted, it may not be such a bad idea to keep the number as a string and chop off the left digit and remove any leading 0's. It won't be as cpu efficient, but it is simple.
2 doesnt even work. It needs to be rethought.

 January 24th, 2018, 12:42 AM #12 Senior Member   Joined: Apr 2014 From: UK Posts: 892 Thanks: 328 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, 09:04 AM #13 Member   Joined: Jan 2016 From: Athens, OH Posts: 91 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, 02:44 AM #14 Senior Member   Joined: Apr 2014 From: UK Posts: 892 Thanks: 328 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, 06: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 Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post OTheB Math 4 July 19th, 2016 01:16 AM gaussrelatz Computer Science 3 April 6th, 2014 09:33 AM helloprajna Differential Equations 2 July 17th, 2013 12:25 AM cire09 Computer Science 1 October 9th, 2010 06:54 AM johnny Computer Science 17 October 21st, 2007 08:12 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top