• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

If s/o can help me translating my code in Python to C plsss ^^'


New Coder
def determinate(automaton, replace=False, is_determinate=False, do_complete=False):

    done = 0

    conserve = []

    states = list(automaton.states)

    next_states = copy.deepcopy(automaton.next_states)

    initial_states = list(automaton.initial_states)

    terminal_states = list(automaton.terminal_states)

    initial_composite = ''.join(letter + (STATE_SEPARATOR if initial_states[-1] != letter else '') for letter in initial_states)

    initial_next_state = []

    is_terminal = any(state in terminal_states for state in initial_states)

    for state in initial_states:

        if state in next_states:

            for _state in next_states[state]:

                if _state not in initial_next_state:


    if is_determinate:

        letter_next = {letter: 0 for letter in automaton.alphabet}

        for _state in initial_next_state:


        if any([letter_next[letter]>1 for letter in letter_next]):

            return False


        states.insert(0, initial_composite)

        next_states[initial_composite] = list(initial_next_state)

    if is_terminal:


    for state in states:

        letter_next = {letter: [] for letter in automaton.alphabet}

        if state in next_states:

            for _state in next_states[state]:


        for letter in letter_next:

            if len(letter_next[letter])>1:

                done = 1

                if is_determinate:

                    return False


                    composite = set(list(_state for _state in letter_next[letter]))

                    matched = match(automaton, states, initial_states, composite, conserve)

                    if matched:

                        next_states[state].append([matched, letter])


                        process_composite(automaton, states, initial_states, automaton.alphabet, next_states, composite, conserve)

                        next_states[state].append([match(automaton, states, initial_states, composite, conserve), letter])

    if not done:

        if is_determinate:

            return True


        for state in initial_states:

            if state not in conserve:

                del next_states[state]

                del states[states.index(state)]

                if state in terminal_states:

                    del terminal_states[terminal_states.index(state)]

        next_states[initial_composite] = [_state for _state in next_states[initial_composite] if _state not in initial_next_state]

        if do_complete:

            save = list(automaton.states), copy.deepcopy(automaton.next_states)

            automaton.states, automaton.next_states = states, next_states

            states, next_states = complete(automaton, replace=False, special=True)

            automaton.states = save[0]

            automaton.next_states = save[1]

        if replace:

            automaton.states = states

            automaton.next_states = next_states

            automaton.initial_states = [initial_composite]

            automaton.terminal_states = terminal_states

            if do_complete:

                automaton.is_complete = True

            automaton.is_determinate = True

            automaton.rename(automaton.name + ' (déterministe' +

                             (' et complet' if complete else '') + ')')

            automaton.is_standard = is_standard(automaton)



            automaton = Automaton(automaton.alphabet, states,

                             next_states, [initial_composite],

                             terminal_states, tag=[automaton,

                                 'det'+('+cpt' if complete else '')], name='', bools=[

                                 False, True, do_complete or automaton.is_complete, False])

Last edited by a moderator:


Active Coder
Staff Team

Does not sound like 'help me translate it', but rather 'translate it for me' :laugh:. Give us some context, how experienced are you with Python and C? What have you tried so far?