Beispiel #1
0
    public static void Run()
    {
        List <string> input = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day8/day8.txt");
        List <Tuple <string, int> > originalInstructions = GetInstructions(input);

        //(int accVal, bool terminated) = RunTheInstructions(originalInstructions);
        //Console.WriteLine($"Solution 1: {accVal}");

        for (int index = 0; index < originalInstructions.Count; index++)
        {
            List <Tuple <string, int> > instructions = new List <Tuple <string, int> >(originalInstructions);
            if (instructions[index].Item1 == "jmp")
            {
                instructions[index] = new Tuple <string, int>("nop", instructions[index].Item2);
            }
            else if (instructions[index].Item1 == "nop")
            {
                instructions[index] = new Tuple <string, int>("jmp", instructions[index].Item2);
            }

            (int accVal, bool terminated) = RunTheInstructions(instructions);

            if (terminated)
            {
                Console.WriteLine($"Solution 2: {accVal}");
            }
        }
    }
Beispiel #2
0
    /*
     * Action N means to move north by the given value.
     * Action S means to move south by the given value.
     * Action E means to move east by the given value.
     * Action W means to move west by the given value.
     * Action L means to turn left the given number of degrees.
     * Action R means to turn right the given number of degrees.
     * Action F means to move forward by the given value in the direction the ship is currently facing.
     */

    //The ship starts by facing east

    //Only the L and R actions change the direction the ship is facing

    public static void Run()
    {
        List <string> input    = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day12/day12.txt");
        List <Entry>  entries  = SeperateEntries(input);
        int           distance = GetDistanceTravelledFromEntries(entries);

        //Console.WriteLine($"Solution 1: {distance}");
        Console.WriteLine($"Solution 2: {distance}");
    }
Beispiel #3
0
    public static void Run()
    {
        List <string>         input  = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day6/day6.txt");
        List <List <string> > groups = SeperateGroups(input);
        //List<int> answeredYesGroups = GetYesInGroupsSolution1(groups);
        List <int> answeredYesGroups = GetYesInGroupsSolution2(groups);
        int        sumYesInGroups    = SumInList(answeredYesGroups);

        Console.WriteLine($"\nSolution 1: {sumYesInGroups}");
    }
Beispiel #4
0
    //Read/write to memory
    // Values and memory addresses are both 36-bit unsigned integers
    //The bitmask is always given as a string of 36 bits,
    //written with the most significant bit (representing 2^35

    //The current bitmask is applied to values immediately before they are written to memory
    //0 or 1 overwrites the corresponding bit in the value
    //X leaves the bit in the value unchanged

    //need the sum of all values left in memory after the initialization program completes
    //Test1 sol1 ans: 165
    //Test1 sol2 ans: 208
    public static void Run()
    {
        List <string>      input        = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day14/day14Test2.txt");
        List <Instruction> instructions = Instruction.ConvertInput(input);
        long sumVals = GetSumVals(instructions);

        Console.WriteLine($"Solution 1: {sumVals}");

        sumVals = GetSumValsVersion2(instructions);
        Console.WriteLine($"Solution 2: {sumVals}");
    }
Beispiel #5
0
    public static void Run()
    {
        List <string>    input = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day11/day11.txt");
        List <GridPoint> grid  = GetGrid(input);

        GridMaxDim      = grid.Count / input.Count;
        GridVerticalDim = input.Count;
        int numFinalOccupied = GetFinalOccupied(grid);

        Console.WriteLine($"Final occupied: {numFinalOccupied}");
    }
Beispiel #6
0
    public static void Run()
    {
        List <string> input = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day7/day7.txt");
        List <Bag>    bags  = SetBags(input);
        //Bag.PrintBags(bags);
        Bag goldBag = new Bag("shiny gold");

        //int numGoldBags = Bag.GetSumNumBags(goldBag, bags);
        //Console.WriteLine($"Solution 1: {numGoldBags}");

        Console.WriteLine($"Solution 2: {Bag.GetNumBagsInsideBag(goldBag, bags)}");
    }
Beispiel #7
0
    //Any given adapter can take an input 1, 2, or 3 jolts lower than its rating and still produce its rated output joltage

    //built-in joltage adapter rated for 3 jolts higher than the highest-rated
    //adapter list were 3, 9, and 6, your device's built-in adapter would be rated for 12

    //Treat the charging outlet near your seat as having an effective joltage rating of 0
    public static void Run()
    {
        List <string> input    = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day10/day10.txt");
        List <int>    adapters = GetAdapters(input);

        (int jolt1, int jolt2, int jolt3) = GetAllJoltsSolution1(adapters);
        Console.WriteLine($"Jolt1: {jolt1}, Jolt2: {jolt2}, Jolt3: {jolt3}");
        Console.WriteLine($"Solution1: {jolt1 * jolt3}");

        int distinctArrangements = GetDistinctArrangements(adapters);

        Console.WriteLine($"Solution2: {distinctArrangements}");
    }
