Category: Blog

  • Daily Coping 25 May 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to write down one thing you plan to do in the next year.

    I don’t make a lot of plans. While I do have a life (bucket) list, it doesn’t drive me on a regular basis. I have enough commitments that I prefer to not add other items if I don’t need to do so.

    For the next year, as I think about something that I might want to do, there are a lot of items outside of my control. I hate to plan something based on what others might not do, so I’m thinking about what can I control and get done.

    I think the item for me isn’t big, but it is something I need to do. I built a generator shed last year, but it’s too small, and doesn’t have proper ventilation. I can control my actions to work on that, so I’m going to spend time fixing that this summer and get it ready for winter.

    A small project, but it will make me feel good to get it done.

  • 2020 Advent of Code Day 6

    This series looks at the Advent of Code challenges.

    As one of my goals, I’m working through challenges. This post looks at day 6. I’m going to do this one in Python here, though I did solve it in other languages in my repo.

    Part 1

    This is another weird string grouping issue. The data load is a mess, meaning that there are groups of data I need to consider, and the groups are separated by blank lines. However, each group has multiple lines.

    Ugh.

    Easier in Python, where I can load the data line by line and break things. I do that with this code:

    for answers in open("2020\day6\day6_data.txt").read().split("\n\n"):

    In SQL, it’s harder. I bulk load into a table, the cursor through the data.

    DECLARE pcurs CURSOR FOR SELECT lineval FROM Day6 ORDER BY linekey;
    DECLARE
         @val VARCHAR(1000) = ''
       , @groups VARCHAR(1000);
    OPEN pcurs;
    FETCH NEXT FROM pcurs
    INTO @val;
    SET @groups = '';
    WHILE @@FETCH_STATUS = 0
    BEGIN
         IF @val > ''
             SELECT @groups += ' ' + @val;
         ELSE
         BEGIN
             INSERT dbo.Day6_Groups (groupanswers) VALUES (@groups);
             SET @groups = '';
         END;
         FETCH NEXT FROM pcurs
         INTO @val;
    END;
         INSERT dbo.Day6_Groups(groupanswers) VALUES (@groups);
    DEALLOCATE pcurs;
    GO

    Once that is done, I again have to do things differently. Python is easy, where I count the values and add them up.

    answers = set(answers.replace("\n",""))
    part1 += len(answers)

    In SQL, I need to distinctly find the values, for which I need a function of some sort.

    UPDATE dbo.Day6_Groups
      SET deduppedanswers =  DBO.REMOVE_DUPLICATE_INSTR(1,groupanswers)

    Once that’s done the answer is the sum of lengths.

    Part 2

    More complex here. Now I need to match up the common answers among the groups. In Python, this isn’t bad. I use the intersection method to find out what matches between the groups.

    for answers in open("2020\day6\day6_data.txt").read().split("\n\n"):
        matches = set.intersection(*[set(answer) for answer in answers.split()])
        part2 += len(matches)
    print("Part 2: ", part2)

    Fairly simple here, with the grouping of the answers in a set.

    SQL is hard.I reloaded the data, and separated each group by a comma. This gave me data I could split up, keeping each group in a group.

    2021-05-12 13_41_16-day6.sql - ARISTOTLE.AdventofCode (ARISTOTLE_Steve (56)) - Microsoft SQL Server

    From here, I had a CTE for this, another to put these into groups of 2 strings by groupID. I then did a comparison for common characters across each group of 2 strings. This gave me partial matches, and I then compared all these in a group, taking the minimum number of matches. From here, I summed up the count of all the matches.

  • Daily Coping 24 May 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to write down the memory of something good that happened in the last year.

    I’ve had a lot of good memories in the last year. Some tough ones, but overall, a good year. I think one of the good things that went well last year was taking a few days to relax with my wife in the mountains. Without a lot of vacation travel, our mountain rental was open and we took advantage of it. We spent a couple days up there, and while we didn’t ski much, we did get to relax and enjoy time with each other.

    Our lives are busy, and we don’t often get a few days completely off when we don’t have commitments. Finding 3 days that allowed us to read, relax, and unwind from life without animals, kids, work, and more was really nice.

  • Daily Coping 21 May 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to watch the sunset and reflect on the world.

    I was hoping for a weekend off, but it’s not coming. Mother’s Day was slightly off, but we had my son’s college graduation party and one practice, so it was only a slight break. Since May, I’ve had volleyball on two weekends (and next) and this weekend I’m helping a kid move with some practices around that. I truly am looking forward to the season ending and a little more free time.

    I write this because Thursday night was really the only time off this week. I scheduled yoga one night and had to cook, dinner with a friend another, and practice two others. As my wife went to feed horses, I sat outside watching and watching the sun start to go down.

    I also grabbed a bottle of wine and a couple glasses to take out and just relax, sitting and thinking about the rapidly changing world, the hope for the future, and some mourning for those that have, or are, suffering.