//Title: Palindromic Check
//Contributed By: Haywire
//Inspired By: Project Euler, Problem 4.
/*
This is a simple palindromic number check which returns true if the number (n) is symmetrical.
*/
proc
is_palindromic(var/n)
return (n==reverse_num(n))
reverse_num(var/n)
n = num2text(n)
for(var/i = lentext(n), i > 0, i--)
. += copytext(n, i, i+1)
.=text2num(.)
mob
verb
Test(n as num)
//9009 is an example of a symmetrical number (palindromic number)
world << "[n] is [(is_palindromic(n)? "a":"not a")] palindromic number."
ID:195035
May 31 2009, 12:06 pm
|
|
Aug 10 2009, 5:31 am
|
|
This proc crashes if you give it a number argument with 7 digits or more, because of scientific notation.
|
In response to Metamorphman
|
|
Metamorphman wrote:
This proc crashes if you give it a number argument with 7 digits or more, because of scientific notation. Thanks for spotting that out but that partly at fault of BYOND (however it doesn't crash but it does indeed fail). Due to scientific notation and BYOND's inaccurate precision of larger numbers I couldn't really modify it to work exactly how I wanted it to. However I have discovered a different method (thanks to Popisfizzy), by taking text as an input I can compare the value with precision as scientific notation isn't taken in-account when handling non-numerical values. //Title: Palindromic Check |