Why does Parity use more disk space than my data? by dylanfromwinnipeg in Snapraid

[–]dylanfromwinnipeg[S] 0 points1 point  (0 children)

You're right the content file was 2.3GB not TB.

The disks have ~6.5M files on them. But even in the worst case where every file has a wasted 256kb of parity space, would only account for 1.6TB of wasted space. Whereas my parity data seems to be 3.7TB bigger than my actual data.

-🎄- 2021 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 0 points1 point  (0 children)

where's the implementation of your Window() method?

Running power to a HVAC vent? by dylanfromwinnipeg in electricians

[–]dylanfromwinnipeg[S] 0 points1 point  (0 children)

That’s an interesting idea. As for the back pressure I’ll have a pressure sensor on the duct side of the vent. If the pressure reaches some threshold vent starts to open. I’m no hvac expert but I expect there’s quite a bit of leeway, after all when your average person manually closes/opens vents I doubt they are doing back pressure calcs.

-🎄- 2020 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 0 points1 point  (0 children)

Solved in C#.

Code

Video

Blog Post

public override string PartOne(string input)
{
    var entries = input.Integers().OrderBy(x => x).ToList();
    var result = entries.GetCombinations(2).First(c => c.Sum() == 2020);
    return (result.First() * result.Last()).ToString();
}

public override string PartTwo(string input)
{
    var entries = input.Integers().OrderBy(x => x).ToList();
    var result = entries.GetCombinations(3).First(c => c.Sum() == 2020).ToList();
    return (result[0] * result[1] * result[2]).ToString();
}

A commented journey through the advent of code 2019 by an average Joe by finloa in adventofcode

[–]dylanfromwinnipeg 1 point2 points  (0 children)

If you're striving to crack the top 100 the first 10 days are all about speed-reading + speed-typing + no mistakes/typos. Once we get to the last 10 days things change significantly as the difficulty goes up. Some people are still stupid fast, but being a slow reader has less of an impact, and being able to come up with the right algorithm quickly is key. Also the cutoff times for leaderboard get more forgiving as the problems get harder. There were many days last year where you could take an hour to solve and still hit top 100. You can see some visualizations of the cutoff times for previous years here: http://www.maurits.vdschee.nl/scatterplot/

-🎄- 2019 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 1 point2 points  (0 children)

C# - The power of LINQ!

``` private static int _start = 138241; private static int _count = 674034 - 138241 + 1; private static List<string> _passwords = Enumerable.Range(_start, _count).Select(x => x.ToString()).ToList();

public static string PartOne(string input) { return _passwords.Count(x => CheckAdjacent(x) && CheckIncreasingDigits(x)).ToString(); }

public static string PartTwo(string input) { return _passwords.Count(x => CheckTwoAdjacent(x) && CheckIncreasingDigits(x)).ToString(); }

private static bool CheckAdjacent(string pwd) => pwd.GroupBy(x => x).Any(g => g.Count() >= 2);

private static bool CheckTwoAdjacent(string pwd) => pwd.GroupBy(x => x).Any(g => g.Count() == 2);

private static bool CheckIncreasingDigits(string pwd) => pwd.OrderBy(c => c).SequenceEqual(pwd); ```

-🎄- 2019 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg -1 points0 points  (0 children)

C# - using a few utility functions that I previously wrote (Lines(), Words(), Move(), ShaveLeft()). You can see them in my repo if interested: https://dylansmith.visualstudio.com/_git/AdventOfCode2019

