scalacaster icon indicating copy to clipboard operation
scalacaster copied to clipboard

Classic-modern interpretations

Open ppKrauss opened this issue 6 years ago • 0 comments

Checking the isPalindrome... The classic algorithms are expressed as an "character-by-character algorithm", and is fine. Is oriented to a low-level view of algoritms and data-structures.

Another classic manner to view pattern-recognition algoritms in strings, is to express it by regular expression

  • isPalindrome() by "anchored recursive" regular expression ^((.)(?:(?1)|.?)\2)$

  • containsPalindrone() by recursive regular expression, supposing only letters (\w)(?:(?R)|\w?)\1

It is a good view from a first abstraction layer of strings... And is also classic.


The best layer for an algorithm perhaps is where the simplest and faster algorithm is expressed. It is also "classic". In the isPalindrome() an intermediary layer of abstraction, the ideal to express the same algorithm, is by use the string.reverse() method to compare strings.

ppKrauss avatar Feb 04 '18 15:02 ppKrauss