コード例 #1
0
        public static void Solve()
        {
            using (var timer = new Timer("Day 11A Problem"))
            {
                //String[] lines = File.ReadAllLines(inputPath);

                List <Task <PowerBox> > lst = new List <Task <PowerBox> >();
                int  rowSlice = NumRows / NumWorkers;
                bool foundEnd = false;
                for (int i = 1; i <= NumRows; i += rowSlice)
                {
                    lst.Add(CreateJob(i, rowSlice));
                }


                Task <PowerBox>[] tasks = lst.ToArray();
                Log.WriteLine("Awaiting " + tasks.Length + " tasks");
                Task.WaitAll(tasks);
                PowerBox best = null;
                for (int i = 0; i < tasks.Length; i++)
                {
                    if (best == null || best.Power < tasks[i].Result.Power)
                    {
                        best = tasks[i].Result;
                    }
                }
                Log.WriteLine("Best box at " + best.TopLeftCornerX + "," + best.TopLeftCornerY + " with total power " + best.Power);
            }
        }
コード例 #2
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        coList.Remove(collision.gameObject);
        if (coList.Count == 0)
        {
            PowerBox pb = collision.GetComponent <PowerBox>();
            pb.setUse(false);

            ON.SetActive(false);
            OFF.SetActive(true);
        }
    }
コード例 #3
0
    // Collision detection
    void OnTriggerEnter2D(Collider2D collision)
    {
        // If it collides with the player
        if (collision.CompareTag("PowerBlock") /*|| collision.CompareTag("Player") || collision.CompareTag("Enemy")*/)
        {
            PowerBox pb = collision.GetComponent <PowerBox>();
            pb.setUse(true);

            coList.Add(collision.gameObject);
            ON.SetActive(true);
            OFF.SetActive(false);
        }
    }
コード例 #4
0
        public static PowerBox GenerateBox(int i, int j)
        {
            //Log.WriteLine("Generating a box at " + i + " , " + j);
            PowerBox res = new PowerBox();

            res.TopLeftCornerX = i - 1;
            res.TopLeftCornerY = j - 1;
            int totalPower = 0;

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    totalPower += CalculatePowerAtLocation(i + x, j + y);
                }
            }

            res.Power = totalPower;
            return(res);
        }
コード例 #5
0
ファイル: Day11BSolver.cs プロジェクト: jmcguirk/aoc-2018
        public static PowerBox GenerateBoxOfSize(int i, int j, int size)
        {
            //Log.WriteLine("Generating a box at " + i + " , " + j);
            PowerBox res = new PowerBox();

            res.Size           = size;
            res.TopLeftCornerX = i;
            res.TopLeftCornerY = j;
            int totalPower = 0;

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    totalPower += GetPowerValue(i + x, j + y);
                }
            }

            res.Power = totalPower;
            return(res);
        }
コード例 #6
0
ファイル: Day11BSolver.cs プロジェクト: jmcguirk/aoc-2018
        public static void Solve()
        {
            using (var timer = new Timer("Day 11B Problem"))
            {
                PowerValues = new int[NumRows * NumCols];
                for (int i = 1; i < NumRows; i++)
                {
                    for (int j = 1; j < NumCols; j++)
                    {
                        SetPowerValue(i, j, CalculatePowerAtLocation(i, j));
                    }
                }
                //String[] lines = File.ReadAllLines(inputPath);

                List <Task <PowerBox> > lst = new List <Task <PowerBox> >();
                bool foundEnd = false;
                for (int i = 1; i <= NumRows; i++)
                {
                    lst.Add(CreateJob(i));
                }


                Task <PowerBox>[] tasks = lst.ToArray();
                Log.WriteLine("Awaiting " + tasks.Length + " tasks");
                Task.WaitAll(tasks);
                PowerBox best = null;
                for (int i = 0; i < tasks.Length; i++)
                {
                    if (tasks[i].Result == null)
                    {
                        continue;
                    }
                    if (best == null || best.Power < tasks[i].Result.Power)
                    {
                        best = tasks[i].Result;
                    }
                }
                Log.WriteLine("Best box at " + best.TopLeftCornerX + "," + best.TopLeftCornerY + " with total power " + best.Power + " and size " + best.Size);
            }
        }
コード例 #7
0
        public static PowerBox FindBestBox(int startRow, int workSlice)
        {
            PowerBox res = null;

            startRow = Math.Clamp(startRow, 2, NumRows - 1);
            int endRow = Math.Clamp(startRow + workSlice, 2, NumRows - 1);

            //Log.WriteLine("Starting " + startRow + " ");
            for (int i = startRow; i < endRow; i++)
            {
                for (int j = 2; j < NumCols; j++)
                {
                    PowerBox box = GenerateBox(i, j);
                    if (res == null || box.Power > res.Power)
                    {
                        res = box;
                    }
                }
            }

            return(res);
        }
コード例 #8
0
ファイル: Day11BSolver.cs プロジェクト: jmcguirk/aoc-2018
        public static PowerBox FindBestBoxOfSize(int size)
        {
            PowerBox res = null;

            int endRow = NumRows - size;
            int endCol = NumCols - size;

            //Log.WriteLine("Starting " + startRow + " ");
            for (int i = 1; i <= endRow; i++)
            {
                for (int j = 1; j < endCol; j++)
                {
                    PowerBox box = GenerateBoxOfSize(i, j, size);
                    if (res == null || box.Power > res.Power)
                    {
                        res = box;
                    }
                }
            }

            return(res);
        }
コード例 #9
0
ファイル: PowerMeterUI.cs プロジェクト: shreyask21/powermeter
 private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     PowerBox.Invoke(DataDelegate, new Object[] { Serial.ReadLine() });
 }