<commit_before>import java.util.*;

/*
 * Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

L,4L,4L,6R,10L,6

== A

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

L,4L,4L,6R,10L,6

== A

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

L,12L,6R,10L,6R,8R,10L,6

== B

Commands: R,8
Commands: R,10
Commands: L,6

R,8R,10L,6

== C

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

L,4L,4L,6R,10L,6

== A

Commands: R,8
Commands: R,10
Commands: L,6

R,8R,10L,6

== C

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

L,12L,6R,10L,6R,8R,10L,6

== B

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6

L,12L,6R,10L,6

== B
 */

public class FunctionRoutine
{
    public static final int NUMBER_OF_FUNCTIONS = 3;

    public static final int ROUTINE_A = 0;
    public static final int ROUTINE_B = 1;
    public static final int ROUTINE_C = 2;

    public static final int MAX_CHARACTERS = 20;

    public FunctionRoutine (Stack<String> pathTaken, boolean debug)
    {
        _path = pathTaken;
        _functions = new Vector<MovementRoutine>();
        _debug = debug;
    }

    public void createMovementFunctions ()
    {
        /*
         * Now convert the path into a series of commands
         * such as L,4 or R,8.
         */

        Vector<String> commands = getCommands();

        /*
         * Now turn the series of commands into functions
         * A, B and C based on repeated commands.
         * 
         * There are only 3 possible functions.
         * This means one function always starts at the beginning.
         * One function always ends at the ending (!) assuming it's not a repeat
         * of the first.
         * Then using both the first and the last fragment to find the third
         * and split the entire sequence into functions.
         * 
         * Also it's possible to give the Robot more commands than it can
         * execute before it gets to end of the route.
         */

        String fullCommand = "";

        for (int i = commands.size() -1; i >= 0; i--)
        {
            fullCommand += commands.elementAt(i);
        }

        System.out.println("Full command "+fullCommand);

        /*
         * Find repeated strings. Assume minimum of 2 commands.
         */

        int commandStart = 0;
        int startString = 0;
        String str = fullCommand;

        System.out.println("fullCommand length "+fullCommand.length());

        do
        {
            System.out.println("startString "+startString);

            if (startString != 0)
                str = fullCommand.substring(startString);

            System.out.println("str is "+str);

            MovementRoutine func = getFunction(commands, str, commandStart, 2);

            _functions.add(func);

            System.out.println("Function is "+func+"\n");

            commandStart += func.numberOfCommands();
            startString += func.getLength();

            System.out.println("Total commands used so far: "+commandStart);

        } while (str != null);
    }

    /*
     * Return a repeating function. Will return all repeating
     * functions given the input so we need to later figure out
     * the unique instances afterwards.
     * 
     * fullCommand is the String to search.
     * startingCommand is the command from which to begin the search.<commit_msg>Update FunctionRoutine.java<commit_after>import java.util.*;

/*
 * Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

L,4L,4L,6R,10L,6

== A

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

L,4L,4L,6R,10L,6

== A

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

L,12L,6R,10L,6R,8R,10L,6

== B

Commands: R,8
Commands: R,10
Commands: L,6

R,8R,10L,6

== C

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

L,4L,4L,6R,10L,6

== A

Commands: R,8
Commands: R,10
Commands: L,6

R,8R,10L,6

== C

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

L,12L,6R,10L,6R,8R,10L,6

== B

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6

L,12L,6R,10L,6

== B
 */

public class FunctionRoutine
{
    public static final int NUMBER_OF_FUNCTIONS = 3;

    public static final int ROUTINE_A = 0;
    public static final int ROUTINE_B = 1;
    public static final int ROUTINE_C = 2;

    public static final int MAX_CHARACTERS = 20;

    public FunctionRoutine (Stack<String> pathTaken, boolean debug)
    {
        _path = pathTaken;
        _functions = new Vector<MovementRoutine>();
        _debug = debug;
    }

    public void createMovementFunctions ()
    {
        /*
         * Now convert the path into a series of commands
         * such as L,4 or R,8.
         */

        Vector<String> commands = getCommands();

        /*
         * Now turn the series of commands into functions
         * A, B and C based on repeated commands.
         * 
         * There are only 3 possible functions.
         * This means one function always starts at the beginning.
         * One function always ends at the ending (!) assuming it's not a repeat
         * of the first.
         * Then using both the first and the last fragment to find the third
         * and split the entire sequence into functions.
         * 
         * Also it's possible to give the Robot more commands than it can
         * execute before it gets to end of the route.
         */

        String fullCommand = "";

        for (int i = commands.size() -1; i >= 0; i--)
        {
            fullCommand += commands.elementAt(i);
        }

        System.out.println("Full command "+fullCommand);

        /*
         * Find repeated strings. Assume minimum of 2 commands.
         */

        int commandStart = 0;
        int startString = 0;
        String str = fullCommand;

        System.out.println("fullCommand length "+fullCommand.length());

        do
        {
            System.out.println("startString "+startString);

            if (startString != 0)
                str = fullCommand.substring(startString);

            System.out.println("str is "+str);

            MovementRoutine func = getFunction(commands, str, commandStart, 2);

            _functions.add(func);

            System.out.println("Function is "+func+"\n");

            commandStart += func.numberOfCommands();
            startString += func.getLength();

            System.out.println("Total commands used so far: "+commandStart);

            System.out.println("left "+str);

        } while (str != null);
    }

    /*
     * Return a repeating function. Will return all repeating
     * functions given the input so we need to later figure out
     * the unique instances afterwards.
     * 
     * fullCommand is the String to search.
     * startingCommand is the command from which to begin the search.
{'fraction_non_alphanumeric': 0.10470388211958062, 'fraction_numerical': 0.03400396712949844, 'mean_word_length': 2.3109756097560976, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3428358', 'n_tokens_mistral': 2336, 'n_tokens_neox': 2278, 'n_words': 716}