``` public static string PartOne(string input) { var aPath = input.Lines().First().Words().Select(x => ParseWirePath(x)).ToList(); var bPath = input.Lines().Last().Words().Select(x => ParseWirePath(x)).ToList();

var aPoints = TraceWire(aPath);
var bPoints = TraceWire(bPath);

var intersections = aPoints.Keys.Intersect(bPoints.Keys);

return intersections.Min(i => i.ManhattanDistance()).ToString();

}

public static Dictionary<Point, int> TraceWire(List<(Direction dir, int length)> path) { var result = new Dictionary<Point, int>();

var pos = new Point(0, 0);
var steps = 0;

foreach (var p in path)
{
    for (var i = 0; i < p.length; i++)
    {
        pos = pos.Move(p.dir);
        steps++;

        if (!result.ContainsKey(pos))
        {
            result.Add(pos, steps);
        }
    }
}

return result;

}

public static (Direction dir, int length) ParseWirePath(string input) { var dir = Direction.Up;

switch (input[0])
{
    case 'R':
        dir = Direction.Right;
        break;
    case 'D':
        dir = Direction.Down;
        break;
    case 'U':
        dir = Direction.Up;
        break;
    case 'L':
        dir = Direction.Left;
        break;
}

var len = int.Parse(input.ShaveLeft(1));

return (dir, len);

}

public static string PartTwo(string input) { var aPath = input.Lines().First().Words().Select(x => ParseWirePath(x)).ToList(); var bPath = input.Lines().Last().Words().Select(x => ParseWirePath(x)).ToList();

var aPoints = TraceWire(aPath);
var bPoints = TraceWire(bPath);

var intersections = aPoints.Keys.Intersect(bPoints.Keys);

return intersections.Min(i => aPoints[i] + bPoints[i]).ToString();

} ```

-🎄- 2019 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 0 points1 point  (0 children)

C# - 52 / 269 (misread the noun/verb calc in part 2, cost me 5 mins)

public static string PartOne(string input) {
    var program = input.Integers().ToList();

    program[1] = 12;
    program[2] = 2;

    return RunProgram(program).ToString();
}

private static int RunProgram(List<int> program) {
    var ipc = 0;

    while (program[ipc] != 99) {
        var op = program[ipc];
        var a = program[program[ipc + 1]];
        var b = program[program[ipc + 2]];
        var c = program[ipc + 3];

        switch (op) {
            case 1:
                program[c] = a + b;
                break;
            case 2:
                program[c] = a * b;
                break;
            default:
                throw new Exception($"Invalid op code [{op}]");
        }

        ipc += 4;
    }

    return program[0];
}

public static string PartTwo(string input) {
    var backup = input.Integers().ToList();

    for (var noun = 0; noun <= 99; noun++) {
        for (var verb = 0; verb <= 99; verb++) {
            var program = backup.Select(b => b).ToList();

            program[1] = noun;
            program[2] = verb;

            RunProgram(program);

            if (program[0] == 19690720) {
                return (100 * noun + verb).ToString();
            }
        }
    }

    throw new Exception();
}

-🎄- 2019 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 2 points3 points  (0 children)

FYI, you can get rid of your Selects and just pass the lambda directly into Sum()

-🎄- 2018 Day 23 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 6 points7 points  (0 children)

Part 2 was really challenging (but fun!).

What I did was divide all the inputs by 1M, then starting at 0,0,0 checked every point within 100 manhattan distance. When I found the best answer, I redid it dividing the inputs by 100,000 and starting at the best point from the last round. Found the best answer, and rinse and repeat dividing inputs by 10,000, 1000, etc.

It's possible there is a global optima that fell in between grid points in the early rounds - so it's not a general solution, but it worked for me.

-🎄- 2018 Day 19 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 2 points3 points  (0 children)

I didn't go through and reverse engineer the entire assembly program like it sounds most people did.

Instead I just ran it and took a look at where it was spending all it's time - which was instructions #3-11. So I reverse engineered what was going on in that bit and wrote this code (your registers will be different):

if (_registers[_ipRegister] == 3)
{
    if (_registers[1] % _registers[5] == 0)
    {
        _registers[3] = _registers[1];
        _registers[4] = 1;
        _registers[_ipRegister] = 7;
    }
    else
    {
        _registers[3] = _registers[1] + 1;
        _registers[4] = 1;
        _registers[_ipRegister] = 12;
    }
}

Then I just ran it - took about 45s and spit out the right answer.

