A binary string is a non-empty finite sequence of 0's and 1's. Given two binary strings, *u* and *v*, their concatenation, *u* * *v*, is defined to be the binary string obtained by appending *v* to the end of *u*. For example, if *u* = 01100 and *v* = 110, then *u* * *v* = 01100110.
Consider a function, *h*, that maps binary strings to other binary strings. Suppose that for every string *u* with digits *a*_{1}, *a*_{2}, ..., *a*_{k} in that order, it is true that *h*(*u*) = *h*(*a*_{1}) * *h*(*a*_{2}) *
... * *h*(*a*_{k}). Then, *h* is called a *non-degenerate homomorphism*. In general, this means that *h* is uniquely determined by the values of *h*(0) and *h*(1). For example, if *h*(0) = 001, and *h*(1) = 10, then,
- -
*h*(110) = *h*(1) * *h*(1) * *h*(0) = 1010001.
- -
*h*(00) = *h*(0) * *h*(0) = 001001.
- -
*h*(0101) = *h*(0) * *h*(1) * *h*(0) * *h*(1) = 0011000110.
Create a class Homomorphism that contains a method count, which is a given a String **u** and a String **v**. The method should return the number of distinct non-degenerate homomorphisms, *h*, which satisfy *h*(**u**) = **v**. If there are infinitely many such non-degenerate homomorphisms, the method should return -1. |