My Math Forum  

Go Back   My Math Forum > College Math Forum > Number Theory

Number Theory Number Theory Math Forum


Reply
 
LinkBack Thread Tools Display Modes
October 19th, 2011, 02:36 PM   #1
Newbie
 
Joined: Oct 2011

Posts: 15
Thanks: 0

reverse n

Hi.

I was looking for a way to test if some, non-negative, integer n is a palindrome. One way requires a non-recursive function (r(n)) that is going to yield the reversed order of digits of some n. I derived this function, but was wondering, if anyone here ever came across this and what were their results. I'm guessing there is a better way to do this, from what I did. If someone has any ideas, you can post them and I will post what I found also.
vdrn is offline  
 
October 19th, 2011, 02:38 PM   #2
Newbie
 
Joined: Oct 2011

Posts: 15
Thanks: 0

Re: reverse n

also, to add, we are talking about base 10.
vdrn is offline  
October 20th, 2011, 04:44 AM   #3
Global Moderator
 
CRGreathouse's Avatar
 
Joined: Nov 2006
From: UTC -5

Posts: 16,046
Thanks: 938

Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms
Re: reverse n

How large are the numbers you're looking at?
CRGreathouse is offline  
October 20th, 2011, 06:04 AM   #4
Newbie
 
Joined: Oct 2011

Posts: 15
Thanks: 0

Re: reverse n

from 0 to infinity.
vdrn is offline  
October 20th, 2011, 07:21 AM   #5
Global Moderator
 
CRGreathouse's Avatar
 
Joined: Nov 2006
From: UTC -5

Posts: 16,046
Thanks: 938

Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms
Re: reverse n

That's not very helpful.

Almost all natural numbers are too large to be stored on an x-gigabyte hard drive, where x is the number of electrons in the universe. I suppose you're not trying to work with those. But what range is of interest to you? If you want to work with large numbers then you should be willing to use an algorithm that is slow for small numbers, but if small numbers are of special importance you wouldn't want that trade.

I would suggest one method if you cared only about numbers up to 3 digits, another if you cared mostly about numbers up to wordsize (10 or 20 digits for 32/64 bits), another if you cared mostly about numbers below a few kilobytes in size (say, 25,000 digits and below), and yet another for larger numbers. The last would be implemented differently depending on the target size and the capabilities of the machine used.

For the first group table lookup would be best; for the second, convert the whole number to decimal (ideally via BCD instructions) and then test; for the next, pulling out the most- and least-significant words and pretesting is important, followed by a binary splitting radix conversion algorithm using Newton/Karatsuba division; the following is similar but using cache-friendly strategies and FFT-based division rather than Karatsuba; the last probably requires on-disk methods with access-friendly strategies that involve storing large portions of the number because hard drives work best by sector.
CRGreathouse is offline  
October 20th, 2011, 08:20 AM   #6
Newbie
 
Joined: Oct 2011

Posts: 15
Thanks: 0

Re: reverse n

I didn't mean a program function CRGreathouse , I am looking for a generalized way to do this for any n with the stated conditions in the first post (so that r(n)-n=0, that is, n is a palindromic number). Maybe I don't understand what you mean, could you please clarify?
vdrn is offline  
October 20th, 2011, 08:40 AM   #7
Global Moderator
 
CRGreathouse's Avatar
 
Joined: Nov 2006
From: UTC -5

Posts: 16,046
Thanks: 938

Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms
Re: reverse n

Quote:
Originally Posted by vdrn
I didn't mean a program function CRGreathouse , I am looking for a generalized way to do this for any n
In that case I don't understand what you want.
CRGreathouse is offline  
October 20th, 2011, 09:02 AM   #8
Newbie
 
Joined: Oct 2011

Posts: 15
Thanks: 0

Re: reverse n

example: for n=321, f(n)=123.
find f(n)?
vdrn is offline  
October 20th, 2011, 10:23 AM   #9
Global Moderator
 
CRGreathouse's Avatar
 
Joined: Nov 2006
From: UTC -5

Posts: 16,046
Thanks: 938

Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms
Re: reverse n

f(n) is the reverse of the decimal digits of n. What more do you want?
CRGreathouse is offline  
October 20th, 2011, 10:25 AM   #10
Newbie
 
Joined: Oct 2011

Posts: 15
Thanks: 0

Re: reverse n

generalized expression of what comes after f(n)=
vdrn is offline  
Reply

  My Math Forum > College Math Forum > Number Theory

Tags
reverse



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reverse Quaternion Kinematics equations. BVP? zuba Applied Math 1 December 19th, 2012 02:58 AM
reverse engineering a graph ravynware Algebra 0 April 15th, 2012 07:11 PM
Reverse Modulo swtrse Number Theory 2 August 6th, 2009 04:53 AM
Reverse solve f(x)? NumberA Algebra 5 April 19th, 2009 11:03 AM
Reverse calculation Clox Algebra 2 January 23rd, 2008 12:24 AM





Copyright © 2019 My Math Forum. All rights reserved.