예제 #1
0
    public override string RunA()
    {
        List <(string, int)> items = AOCLoader.LoadLines(ResourceName,
                                                         ParseDirections);
        //items.ForEach((x) => Debug.Log(x));
        int y, z = y = 0;

        foreach ((string, int)item in items)
        {
            (string name, int distance) = item;

            switch (name)
            {
            case "forward":
                z += distance;
                break;

            case "up":
                y -= distance;
                break;

            case "down":
                y += distance;
                break;
            }
        }

        return((y * z).ToString()); // 2070300
    }
예제 #2
0
    public override string RunB()
    {
        List <(string, int)> items = AOCLoader.LoadLines(ResourceName,
                                                         ParseDirections);
        //items.ForEach((x) => Debug.Log(x));
        int y, z, a = z = y = 0;

        foreach ((string, int)item in items)
        {
            (string name, int units) = item;

            switch (name)
            {
            case "forward":
                z += units;
                y += (a * units);
                break;

            case "up":
                a -= units;
                break;

            case "down":
                a += units;
                break;
            }
        }

        return((y * z).ToString()); // 2078985210
    }
예제 #3
0
    public override string RunB()
    {
        List <int> items = AOCLoader.LoadLines(ResourceName, x => int.Parse(x));

        int measurementSize = 3;
        int lastMeasurement = 0;

        int count = 0;

        for (int i = 0; i < items.Count - (measurementSize - 1); i++)
        {
            int currentMeasurement = 0;

            for (int j = 0; j < measurementSize; j++)
            {
                currentMeasurement += items[i + j];
            }
            //Debug.Log(currentMeasurement);

            if (currentMeasurement > lastMeasurement && i > 0)
            {
                count++;
            }

            lastMeasurement = currentMeasurement;
        }

        return(count.ToString()); // 1275
    }
예제 #4
0
    public override string RunA()
    {
        List <int> items = AOCLoader.LoadLines(ResourceName, x => int.Parse(x));

        int count = 0;

        for (int i = 1; i < items.Count; i++)
        {
            if (items[i] > items[i - 1])
            {
                count++;
            }
        }

        return(count.ToString()); // 1233
    }