Skip to main content
added 43 characters in body
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259

Haskell, 7272 69 bytes (no regex)

g(a:b:c)|a==b=g c
g x=x==[]
or.mapany(g.words.concat).mapM(\c->[[c],c:" "])

Thanks to BlackCap for -3 bytes.

g(a:b:c)                                     g on list with elements a, b and tail c,
        |a==b                                 in the case that a==b,
             =g c                             recurses to the tail c.
g x=                                         g on any other list x
    x==[]                                     checks that x is empty.
                                              This includes the case where a is not equal
                                              to b, resulting in False.
or.mapany(g.words.concat).mapM(\c->[[c],c:" "]) The main function:
                       mapM(\c->[[c],c:" "])  Replace each letter c with either "c" or "c "
                                              in all possible ways, return list of results.
   mapany(              ).                       Map thisCheck functionthat overat theleast results:
one result satisfies this:
            concat                          Concatenate the 1- or 2-letter strings,
         words.                                split again at each space,
       g.                                      apply g.
or.                                           Check that at least one result gave True.

Haskell, 72 bytes (no regex)

g(a:b:c)|a==b=g c
g x=x==[]
or.map(g.words.concat).mapM(\c->[[c],c:" "])
g(a:b:c)                                     g on list with elements a, b and tail c,
        |a==b                                 in the case that a==b,
             =g c                             recurses to the tail c.
g x=                                         g on any other list x
    x==[]                                     checks that x is empty.
                                              This includes the case where a is not equal
                                              to b, resulting in False.
or.map(g.words.concat).mapM(\c->[[c],c:" "]) The main function:
                       mapM(\c->[[c],c:" "])  Replace each letter c with either "c" or "c "
                                              in all possible ways, return list of results.
   map(              ).                       Map this function over the results:
               concat                          Concatenate the 1- or 2-letter strings,
         words.                                split again at each space,
       g.                                      apply g.
or.                                           Check that at least one result gave True.

Haskell, 72 69 bytes (no regex)

g(a:b:c)|a==b=g c
g x=x==[]
any(g.words.concat).mapM(\c->[[c],c:" "])

Thanks to BlackCap for -3 bytes.

g(a:b:c)                                  g on list with elements a, b and tail c,
        |a==b                              in the case that a==b,
             =g c                          recurses to the tail c.
g x=                                      g on any other list x
    x==[]                                  checks that x is empty.
                                           This includes the case where a is not equal
                                           to b, resulting in False.
any(g.words.concat).mapM(\c->[[c],c:" "]) The main function:
                    mapM(\c->[[c],c:" "])  Replace each letter c with either "c" or "c "
                                           in all possible ways, return list of results.
any(              ).                       Check that at least one result satisfies this:
            concat                          Concatenate the 1- or 2-letter strings,
      words.                                split again at each space,
    g.                                      apply g.
Source Link
Zgarb
  • 42.8k
  • 4
  • 79
  • 259

Haskell, 72 bytes (no regex)

g(a:b:c)|a==b=g c
g x=x==[]
or.map(g.words.concat).mapM(\c->[[c],c:" "])

A brute-force approach. Try it on Ideone.

Explanation

The helper function g takes a list of strings, and checks that it consists of pairs of identical strings, like ["aa","aa","bba","bba","ab","ab"]. The (anonymous) main function splits a string in all possible ways, and checks that at least one splitting results in a list that g accepts.

g(a:b:c)                                     g on list with elements a, b and tail c,
        |a==b                                 in the case that a==b,
             =g c                             recurses to the tail c.
g x=                                         g on any other list x
    x==[]                                     checks that x is empty.
                                              This includes the case where a is not equal
                                              to b, resulting in False.
or.map(g.words.concat).mapM(\c->[[c],c:" "]) The main function:
                       mapM(\c->[[c],c:" "])  Replace each letter c with either "c" or "c "
                                              in all possible ways, return list of results.
   map(              ).                       Map this function over the results:
               concat                          Concatenate the 1- or 2-letter strings,
         words.                                split again at each space,
       g.                                      apply g.
or.                                           Check that at least one result gave True.