
-----------------------------------
md
Mon Oct 24, 2005 11:10 pm

Quick contest (all languages)
-----------------------------------
Ok... so I gave the challenge on IRC, but I figure I'll open it to anyone on compsci

The Challenge: write a function to check to see if a string is a palendrome. It should only one parameter, the string, and return a boolean value of true if the string is a palendrome, or false if it is not.
The Judges: I'll judge who wins by who can write the shortest code (instruction wise), who can write the fastest code (order n wise), and who's code is easiest to read. I might get a few other people (wtd, rizzix) to help judge too if I can.

The prize: the proze will be all my bits devided amongst the winners, or if there is a mod who will sponsor this however much they feel like giving.

-----------------------------------
[Gandalf]
Mon Oct 24, 2005 11:15 pm


-----------------------------------
fcn checkPalindrome (word : string) : boolean
    for i : 1 .. length (word) div 2
        if word (i) ~= word (length (word) - i + 1) then
            result false
        end if
    end for
    result true
end checkPalindrome

-----------------------------------
md
Mon Oct 24, 2005 11:18 pm


-----------------------------------
My C/C++ entry so people have an idea how one could do it


bool Palindrome(char *string, int length)
{
	return (length  s == reverse s) (Just "aaaa")

-----------------------------------
goomba
Sat Oct 29, 2005 1:22 pm


-----------------------------------
Python for the win!


def isPalindrome(word):
        if word[::-1] in word:
                return True
        return False


Drat!! :( I was just about to post that.

Just for the record, you can make this a one-liner:
def isPalindrome(word): return word[::-1]==word

Going even further, how about a real one-liner:

isPalindrome=lambda word: word

There we go. :P

-----------------------------------
md
Sun Oct 30, 2005 1:57 pm


-----------------------------------
Weekend -> Contest is over. However I'm lazy and have lots of study to do so methinks I'll leave hte judging until later... (if at all). There are some interesting solutions, though the one line solutions are only one line because all the work is being done by the language and other routines (ei. because they cheat :P). I did leave it open to all languages however so I suppose I can't complain.

And so no one can cheat... here are all the entries... 

Gandalf:
fcn checkPalindrome (word : string) : boolean
    for i : 1 .. length (word) div 2
        if word (i) ~= word (length (word) - i + 1) then
            result false
        end if
    end for
    result true
end checkPalindrome


beard0:
fcn isPalindrome (str : string) : boolean
    result length(str)