All pastes #465397 Raw Edit

Someone

public text v1 · immutable
#465397 ·published 2007-04-30 03:48 UTC
rendered paste body
//General ArrayList o' Object implementation
static void mutate(ArrayList<Object> pre, ArrayList<Object> suf, ArrayList<ArrayList<Object>> results)
{
    if (suf.size() == 0)
        results.add(pre);
    for (int i = 0; i < suf.size(); i++)
    {
        ArrayList<Object> npre = (ArrayList<Object>) pre.clone();
        ArrayList<Object> nsuf = (ArrayList<Object>) suf.clone();
        npre.add(nsuf.remove(i));
        mutate(npre, nsuf, results);
    }
}

//String implementation (less lines)
static void mutate(String pre, String suf, ArrayList<String> results)
{
    if (suf.length() == 0)
        results.add(pre);
    for (int i = 0; i < suf.size(); i++)
        mutate(pre + suf.charAt(i), suf.substring(0, i) + suf.substring(i+1, i), results);
}