bradengroom/scala-automata-library

Implement repeat(min: Int) and repeat(min: Int, max: Int)

Closed this issue · 2 comments

These methods should repeat an automaton a certain amount of times. This will be implemented using the concatenate function.

repeat(min: Int) should repeat an automaton at least the given amount of times.
(a).repeat(3) should return a+a+a+(a*). This will accept any given amount of a's greater than 2.

repeat(min: Int, max: Int) should perform the same task but cap at the max number provided.
This might work but should be tested:

(this.repeat(min) intersect ((this.repeat(max+1)).complement))

repeat(min: Int)

def repeat(min: Int): Automaton = {
    if (min < 1)
        this*
    else
        this + repeat(min - 1)
}

repeat(min: Int, max: Int)

def repeat(min: Int, max: Int): Automaton = {
    if (min > max)
        BasicAutomaton.empty
    else
        this.repeat(min) intersect this.repeat(max + 1).complement
}