ex:
Welcome to D :-) Few more comments beside the ones written by Jonathan M Davis.
> I'm learning D and I was wondering on what can be optimized of my
> implementation of a palindrome function:
See below.
> 2) Does using a variable to store the string length is more efficient
As a side note, I'd suggest making your function take a string of some kind, if
not outright making it a template to deal with multiple string types. That way,
you can check for a palindrome regardless of whether you're dealing with
numbers, and if you need to do it with a number, you just conve
On Saturday 07 August 2010 16:56:08 ex wrote:
> Hello!
> I'm learning D and I was wondering on what can be optimized of my
> implementation of a palindrome function:
>
> bool isPalindrome(int num) {
> string s = text(num);
> int len = s.length;
> for
Sorry I forg to paste my last version"
bool isPalindrome(int num) {
string s = text(num);
int length = s.length;
int limit = length / 2;
for (int i = 0; i < limit; ++i) {
if (s[i] != s[$ - 1 - i]) {
return false;
}
}
return true;
}
Hello!
I'm learning D and I was wondering on what can be optimized of my
implementation of a palindrome function:
bool isPalindrome(int num) {
string s = text(num);
int len = s.length;
for (int i = 0; i < len / 2; ++i) {
if (s[i] != s[len - 1 - i]) {
retu