Limerick

MathBabbler posted the following to his Facebook on 24 April 2019.

   It's 4/4! and I have 4*4 days left being an Artichoke.

MathBabber's posting is not a limerick, but it got Compufoo (MathBabbler's sibling) to ponder writing a program that tests if an array of integers contains any limerickal patterns. Compufoo didn't know what a limerick was, so he looked it in the Wikipedia.

   "A limerick is a form of verse, usually humorous and frequently 
    rude, in five-line, predominantly anapestic meter with a strict 
    rhyme scheme of AABBA, in which the first, second and fifth line 
    rhyme, while the third and fourth lines are shorter and share a 
    different rhyme." [source: Wikipedia.org]

The limerick pattern is AABBA, where A ≠ B.

   { array }:  # of AABBA patterns
   ===============================
   { 6,2,4, }:  0
   { 1,1,2,2,1, }:  1
   { 1,2,3,2,1, }:  0
   { 2,7,7,7,7,7,2, }:  0
   { 2,2,4,4,2,2,4, }:  2
   { 0,2,2,4,4,2,2,4,6, }:  2
   { 4,0,1,1,2,2,1,3,5, }:  1
   { 9,9,3,3,9,9,9,3,3,9, }:  2
   { 0,1,2,2,1,1,2,4,5,5,3,3,5, }:  2
   { 7,1,1,7,7,1,7,7,7,1,1,7,1,7,7,1,1,7,1, }:  3

An array having less than five elements cannot contain any AABBA patterns.

When testing it is necessary to use arrays that start with and end with AABBA patterns (boundary conditions). In addition, overlapping AABBA patterns must be counted.

AABBAA.java


Creator: Gerald Thurman [gthurman@gmail.com]
Created: 24 April 2019