Share:

C

Colby Meline

in

development

February 20 2023

Keep things in perspective

#adventofcode

#growth

#development

#learning

Working "in tech" is awesome and brings with it huge benefits. The tasks are rewarding, you're capable of doing things you never thought possible, and the compensation doesn't hurt. However, it can also be a huge mental burden. No matter what you do or how hard you work, it sometimes feels like the things you've learned are tiny when contrasted with the things you need to learn.

If you're starting to understand REST APIs,
  you're actually behind because you don't understand GraphQL.
If you're starting to understand Bootstrap CSS,
  you're actually behind because you don't understand Tailwind.
If you're starting to understand React,
  you're actually behind because 10 new Frontend Frameworks™ were released while you read this sentence.

There's some good to feeling this way. It's a motivating force that compels you to keep improving. But, it's also stressful and deceiving. Instead of comparing what we know about software engineering to all of the knowledge present in mankind about software engineering, it's much better to compare what we know about software engineering to what we knew about software engineering yesterday, last week, last month, or last year.
Recently, I decided to do just that, taking a look back at the past two years of Advent of Code.

Advent of Code is an annual advent calendar of daily coding puzzles which increase in difficulty from December 1st to 25th. Each day's puzzle has two separate parts to complete, each rewarding successful answers with one star. I've only participated for two years (and I'm not that good at it), but I think it's an awesome thing to do.

In 2021, I managed to earn 14 stars out of 50, with the last star coming from day 14.
In 2022, I earned 34 out of 50 stars, with the last star coming from day 25.

I certainly could have (and sometimes did) beat myself up last December about not getting all 50 stars. If I'm supposed to be someone who writes software for a living, shouldn't these puzzles be a cinch?

This isn't a helpful way to consider what happened, though. In reality, approaching this retrospective with a growth mindset is way more productive. Not only was I able to earn 243% of the stars from my first year, but I was able to solve puzzles of a higher difficulty than previously possible.

Another thing to keep in mind is that the quality of my solutions improved between year 1 and year 2. For example, take the following two solutions.
The first is from day 3, 2021. It took me 119 lines of mediocre Java code to solve the puzzle.
The second code block is from day 3, 2022. It took me 34 lines of pretty readable Python code to solve the puzzle. Admittedly, the puzzles are different year-to-year, and comparing Java code to Python code isn't the most fair thing. Performing certain operations requires more effort: reading a file line-by-line, for instance. Still, I would be willing to assert that year 2's solutions are, on the whole, cleaner and more efficient.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Day3_Diagnostic {
  static File dataFile = new File("C:\\Users\\Colby\\Programming\\Java\\AdventOfCode\\d3data1");
  static ArrayList⟨String〉 dataList = new ArrayList⟨〉();
  static ArrayList⟨Integer〉 gamma = new ArrayList⟨〉();
  static ArrayList⟨Integer〉 epsilon = new ArrayList⟨〉();

  static {
    try (Scanner scanner = new Scanner(new FileReader(dataFile))) {
      while (scanner.hasNext()) {
        dataList.add(scanner.nextLine());
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }

  public static int findModeOfPosition(int bitPosition, ArrayList⟨String〉 dataList) {
    int zeroCount = 0;
    int oneCount = 0;
    for (int i = 0; i ⟨ dataList.size(); i++) {
      if (dataList.get(i).charAt(bitPosition) == '0') zeroCount++;
      else oneCount++;
    }
    System.out.println("There were " + zeroCount +" zeros and " + oneCount + " ones");

    if (zeroCount 〉 oneCount) {
      gamma.add(0);
      epsilon.add(1);
      return 0;
    }
    else {
      gamma.add(1);
      epsilon.add(0);
      return 1;
    }
  }

  public static int convertListToDecimal(ArrayList⟨Integer〉 arrayList) {
    String outputString = arrayList.get(0).toString();
    for (int i = 1; i ⟨ arrayList.size(); i++) {
      outputString = outputString.concat(arrayList.get(i).toString());
    }
    System.out.println(outputString);
    return Integer.parseInt(outputString, 2);
  }

  public static ArrayList⟨String〉 filterFindRating(int bitPosition, ArrayList⟨String〉 arrayList, boolean useMax) {
    String mode = Integer.toString(findModeOfPosition2(bitPosition, arrayList));
    ArrayList⟨Integer〉 removalList = new ArrayList();
    if (useMax) {
      for (int i = 0; i ⟨ arrayList.size(); i++) if (!arrayList.get(i).substring(bitPosition, bitPosition + 1).equals(mode)) removalList.add(i);
    } else {
      for (int w = 0; w ⟨ arrayList.size(); w++) if (arrayList.get(w).substring(bitPosition,bitPosition+1).equals(mode)) removalList.add(w);
    }
    arrayList.removeAll(removalList);
    return arrayList;
  }

  public static int findModeOfPosition2(int bitPosition, ArrayList⟨String〉 dataList) {
    int zeroCount = 0;
    int oneCount = 0;
    for (int i = 0; i ⟨ dataList.size(); i++) {
      if (dataList.get(i).charAt(bitPosition) == '0') zeroCount++;
      else oneCount++;
    }
    System.out.println("There were " + zeroCount +" zeros and " + oneCount + " ones");

    if (zeroCount 〉 oneCount) {
      return 0;
    }
    else {
      return 1;
    }
  }

  public static void main(String[] args) {
    for (int i = 0; i ⟨ dataList.get(0).length(); i++) {
      findModeOfPosition(i, dataList);
    }
    System.out.println(gamma);
    System.out.println(epsilon);
    int gammaInt = convertListToDecimal(gamma);
    int epsilonInt = convertListToDecimal(epsilon);
    System.out.println(gammaInt * epsilonInt);

    for (int i = 0; i ⟨ dataList.get(0).length(); i++) {
      if (dataList.size() 〉 1) {
        dataList = filterFindRating(i, dataList, true);
      }
    }
    String oxygenGeneratorRating = dataList.get(0);
    System.out.println("Oxygen Generator Rating = " + oxygenGeneratorRating);
    System.out.println(Integer.parseInt(oxygenGeneratorRating, 2));
    dataList.clear();
    try (Scanner scanner = new Scanner(new FileReader(dataFile))) {
      while (scanner.hasNext()) {
        dataList.add(scanner.nextLine());
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    for (int i = 0; i ⟨ dataList.get(0).length(); i++) {
      if (dataList.size() 〉 1) {
        dataList = filterFindRating(i, dataList, false);
      }
    }
    String co2ScrubberRating = dataList.get(0);
    System.out.println("CO2 Scrubber Rating = " + co2ScrubberRating);
    System.out.println(Integer.parseInt(co2ScrubberRating, 2));
    // Answer Incorrect, needs revision
    System.out.println(Integer.parseInt(co2ScrubberRating, 2) * Integer.parseInt(oxygenGeneratorRating, 2));
  }
}


with open("inputs/3.txt") as file:
  inputs = [i.replace("\n", "") for i in file.readlines()]


scores = {}

for i in range(65, 91): # Uppercase letters Unicode indexes
  scores[chr(i)] = i - 38

for i in range(97, 123): # Lowercase letters Unicode indexes
  scores[chr(i)] = i - 96


def part_one(inputs):
  score = 0
  for i in inputs:
    num_items = len(i)
    first, second = i[:num_items//2], i[num_items//2:]
    shared = set(first).intersection(set(second)).pop()
    score += scores[shared]
  return score

   
def part_two(inputs):
  score = 0
  for i in range(2, len(inputs), 3):
    first, second, third = inputs[i-2], inputs[i-1], inputs[i]
    badge = set(first).intersection(set(second)).intersection(set(third)).pop()
    score += scores[badge]
  return score

if __name__ == "__main__":
  print(part_one(inputs))
  print(part_two(inputs))

All of this is to say, if you feel like no matter how hard you work, no matter how much you build, and no matter how many things you learn, you're not reaching your goals; remember, you're probably making far more progress than you think.

Take a look back at things you made when you started out and remind yourself that you've come a long way, even if you've got a lot left to learn.

Copyright © 2023 MuensterMonster

Privacy PolicyTerms and Conditions