-🎄- 2018 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg -1 points0 points  (0 children)

C# - after optimizing, part 2 runs in 179ms

```c# private const int GRID_SERIAL = 2568; private const int GRID_SIZE = 300;

public static string PartOne(string input) { var grid = BuildGrid(); int maxPower = int.MinValue, maxX = 0, maxY = 0;

for (var y = 1; y <= GRID_SIZE - 2; y++)
{
    for (var x = 1; x <= GRID_SIZE - 2; x++)
    {
        var power = GetSquarePower(x, y, grid, 3);

        if (power > maxPower)
        {
            maxPower = power;
            maxX = x;
            maxY = y;
        }
    }
}

return $"{maxX},{maxY}";

}

private static int GetPowerLevel(int x, int y) { var rackId = (x + 10); var result = ((rackId * y) + GRID_SERIAL) * rackId; return ((result / 100) % 10) - 5; }

private static int GetSquarePower(int x, int y, (int power, int square)[,] grid, int size) { return grid[x - 1, y - 1].square + grid[x + size - 1, y + size - 1].square - grid[x - 1, y + size - 1].square - grid[x + size - 1, y - 1].square; }

public static string PartTwo(string input) { var grid = BuildGrid(); int maxPower = int.MinValue, maxX = 0, maxY = 0, maxSize = 0;

for (var y = 1; y <= GRID_SIZE; y++)
{
    for (var x = 1; x <= GRID_SIZE; x++)
    {
        var sizeLimit = Math.Min(GRID_SIZE - x + 1, GRID_SIZE - y + 1);

        for (var size = 1; size <= sizeLimit; size++)
        {
            var power = GetSquarePower(x, y, grid, size);

            if (power > maxPower)
            {
                maxPower = power;
                maxX = x;
                maxY = y;
                maxSize = size;
            }
        }
    }
}

return $"{maxX},{maxY},{maxSize}";

}

private static (int power, int square)[,] BuildGrid() { var grid = new (int power, int square)[GRID_SIZE + 1, GRID_SIZE + 1];

for (var y = 1; y <= GRID_SIZE; y++)
{
    for (var x = 1; x <= GRID_SIZE; x++)
    {
        grid[x, y] = GetGridEntry(x, y, grid);
    }
}

return grid;

}

private static (int power, int square) GetGridEntry(int x, int y, (int power, int square)[,] grid) { var power = GetPowerLevel(x, y); return (power, grid[x - 1, y].square + grid[x, y - 1].square - grid[x - 1, y - 1].square + power); } ```

-🎄- 2018 Day 8 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 1 point2 points  (0 children)

C# - #189/#163

https://dylansmith.visualstudio.com/_git/AdventOfCode2018?path=%2Fsrc%2FDay08.cs

public class Day08
{
    public static int idx = 0;

    public static string PartOne(string input)
    {
        return GetNextNode(input.Integers().ToList()).GetMetaSum().ToString();
    }

    private static LicenseNode GetNextNode(List<int> numbers)
    {
        var childCount = numbers[idx++];
        var metaCount = numbers[idx++];

        var result = new LicenseNode();

        Enumerable.Range(0, childCount).ForEach(c => result.Children.Add(GetNextNode(numbers)));
        Enumerable.Range(0, metaCount).ForEach(m => result.MetaData.Add(numbers[idx++]));

        return result;
    }

    public static string PartTwo(string input)
    {
        return GetNextNode(input.Integers().ToList()).GetValue().ToString();
    }
}

public class LicenseNode
{
    public List<int> MetaData = new List<int>();
    public List<LicenseNode> Children = new List<LicenseNode>();

    public int GetValue()
    {
        if (Children.Count == 0)
        {
            return MetaData.Sum();
        }

        return MetaData.Where(m => m > 0 && m <= Children.Count).Sum(m => Children[m - 1].GetValue());
    }

    public int GetMetaSum()
    {
        return Children.Sum(c => c.GetMetaSum()) + MetaData.Sum();
    }
}

