or
Code Golf string decision-problem
Bubbler
A small variation of [a challenge on CGCC.SE](https://codegolf.stackexchange.com/q/85994/78410).

Given a string $s$ made of only lowercase a's and b's, determine if it satisfies

$$s \in \{ a^n b^n a^n | n \in \mathbb{Z}, n \ge 0 \}$$

In plain English, determine if $s$ equals some (possibly zero) copies of a, followed by the same number of b, followed by the same number of a.

## Input and output

A full program or a function is acceptable.

You can take input as a string, a list of characters, or a list of codepoints (which will then be a list of 97 and 98).

You can choose to output one of the following:

* Truthy / falsy values following your language's convention (swapping is also allowed)
* Two distinct values representing true / false respectively

## Test cases

| Input | Output |
| :-- | :-: |
|   (empty string) | true |
| aba | true |
| aabbaa | true |
| aaabbbaaa | true |
| a | false |
| b | false |
| ab | false |
| ba | false |
| aab | false |
| aabbaab | false |
| aabbaaa | false |
| aaabbaa | false |
| baabbaa | false |
| aabbbaa | false |

# [APL (Dyalog Unicode)], 17 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")^SBCS^
Anonymous tacit prefix function. Requires 0-based indexing (⎕IO←0)
apl
⊂∊'aba'/¨∘⊂⍨∘⍳1⌈≢

[Try it online!][TIO-k60fj353]

| Reading order| Notes
| ---- | -----
| ⊂∊ |Is the whole argument a member of
| &emsp;&emsp;'aba'/¨∘⊂|the whole of "aba", with its letters replicated by each
| &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;∘  | of
| &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;⍳  | 0, 1, …
| &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;1⌈ | the maximum of 1 and
|&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;≢  | the tally of characters?

| Execution order| Notes
| ---- | -----
|&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;≢  | tally the argument
| &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;1⌈ | the maximum of 1 and that
| &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;⍳  | 0, 1, … that
| &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;∘  | then
| &emsp;&emsp;'aba'/¨∘⊂|For each of those, replicate the characters of "aba"
| ⊂∊ |is the whole argument a member of that list?

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-k60fj353]: https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/x91NT3q6FJPTEpU1z@04lHHDJBAL5jRu9nwUU/Ho85F/9OASh/19kF0dTUfWm/8qG0ikBcc5AwkQzw8g/@nqatzpYGNAVGJSUmJUBaQCWRDOCAiCaIOzIQpRuhBYiL0Q5hJyKaCDVUHAA "APL (Dyalog Unicode) – Try It Online"
Mathgeek
# [Golfscript](http://www.golfscript.com/), 26 bytes


..3/,/{.|}/~++"aba"=\,3%!*


Not particularly optimal, but the first solution I thought of. Probably could pare down the string-comparison bit into some kind of bitwise comparison. ~++"aba"= is 9 bytes just to check "is the order right", when it could probably be done in 3 somehow. After the loop, we would have (if correct), ["a", "b", "a"], so it should be doable. I'll check some bitwise comparisons later, but this is a good starting benchmark.

Parse;


..  #Duplicate the string twice. Stack is now three copies.
3/  #Divide the string into parts of size 3.
,  #Count how many parts there are, and get rid of that copy
/  #Divide one of the two original strings into three parts
#using the prev number
{.|}/  #For each of these parts, get rid of duplicates
~++  #Break them out of the array then concatenate them.
"aba"=  #Make sure the array followed the pattern of
#1/3 a's, 1/3 b's, then 1/3 a's again.
#If so, we replace it with 1. Otherwise 0.
\  #Bring that last original-string over.
,3%  #Make sure it's a clean multiple of three.
!  #If so, 1. If not, 0.
*  #Multiply! 1*1=1, and 0*1 or 0*0=0, so if
#both conditions pass, we pass 1.

xnor
## [Haskell], 26 bytes

haskell
f s=[c|c<-"aba",'b'<-s]==s


[Try it online!][TIO-k61uvjuc]

[TIO-k61uvjuc]: https://tio.run/##TYxBCoAwDAS/EoLgxf7AvkQ8JMWqWKUYj77dWK2il2QWZncgmboQVD2IbdzuaoPEhFXJZW2ktVZ0pnEBC3Edlw0KmCmChwaxgqymR8z0UMLEOVyHs3fjK3@dH379jPxfvUex1cP5QL2ocTGe "Haskell – Try It Online"

Checks that the input string is equivalent to the following construction: for each character in "aba", repeat that character once for each 'b' in the input (checked with the pattern match 'b'<-s).

An equally-long alternative uses <*.

haskell
f s=("aba"<*[1|'b'<-s])==s


[Try it online!][TIO-k61v36zg]

[TIO-k61v36zg]: https://tio.run/##TYxLCoRADESvEoLgB124t08iLhKZVrGVZuLSsxu1ewbdJK/gVY0k88c5VQtiMiQmbIq23lNOm0q63BjRhaYVDPjvtG6QwEIeLLSIJQT/fsRMP7rw4hjuw9EL@JefzguffkR@r4ZR7PToraNBtOq9PwE "Haskell – Try It Online"
Some a's, b's, and then a's
Bubbler replying to Wheat Wizard
Yeah, even in Python 'abc' and ['a','b','c'] are two different things. Probably a better term could be *sequence of chars*.
Wheat Wizard
Not all languages implement strings that way.  Prolog is one of them.
Bubbler
I'll edit to explicitly allow list of chars and list of codepoints.
Bubbler replying to Wheat Wizard
Well, a string *is* just a list of characters.
Wheat Wizard
Personally I want to answer this in Prolog, so list of codepoints would be leagues better than strings.  But from a more impartial standpoint I don't see why strings are used as opposed to lists, since the structure in question is really a list.
Bubbler replying to Wheat Wizard
Would it be fine to allow a list of codepoints (that is, a list of 97 and 98) but not a list of e.g. 1 and 2? Or do you want any list of two distinct integers?
Wheat Wizard
@Bubbler Could we use a list of integers instead of a string?  Strings seem like a bit of a complex type to me.