Palindrome detection: Difference between revisions

task description: Remove all the unnecessary cruft (doesn't invalidate any solutions), improve formatting, and add related tasks box
(task description: Remove all the unnecessary cruft (doesn't invalidate any solutions), improve formatting, and add related tasks box)
Line 4:
[[Category:Classic CS problems and programs]]
 
A [[wp:Palindrome|palindrome]] is a phrase which reads the same backward and forward.
;Task:
Write at least one function/method (or whatever it is called in your
preferred language) to check if a sequence of characters (or bytes)
is a [[wp:Palindrome|palindrome]] or not.
The ''function'' must return a boolean value
(or something that can be used as boolean value, like an integer).
 
{{task heading}}
It is not mandatory to write also an example code that uses
the ''function'', unless its usage could be not clear
(e.g. the provided recursive C solution
needs explanation on how to call the function).
 
Write at a function or program that checks whether a given sequence of characters (or, if you prefer, bytes)
It is not mandatory to handle properly encodings (see [[String length]]),
asis a palindrome.
i.e. it is admissible that the function does not recognize 'salàlas'
as palindrome.
 
'''''Optional (Extra credit) tasks:'''''
The function must not ignore spaces and punctuations.
* Support Unicode strings.
The compliance to the aforementioned, strict or not,
* Write another function (possibly as a wrapper to the first) which detects ''inexact'' palindromes, i.e. phrases that are palindromes if white-space and punctuation is ignored.
requirements completes the task.
 
{{task heading|Hints}}
'''Example'''<br>
An example of a Latin palindrome is the sentence
"''In girum imus nocte et consumimur igni''",
roughly translated as: we walk around in the night and we are burnt by the fire (of love).
To do your test with it, you must make it all the same case and strip spaces.
 
;Clarification:
To remove some confusion expressed in the discussion tab:
 
* To satisfy this task, the function should only identify exact palindromes; it should *not* strip spaces or punctuation or convert case.
* You may additionally write a wrapper function to detect inexact palindromes, such as the Latin example in the task description, or simply do the conversion in the calling function of your test code.
 
 
:Notes:
* It might be useful for this task to know how to [[Reversing a string|reverse a string]].
* This task's entries might also form the subjects of the task [[Test a function]].
 
{{task heading|Related tasks}}
 
{{Related tasks/Word plays}}
 
<hr>
;Related task:
* &nbsp; [[Semordnilap]]
<br><br>
 
=={{header|ACL2}}==
Anonymous user