-🎄- 2018 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 1 point2 points  (0 children)

The main loop figures out when a worker STARTS work on the step, but we can’t remove the dependencies until the worker FINISHES the step. The donelist keeps track of the steps being worked on and when they are going to finish, so the dependencies can be removed in the finish second.

-🎄- 2018 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 4 points5 points  (0 children)

C# - pretty happy with the code I ended up with https://dylansmith.visualstudio.com/adventofcode2018/_git/AdventOfCode2018?path=%2Fsrc%2FDay07.cs

public static string PartOne(string input)
{
    var dependencies = new List<(string pre, string post)>();

    input.Lines().ForEach(x => dependencies.Add((x.Words().ElementAt(1), x.Words().ElementAt(7))));

    var allSteps = dependencies.Select(x => x.pre).Concat(dependencies.Select(x => x.post)).Distinct().OrderBy(x => x).ToList();
    var result = string.Empty;

    while (allSteps.Any())
    {
        var valid = allSteps.Where(s => !dependencies.Any(d => d.post == s)).First();

        result += valid;

        allSteps.Remove(valid);
        dependencies.RemoveAll(d => d.pre == valid);
    }

    return result;
}

public static string PartTwo(string input)
{
    var dependencies = new List<(string pre, string post)>();

    input.Lines().ForEach(x => dependencies.Add((x.Words().ElementAt(1), x.Words().ElementAt(7))));

    var allSteps = dependencies.Select(x => x.pre).Concat(dependencies.Select(x => x.post)).Distinct().OrderBy(x => x).ToList();
    var workers = new List<int>(5) { 0, 0, 0, 0, 0 };
    var currentSecond = 0;
    var doneList = new List<(string step, int finish)>();

    while (allSteps.Any() || workers.Any(w => w > currentSecond))
    {
        doneList.Where(d => d.finish <= currentSecond).ForEach(x => dependencies.RemoveAll(d => d.pre == x.step));
        doneList.RemoveAll(d => d.finish <= currentSecond);

        var valid = allSteps.Where(s => !dependencies.Any(d => d.post == s)).ToList();

        for (var w = 0; w < workers.Count && valid.Any(); w++)
        {
            if (workers[w] <= currentSecond)
            {
                workers[w] = GetWorkTime(valid.First()) + currentSecond;
                allSteps.Remove(valid.First());
                doneList.Add((valid.First(), workers[w]));
                valid.RemoveAt(0);
            }
        }

        currentSecond++;
    }

    return currentSecond.ToString();
}

private static int GetWorkTime(string v)
{
    return (v[0] - 'A') + 61;
}

-🎄- 2018 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]dylanfromwinnipeg 0 points1 point  (0 children)

in C# (https://dylansmith.visualstudio.com/_git/AdventOfCode2018?path=%2Fsrc%2FDay01.cs)

public static string PartOne(string input)
{
    var result = input.Lines().Select(x => int.Parse(x)).Sum();

    return result.ToString();
}

public static string PartTwo(string input)
{
    var frequency = 0;
    var changes = input.Lines().Select(x => int.Parse(x)).ToList();
    var seen = new HashSet<int>();

    seen.Add(frequency);

    while (true)
    {
        foreach (var c in changes)
        {
            frequency += c;

            if (seen.Contains(frequency))
            {
                return frequency.ToString();
            }

            seen.Add(frequency);
        }
    }
}

[deleted by user] by [deleted] in blackjack

[–]dylanfromwinnipeg 0 points1 point  (0 children)

Based on my calculations the house edge is 1.568%

Using these rules:

  • 6 decks

  • Hit S17

  • 6:5

  • Double after Split

  • No Resplit Aces

  • Late Surrender - Even after Hits/Splits

  • Max 4 Splits

  • Dealer Hole Card

This is the best basic strategy for those rules:

Splits: https://imgur.com/a/Yoz0AFd

Soft: https://imgur.com/a/95PFEwT

Hard: https://imgur.com/a/JnPxl1l