Αναζήτηση αυτού του ιστολογίου

Computer Programming Exercises

PROGRAMMING EXERCISES FOR ANY LANGUAGE

1. Palindrome Detection
Create a simple algorith that will detect if a given string is a palindrome (read the same either when reading from left or right . For example radar , anna, etc).

Extend detection to palindrome phrases (i.e Lisa Bonet ate no basil, maps dna and spam, etc) . Ignore cases, spaces, etc.

The solution / code with less chars wins.

2. Palindrome Detection version 2 (by http://ittestsonline.com/ )
Write an algorithm which analyzes a string and checks if the characters can be rearranged to form a palindromic sequence.

If the string can indeed form a palindrome, also check if it can be transformed into a palindrome in maximum 3 rearrangements of characters – a rearrangement involves that a character changes its position with maximum 1 index, meaning only interchanges of adjacent characters are allowed at a time.

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. There is no need to check for capital letters, diacritics, accents, spaces, punctuation or word dividers.

Input: String
Output: Boolean value - 0 for FALSE or 1 for TRUE if the 2 conditions are met.

Example:
For input "soososo" => output : TRUE (1 change) - soosoos

Extension:
If the word/string is not capable to be reverted in a palindrome with 3 rearrangments, but can be eventually a palindrome with more rearrangements , calculate how many rearrangments are necessary by respecting the rule of adjacent char interchange.
In this case provide Output like this:

Word Evaluation : Not a palindrome
Word Evaluation : Palindrome with 3 or less rearrangments
Word Evaluation : Palindrome with X rearrangments (define X)

Winner is the algorithm that can form a palindrome with the less rearrangments, and also with the less code.

PS: Some Programming Tools provide some built in functions that can reverse words , phrases, etc.
Some languages can also provide ready to use functions to check for palindromes.
The good thing is to built this shit from SCRATCH.

3. Linux Exercise
Built a simple local proxy redirector with netcat that will be able to receive data from your browser, will call the desired web address and send back the returned data from this web site to your browser.
Extend it to log the data also in a file .