SCJP
Visit my download page
Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).
There are 120 reversible numbers below onethousand.
How many reversible numbers are there below onebillion (109)?
SCJP
Visit my download page
Randall Twede wrote:i tried changing from String to StringBuilder, but it is still very slow. any help or observation appreciated.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
SCJP
Visit my download page
Personally, I wouldn't use either. What about breaking up each number into a List (or array) of int digits?
SCJP
Visit my download page
Randall Twede wrote:i am going to try moving the declaration of char c and int t out of the loop that might help
Randall Twede wrote:
Personally, I wouldn't use either. What about breaking up each number into a List (or array) of int digits?
that sounds good to me i didn't like changing back and forth in the first place. i have no idea how though
primitives don't have a charAt() method.
SCJP
Visit my download page
Randall Twede wrote:i have also been thinking about modulo math as a last resort.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
SCJP
Visit my download page
SCJP
Visit my download page
Randall Twede wrote:could you imagine...
a= x % 10
b = x % 100
c = x % 1000
d = x % 10000
e = x % 100000
f = x % 1000000
g = x % 10000000
h = x % 100000000
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:... there may well be quicker methods.
Martin Vajsar wrote:What about creating a lookup table for numbers below 1000 and doing it three digits at a time?
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
SCJP
Visit my download page
SCJP
Visit my download page
Randall Twede wrote:i finally let it run long enough and got the correct answer. i am still keeping in mind what Winston wrote and am going to see how others solved it.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
Each problem has been designed according to a "oneminute rule", which means that although it may take several hours to design a successful algorithm with more difficult problems, an efficient implementation will allow a solution to be obtained on a modestly powered computer in less than one minute.
Randall Twede wrote:i finally let it run long enough and got the correct answer. i am still keeping in mind what Winston wrote and am going to see how others solved it.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
Aditya Jha wrote:More optimization on the Math level (as opposed to code level), and the time comes down to 5.982 seconds.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
Aditya Jha wrote:Though, I recommend first proving this theorem for yourself, and then using the technique in code.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
SCJP
Visit my download page
Randall Twede wrote:Winston, i am still going to use your method to see how much it helps my solution to 145, i just got distracted:D
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
SCJP
Visit my download page
SCJP
Visit my download page
Randall Twede wrote:i have trouble with recursion to begin with.
"Leadership is nature's way of removing morons from the productive flow"  Dogbert
Articles by Winston can be found here
All of the world's problems can be solved in a garden  Geoff Lawton. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn KlassenKoop
https://coderanch.com/wiki/718759/books/BuildingWorldBackyardPaulWheaton
