Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Challenge: Nearest Palindromic Number

by murugu (Curate)
on Feb 03, 2005 at 07:38 UTC ( [id://427545]=note: print w/replies, xml ) Need Help??


in reply to Challenge: Nearest Palindromic Number

Hi guys this is my try.

use strict; use warnings; sub palindrome{ my ($n)=shift; my ($a,$b); $b=$a=$n; return $a if ($a eq reverse $a); 1 while (++$a != (reverse $a)); 1 while (--$b != (reverse $b)); (abs($n-$a)>abs($n-$b))?$b:$a; }

Please give your kind suggestions.

Murugesan.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://427545]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found