Advent Of Code 2023

Hi all,

Not strictly testing, but I know there are a lot of testers out there who like to practice their programming skills.

Just wondering if anyone has every attempted the Advent of Code challenge? Are you planning on attempting the challenge this year?

Each day, for advent (starting 1st December, and ending 25th December) a new programming puzzle is released. The challenge is to complete as many as you can. Even though a new puzzle is released daily, there is no time limit to complete each one. You can also pick any programming language you like to solve the puzzle.

The puzzles get tougher each day (last year I was struggling to complete day 10), but its a good way to practice your programming skills. Love to know if there are any testers attempting the challenge.

https://adventofcode.com/

5 Likes

Hey Louise,

I know @kristof and @oxygenaddict were interested in the Advent of Cyber 2023.

1 Like

It’s interesting but less interesting then Advent of Cyber :stuck_out_tongue: So I’ll do AoC + I’m still following some extra courses, 2 Advents is a bit too much XD

I participated in 2015, and then every year since 2016, but never got all the 50 possible stars.
To me the years are very different in how hard they are to solve; 2021 was extremely hard in particular.

Looking forward to this year’s puzzles! :jigsaw:

Cheers,
Stephan

1 Like

Yes, I’m participating. Got reminders set in my calendar.
But like Stephan, I’m not sure if I’ll manage to get all 50 stars. It starts of easy, but gets harder the closer we get to Christmas :sweat_smile:

1 Like

I only learnt about it last year, managed 25 stars. For the other years, I occasionally picked a puzzle to solve for fun, but I didn’t do them in that year.

2015 was a lot easier compared to last years puzzles.

image

1 Like

I will try this one for the first time, more to learn than challenge myself🤔 Glhf to everyone who tries it as well✨

2 Likes

Here is a leaderboard code which everyone is welcome to join. Nice to see how everyone is doing for each challenge
2557629-7358e769

1 Like

Good start to the challenge, well done @pmichielsen
image

Took a few attempts to get the logic correct on part 2, only 5 incorrect answers before getting the correct one.

1 Like

What is everyone’s go to language for this? For me it is Python, but without additional packages; only the standard library :snake:

I’m completing the challenge using C#, the puzzles get so difficult that I wouldn’t want to make it more difficult by attempting them in a programming language I’m not familiar with. Since I started doing the challenges, my programming skills has improved dramatically.

1 Like

I’m in, Ruby all the way for me. <3

Nice to see a new addition to the leaderboard

@pmichielsen completed todays puzzle before me. I’m going to have to set my alarm clock so I can get the points first. My sleeping pattern always goes crazy in December thanks to advent of code.

Day 5 was a tough one, took me a good half an hour just to understand the question. Had to really optimize my code, still took 20 minutes for it to run before I got to the correct answer. Fortunately didn’t have to run the whole thing, would have taken a lot longer otherwise.

I’ve also started the Advent of Code 2023 using C#.
I think I wouldn’t actually get anywhere without the worked examples as explanations. After a while, I question my ability to read English.

I’m still stumped on Day 3 - Part 2.

Day 5 was pretty fun because I was questioning, how am I supposed to check that I am getting the logic right other than submitting the answer in to check.

OK - stuck on Day 5 - part 2. Hints most welcome.
I’m not happy with anything running more than 1 minute. Part 1 was done in 3 ms.

2 Likes

Intrigued, what do you mean by not having to run the whole thing?

Ya! Ignore me - I just read part 2. I get what you mean.

1 Like

Yeah, part 2 had so may possible iterations that had to be run through that it would have taken hours to run through the entire thing. Managed to optimize the code to reduce the potential runtime, but then had to start work so decided to just let it run.

Since the answer had to be the lowest possible value, I just got the code to output the possible answer every time one was found that was lower than the previous one. I then submitted that answer until the correct one was accepted.

I think I only ran through a quarter of the total iterations until the correct answer was found, which took about 20 minutes total.

Today wasn’t too bad, found a lovely visualization of todays challenge.

2 Likes

HELP!!!
I am stuck on part 7 day 1. Here is my code, can anyone spot where I might have gone wrong?

public class handDetails
{
    public string original { get; set; }
    public int card1 { get; set; }
    public int card2 { get; set; }
    public int card3 { get; set; }
    public int card4 { get; set; }
    public int card5 { get; set; }
    public long score { get; set; }
}

string cardOrder = "AKQJT98765432";

public long Part1Answer()
{
    var fullList = System.IO.File.ReadLines(codePath).ToList();

    long answer = 0;
    var fives = new List<handDetails>();
    var fours = new List<handDetails>();
    var fullHouses = new List<handDetails>();
    var threes = new List<handDetails>();
    var twoPairs = new List<handDetails>();
    var pairs = new List<handDetails>();
    var highCards = new List<handDetails>();

    foreach (string line in fullList)
    {
        var hand = line.Split(' ')[0];
        var score = line.Split(' ')[1];

        var count1 = 0;
        var count2 = 0;
        foreach(var card in hand.ToList().Distinct())
        {
            var count = hand.Where(x => x == card).ToList().Count;
            if (count > count1)
                count1 = count;
            else if (count > count2)
                count2 = count;
        }

        var newHand = new handDetails
        {
            original = hand,
            card1 = cardOrder.IndexOf(hand[0].ToString()),
            card2 = cardOrder.IndexOf(hand[1].ToString()),
            card3 = cardOrder.IndexOf(hand[2].ToString()),
            card4 = cardOrder.IndexOf(hand[3].ToString()),
            card5 = cardOrder.IndexOf(hand[4].ToString()),
            score = Convert.ToInt64(score)
        };
 
        if (count1 == 5)
            fives.Add(newHand);
        else if (count1 == 4)
            fours.Add(newHand);
        else if (count1 == 3 && count2 == 2)
            fullHouses.Add(newHand);
        else if (count1 == 3)
            threes.Add(newHand);
        else if (count1 == 2 && count2 == 2)
            twoPairs.Add(newHand);
        else if (count1 == 2)
            pairs.Add(newHand);
        else
            highCards.Add(newHand);
    }

    fives = SortCards(fives);
    fours = SortCards(fours);
    fullHouses = SortCards(fullHouses);
    threes = SortCards(threes);
    twoPairs = SortCards(twoPairs);
    pairs = SortCards(pairs);
    highCards = SortCards(highCards);

    var finallist = highCards
        .Concat(pairs)
        .Concat(twoPairs)
        .Concat(threes)
        .Concat(fullHouses)
        .Concat(fours)
        .Concat(fives);

    var list = finallist.ToArray();
    for(int i = 0; i < list.Length; i++)
    {
        var hand = list[i];
        answer += hand.score * (i + 1);
        Console.WriteLine($"{hand.card1} {hand.card2} {hand.card3} {hand.card4} {hand.card5} - {hand.original} - {hand.score} * {(i + 1)} - {answer}");
    }

    return answer;
}

public List<handDetails> SortCards(List<handDetails> handDetails)
{
    return handDetails
        .OrderByDescending(h => h.card1)
        .ThenByDescending(h => h.card2)
        .ThenByDescending(h => h.card3)
        .ThenByDescending(h => h.card4)
        .ThenByDescending(h => h.card5)
        .ToList();
}

Not my language so can’t immediately see anything. Do you know if you’re classifying the hand-type correctly or if the problem is with the sorting?

Found the mistake, it was sometimes classiying the full house incorrectly

Something like AAKKK would be classed as a three of a kind because it would override count1 with the second distinct count if it was greater than the first distinct count.