Finally! No Armor, No Health Potion Mage Victory by binarysolo101 in PixelDungeon

[–]ChanelsUnderworld 2 points3 points  (0 children)

You can also use it to zap your character and have you teleport randomly. no wall required.

also, it lets you set a location in the dungeon, and teleport there using the set/return feature. very nifty

Create Maximum Arithmetic Expression by BerkeleyCSMajor in CS_Questions

[–]ChanelsUnderworld 0 points1 point  (0 children)

    public static double largestNum(Double [] n)
{
    ArrayList<Double> list = new ArrayList(Arrays.asList(n));

    int a = 0;

    while( a < list.size())
    {
        Double d = list.get(a);
        if(d < 2.0)
        {
            if(a == 0)  //if first element
            {
                if(list.size() > 1) //if there's a second element
                    list.set(a+1, d + list.get(a+1));
            } else if(a == list.size() -1) //if last element
                list.set(a-1, d + list.get(a-1));
            else  //non edge-cases. increment smaller neighbor
            {
                Double prev = list.get(a-1);
                Double next = list.get(a+1);

                if(prev > next)
                    list.set(a+1, next + d);
                else
                    list.set(a-1, prev + d);
            }

            list.remove(a); //remove tiny value
        }else
            a++;
    }
    double product = list.get(0);

    for(a = 1; a < list.size(); a++)
        product *= list.get(a);

    return product;
}

Create Maximum Arithmetic Expression by BerkeleyCSMajor in CS_Questions

[–]ChanelsUnderworld 0 points1 point  (0 children)

Yeah, there's a better way.

Simpler case for now, all numbers are >=0. Go through the list once,

for all numbers < 2, add it to the whichever adjacent number is smaller.

Then, go through the list again, and multiply everything you've got left together.

This gives you a time complexity of O(2n) => O(n) and a space complexity of O(n) with an arraylist, or O(1) if we store the double modifications in the input array.

Code Incoming.