• 0 Posts
  • 36 Comments
Joined 1 year ago
cake
Cake day: June 19th, 2023

help-circle






  • EF can have big problems with “Cartesian explosions” if an object has two lists of sub objects to return, it will get listA length x listB length items due to how the joins work. You can see how this leads to the explosion part of the name (with more objects or lists).

    Their solution is a “split query” option, that does each sub table as a separate query, then seamlessly gives you the combined result.

    If a change like this let’s you get those different table lists as distinct lists with the processing and round trip time of multiple requests then it could be a game changer.

    (Source - my last week 🤣😭 + lots of EF docs)


  • SQL returns subsets of all tables with only those tuples that would be part of the traditional (single-table) query result set

    So it returns only the data that would be returned from the query, so the filtering is done.

    I can see some uses of it. If you look at what something like Entity Framework does behind the scenes to return nested objects, you can see how something like this might help.



  • Nighed@sffa.communitytoGaming@beehaw.org5+ man group games
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    8 months ago

    For some slightly less common games: Golf with your friends is a great mini game to play, effectively really crazy golf online

    From the Depths build ships/planes/tanks with entirely custom guns, engines etc. then play on the campaign map with fleets of these ships. you can make some really complicated vehicles if that’s your thing. Unlimited player count as far as I’m aware.

    A less deep version of that is Avorion - Mine resources to build custom ships (less complicated) then even small fleets and do quests, make allies/enemies as you venture to the centre of the galaxy. Supports unlimited players as far as I’m aware. It also allows you to form an alliance to share resources with other players. Resource gathering (mining/salvaging) can be automated by your fleets if that’s not your thing.




  • C# I had fun with this one and overbuilt it somewhat. Disappointed I didn’t get/need to implement Dijkstra’s algorithm.

    For part two I did a x2 expand, so the example input expanded and found the middles like this (0s for the targets as their easier to distinguish):

    Part 1
    namespace AdventOfCode2023.Days.Ten
    {
        internal class Day10Task1 : IRunnable
        {
            private HashSet<(int, int)> _visitedNodes = new HashSet<(int, int)>();
    
            public void Run()
            {
                //var inputLines = File.ReadAllLines("Days/Ten/Day10ExampleInput.txt");
                //var inputLines = File.ReadAllLines("Days/Ten/Day10ExampleInput2.txt");
                var inputLines = File.ReadAllLines("Days/Ten/Day10Input.txt");
    
                var map = new PipeMap(inputLines);
                _visitedNodes.Add((map.XCoord, map.YCoord));
    
                while (true)
                {
                    bool haveMoved = false;
                    for (int i = 0; i < 4; i++)
                    {
                        if (map.CanMove((Direction)i))
                        {
                            map.Move((Direction)i);
                            if (_visitedNodes.Contains((map.XCoord, map.YCoord)))
                            {
                                map.Move(GetOppositeDirection((Direction)i));
                            }
                            else
                            {
                                _visitedNodes.Add((map.XCoord, map.YCoord));
                                haveMoved = true;
                            }
                        }
                    }
    
                    if (!haveMoved)
                    {
                        break;
                    }
                }
    
                Console.WriteLine("Nodes Visited: "+ _visitedNodes.Count);
                Console.WriteLine("Furthest Node: "+ _visitedNodes.Count/2);
    
            }
    
    
    
    
            public class PipeMap
            {
                public int XCoord { get; private set; }
                public int YCoord { get; private set; }
                public char CurrentPipe { get { return Map[YCoord][XCoord]; } }
    
                private string[] Map { get; set; }
    
                public PipeMap(string[] mapString)
                {
                    Map = mapString;
    
                    for (int y = 0; y < mapString.Length; y++)
                    {
                        for (int x = 0; x < mapString[y].Length; x++)
                        {
                            if (mapString[y][x] == 'S')
                            {
                                YCoord = y;
                                XCoord = x;
                            }
                        }
                    }
                }
    
                public void Move(Direction direction)
                {
                    var adjacent = GetAdjacent(direction);
    
                    XCoord = adjacent.Item1;
                    YCoord = adjacent.Item2;
                }
    
                public bool CanMove(Direction direction)
                {
                    bool currentPositionAllow = CanMoveFromCoord(direction, XCoord, YCoord);
    
                    if (!currentPositionAllow) return false;
    
                    var adjacent = GetAdjacent(direction);
    
                    if (adjacent.Item3 != '.' && CanMoveFromCoord(GetOppositeDirection(direction), adjacent.Item1, adjacent.Item2))
                    {
                        return true;
                    }
    
                    return false;
                }
    
                private bool CanMoveFromCoord(Direction direction, int xCoord, int yCoord)
                {
                    switch (Map[yCoord][xCoord])
                    {
                        case '|':
                            return direction == Direction.Up || direction == Direction.Down;
                        case '-':
                            return direction == Direction.Left || direction == Direction.Right;
                        case 'L':
                            return direction == Direction.Up || direction == Direction.Right;
                        case 'J':
                            return direction == Direction.Up || direction == Direction.Left;
                        case '7':
                            return direction == Direction.Left || direction == Direction.Down;
                        case 'F':
                            return direction == Direction.Right || direction == Direction.Down;
                        case 'S':
                            return true;
                        case '.':
                        default:
                            throw new Exception("you dun fucked up");
                    }
                }
    
                private (int, int, char) GetAdjacent(Direction direction)
                {
                    var newXCoord = XCoord;
                    var newYCoord = YCoord;
    
                    switch (direction)
                    {
                        case Direction.Up:
                            newYCoord--;
                            break;
                        case Direction.Down:
                            newYCoord++;
                            break;
                        case Direction.Left:
                            newXCoord--;
                            break;
                        case Direction.Right:
                            newXCoord++;
                            break;
                    }
    
                    return (newXCoord, newYCoord, Map[newYCoord][newXCoord]);
                }
            }
    
            public enum Direction
            {
                Up, Right, Down, Left
            }
    
            public static Direction GetOppositeDirection(Direction direction)
            {
                switch (direction)
                {
                    case Direction.Up:
                        return Direction.Down;
                    case Direction.Down:
                        return Direction.Up;
                    case Direction.Right:
                        return Direction.Left;
                    case Direction.Left:
                        return Direction.Right;
                    default: throw new Exception("You dun fucked up... again");
                }
            }
        }
    
    
    }
    

    Part 2 is too big to post… see pastebin link






  • C#

    Not too bad - I just scored every hand for the first part so I could easily sort it.

    For the second part I just brute forced the replacements for the hand type matchinge (first digit of score)

    Task1

    public class Day7Task1:IRunnable {

    public static Dictionary CardValues = new Dictionary()
     {
         { '2', "01" },
         { '3', "02" },
         { '4', "03" },
         { '5', "04" },
         { '6', "05" },
         { '7', "06" },
         { '8', "07" },
         { '9', "08" },
         { 'T', "09" },
         { 'J', "10" },
         { 'Q', "11" },
         { 'K', "12" },
         { 'A', "13" }
     };
     
     public void Run()
     {
         //var inputLines = File.ReadAllLines("Days/Seven/Day7ExampleInput.txt");
         var inputLines = File.ReadAllLines("Days/Seven/Day7Input.txt");
    
    
    
         var hands = inputLines.Select(line =>
         {
             var split = line.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
             return new Hand(split[0],  split[1] );
         }).ToList();
    
         var sortedHands = hands.OrderBy(hand => hand.Score).ToList();
    
         long resultValue = 0;
    
         for (int i = 1; i < hands.Count()+1; i++)
         {
             resultValue += i * sortedHands[i-1].Bid;
         }
    
         Console.WriteLine("Result:" + resultValue);
    
     }
    
     public class Hand
     {
         public Hand(string cards, string bid)
         {
             Cards = cards;
             Bid = int.Parse(bid);
             Score = GenerateScore();
         }
    
         public string Cards { get; set; }
         public int Bid { get; set; }
         
         public long Score { get; }
    
         private long GenerateScore()
         {
             var resultString = new StringBuilder();
             var cardGroups = Cards.GroupBy(c => c).ToList();
             var groupCounts = cardGroups.OrderByDescending(g => g.Count()).Select(g => g.Count()).ToList();
             if (cardGroups.Count() == 1)
             {
                 resultString.Append("7");
             }
             else if(cardGroups.Count() == 2 && (cardGroups[0].Count() == 4 || cardGroups[0].Count() == 1))
             {
                 resultString.Append("6");
             }
             else if(cardGroups.Count() == 2 && (cardGroups[0].Count() == 3 || cardGroups[0].Count() == 2))
             {
                 resultString.Append("5");
             }
             else if(cardGroups.Count() == 3 && (cardGroups[0].Count() == 3 || cardGroups[1].Count() == 3 || cardGroups[2].Count() == 3))
             {
                 resultString.Append("4");
             }
             else if(cardGroups.Count() == 3 && groupCounts[0] == 2 && groupCounts[1] == 2 && groupCounts[2] == 1)
             {
                 resultString.Append("3");
             }
             else if(cardGroups.Count() == 4 )
             {
                 resultString.Append("2");
             }
             else
             {
                 resultString.Append("1");
             }
    
             foreach (var card in Cards)
             {
                 resultString.Append(Day7Task1.CardValues[card]);
             }
    
             Console.WriteLine("Cards:{0} Score:{1}",Cards,resultString);
             return long.Parse(resultString.ToString());
         }
     }
    }
    
    Task2
    public class Day7Task2:IRunnable
    {
        public static Dictionary CardValues = new Dictionary()
        {
            { '2', "01" },
            { '3', "02" },
            { '4', "03" },
            { '5', "04" },
            { '6', "05" },
            { '7', "06" },
            { '8', "07" },
            { '9', "08" },
            { 'T', "09" },
            { 'J', "00" },
            { 'Q', "11" },
            { 'K', "12" },
            { 'A', "13" }
        };
        
        public void Run()
        {
            //var inputLines = File.ReadAllLines("Days/Seven/Day7ExampleInput.txt");
            var inputLines = File.ReadAllLines("Days/Seven/Day7Input.txt");
    
    
    
            var hands = inputLines.Select(line =>
            {
                var split = line.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
                return new Hand(split[0],  split[1] );
            }).ToList();
    
            var sortedHands = hands.OrderBy(hand => hand.Score).ToList();
    
            long resultValue = 0;
    
            for (int i = 1; i < hands.Count()+1; i++)
            {
                resultValue += i * sortedHands[i-1].Bid;
            }
    
            Console.WriteLine("Result:" + resultValue);
    
        }
    
        public class Hand
        {
            public Hand(string cards, string bid)
            {
                Cards = cards;
                Bid = int.Parse(bid);
                Score = GenerateScore();
            }
    
            public string Cards { get; set; }
            public int Bid { get; set; }
            
            public long Score { get; }
    
            private long GenerateScore()
            {
                var generateFirstDigit = new Func(cards =>
                {
                    var cardGroups = cards.GroupBy(c => c).ToList();
                    var groupCounts = cardGroups.OrderByDescending(g => g.Count()).Select(g => g.Count()).ToList();
                    if (cardGroups.Count() == 1)
                    {
                        return 7;
                    }
                    else if (cardGroups.Count() == 2 && (cardGroups[0].Count() == 4 || cardGroups[0].Count() == 1))
                    {
                        return 6;
                    }
                    else if (cardGroups.Count() == 2 && (cardGroups[0].Count() == 3 || cardGroups[0].Count() == 2))
                    {
                        return 5;
                    }
                    else if (cardGroups.Count() == 3 && (cardGroups[0].Count() == 3 || cardGroups[1].Count() == 3 || cardGroups[2].Count() == 3))
                    {
                        return 4;
                    }
                    else if (cardGroups.Count() == 3 && groupCounts[0] == 2 && groupCounts[1] == 2 && groupCounts[2] == 1)
                    {
                        return 3;
                    }
                    else if (cardGroups.Count() == 4)
                    {
                        return 2;
                    }
                    else
                    {
                        return 1;
                    }
                });
                
                var resultString = new StringBuilder();
    
                var maxFistDigit = Day7Task2.CardValues.Keys.Select(card => generateFirstDigit(Cards.Replace('J', card))).Max();
    
                resultString.Append(maxFistDigit);
                
                foreach (var card in Cards)
                {
                    resultString.Append(Day7Task2.CardValues[card]);
                }
    
                Console.WriteLine("Cards:{0} Score:{1}",Cards,resultString);
                return long.Parse(resultString.ToString());
            }
        }
    }