Beispiel #8
0
    public static void Run()
    {
        List <string>  input    = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day10/day10.txt");
        List <Adapter> adapters = GetAdaptersSortInput(input);

        int[] jolts = GetAllJolts(adapters);
        Console.WriteLine($"Jolt1: {jolts[0]}, Jolt2: {jolts[1]}, Jolt3: {jolts[2]}");
        Console.WriteLine($"Solution1: {jolts[0] * jolts[2]}");

        double distinctArrangements = GetDistinctArrangements(adapters, jolts);

        Console.WriteLine($"Solution2: {distinctArrangements}");
    }
Beispiel #9
0
    public static void Run()
    {
        List <string> input = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day4/day4.txt");

        //Solution 1
        List <List <string> > entries = SeperateEntries(input);
        int validEntryCount           = GetValidEntriesCount(entries);

        Console.WriteLine($"Valid Entries count: {validEntryCount}");

        //Solution 2
        //Just Changed the GetValidEntriesCount
    }
Beispiel #10
0
    //preamble of 25 numbers
    //After that, each number you receive should be the sum of any two of the 25 preamble nums
    //The two numbers will have different values, and there might be more than one such pair
    //nums like 100 are invalid, no sum of 25 pairs can sum to 100
    //26 is valid, 1 + 25

    public static void Run()
    {
        List <string> input       = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day9/day9.txt");
        List <long>   nums        = GetNums(input);
        int           numPreamble = 25;

        (List <long> preamble, List <long> validation) = GetPreambleAndValidation(nums, numPreamble);
        long firstWrongValidationNum = GetFirstWrongValidationNum(preamble, validation);

        Console.WriteLine($"Solution 1: {firstWrongValidationNum}");

        (long min, long max) = GetMinAndMaxContigSet(firstWrongValidationNum, nums);
        Console.WriteLine($"Solution 2: {min + max}");
    }
Beispiel #11
0
    public static void Run()
    {
        List <string>     input        = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day13/day13.txt");
        int               earliestTime = int.Parse(input[0]);
        List <(int, int)> buses        = GetBuses(input[1]);

        //Solution 1
        //List<Tuple<int, int>> timeStampsClosestTo = GetClosestTimeStampsTo(earliestTime, buses);
        //(int smallestBus, int smallestTime) = GetSmallest(timeStampsClosestTo);
        //Console.WriteLine($"Solution 1: {smallestBus * (smallestTime - earliestTime)}");
        Log10Target = Target.ToString().Length - 1;
        long startingTimeStampConvergence = GetBusesConverging(buses);

        Console.WriteLine($"Solution 2: {startingTimeStampConvergence}");
    }
Beispiel #12
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            lblResults.Text = string.Empty;

            try
            {
                decimal[] pricesLastMonth = ReadInputFile.ReadPrices(lblSelectedFile.Text).ToArray();

                var results = ProcessBuySell.CalculateBestProfit(pricesLastMonth);

                lblResults.Text = $"{results.BuyDay}({results.BuyPrice}),{results.SellDay}({results.SellPrice})";
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Your entry was not valid: {ex.Message}");
            }
        }
Beispiel #13
0
    public static void Run()
    {
        List <string> input = ReadInputFile.GetInputAsLines("D:/C# projects/AdventOfCode2020/day5/day5.txt");

        (List <string> Rows, List <string> Columns) = SeperateRowAndColumns(input);
        List <int> IntRows    = GetIntEntries(Rows, 'F', 'B');
        List <int> IntColumns = GetIntEntries(Columns, 'L', 'R');

        //Solution 1
        int HighestID = GetHighestID(IntRows, IntColumns);

        Console.WriteLine($"Highest ID: {HighestID}");

        //Solution 2
        //Maybe get rid of all seats in the back
        //So -1 from front, add and then - 1 from back
        //Row 0 and 127 dont exist
        //not - So 8 seats per row, max is -16
        // Find the missing entries, and then minus them from your entry...
        // No dont think so Find which missing entries are below your id, if are then -1 from yours
        //      if above your id, then nothing

        (List <int> MissingEntryRows, List <int> MissingEntryColumns) = GetMissingRowsColumns(IntRows, IntColumns);
        //Console.WriteLine($"Missing num entries: {MissingEntryRows.Count}, Total num entries: {IntRows.Count}");

        //int myID = HighestID;
        for (int entryCount = 0; entryCount < MissingEntryRows.Count; entryCount++)
        {
            int id = GetID(MissingEntryRows[entryCount], MissingEntryColumns[entryCount]);
            Console.WriteLine(id);
            //if (id < HighestID || id > HighestID)
            //    myID--;
        }
        //Console.WriteLine($"My ID: {myID}");

        //Then picked the id of 633, which was the only 1 not in the front or the back...
        //I don't think the instructions were pretty clear
    }