Advent of Code: Day 2

Leo Nguyen Dec 2, 2021

Just like clockwork, Day 2 opened precisely at midnight of Eastern Standard Time.

The Puzzle

The puzzle, called Dive, has an input file that contains a list of commands. Each command has a word and a value, which represent a movement and how much to move, respectively. The words can be: forward to increase forward (horizontal) position, down to increase depth, and up to decrease depth. For example, this input:

forward 5
down 5
forward 8
up 3
down 8
forward 2

tells us that, if you move according to these commands from your starting point, you will be 15 forward and 10 deep. And the puzzle expects you to give it the product of these two numbers (150 in this case).

Here’s my code to solve it:

file = open('input.txt')
lines = file.read().splitlines()

x = 0
depth = 0

for line in lines:
    items = line.split()
    command = items[0]
    value = int(items[1])

    match command:
        case 'forward':
            x += value
        case 'down':
            depth += value
        case 'up':
            depth -= value

print(x * depth)

After Part 1 was solved, Part 2 presented a new element: aim. Similar to Part 1, but it has some modifications:

  • down X increases your aim by X units.

  • up X decreases your aim by X units.

  • forward X does two things:

    • It increases your horizontal position by X units.

    • It increases your depth by your aim multiplied by X.

So the code evolved:

file = open('input.txt')
lines = file.read().splitlines()

x = 0
depth = 0
aim = 0

for line in lines:
    items = line.split()
    command = items[0]
    value = int(items[1])

    match command:
        case 'forward':
            x += value
            depth += aim * value
        case 'down':
            aim += value
        case 'up':
            aim -= value

print(x * depth)

Huge Community

Man does this Advent of Code have a huge community! It has a DJ performing live when the puzzle started. Day 2 has people visualizing the problems like this one here. Folks have formed clubs, private leaderboards, and thinktanks to brainstorm and solve these puzzles together.

I expect to last ‘til December 25. Do you?


Advent of Code: Day 1

Leo Nguyen Dec 1, 2021

So this year I’m participating in the Advent of Code, a worldwide event that is only available in Christmas time and draws hundreds of thousands of developers to solve puzzles together. Anyone can register, no matter if you're a professional programmer, an IT student, or someone just learning to code.

Advent of Code starts on December 1 every year and runs through December 25, ending precisely on Christmas Day.

So for Day 1, we were presented with a problem called Sonar Sweep. You can read the puzzle here. In essence, we’re given a list of numbers and our goal is to find how many times the numbers increase from one number to the next.

I decided to use Python to solve this year’s puzzles. It’s a relatively new language to me and I think this is a great way to learn it along with the ride.

Here’s my very rudimentary code to solve the first puzzle:

file = open('input.txt')

lines = file.read().splitlines()
numbers = list(map(int, lines))

increases = 0

for i in range(len(numbers) - 1):
    if numbers[i + 1] > numbers[i]:
        increases += 1

print(increases)

This script gave me a result of 1665, which I submitted and thankfully it’s the correct answer.

Now the surprise part! Actually, when you’ve successfully solved a puzzle of a day, the second puzzle will show up. This newcomer is often based on the first puzzle, and in this case, it uses the exact same input. The requirement is a little different: We’re to find how many times the collection of 3 adjacent numbers increases from the beginning to the end. So, similar to the first puzzle, only in time we calculate 3 numbers at once.

Here’s my Python script to solve it:

file = open('input.txt')

lines = file.read().splitlines()
numbers = list(map(int, lines))

increases = 0

for i in range(len(numbers) - 3):
    if numbers[i + 1] + numbers[i + 2] + numbers[i + 3] > numbers[i] + numbers[i + 1] + numbers[i + 2]:
        increases += 1

print(increases)

This time the result was 1702, which got me the second star of the day.

That’s it for Day 1. The challenge is just starting.


Change a Big Project

Leo Nguyen Nov 19, 2021

League of Legends in the most popular video game in the world today. No other game in the entire human history has achieved the same level as League.

Then this link.

The question was completely valid:

Were keystones a rushed idea? There’s no HUD visibility for spectators, for example, and several champions came out of nowhere into the meta because they weren’t adjusted with the new keystones in mind.

What was Riot’s answer? It’s also completely valid:

In projects like this, you frequently find that technically 50% of the work is almost trivial to implement, and 50% of the work is an uphill climb in the snow. We do try to make sure features are in reasonable shape before releasing them, but we also try to be mindful of diminishing returns. If spectator support had taken two more months, does it make sense to hold the feature for two more months when we’re not even sure players will really like it?

The same holds true of champion balance. We could go through and rebalance every champion (a monumental task) but that could totally be throw-away work if the keystone feature ended up being poorly received by players and needed a lot more work or even scrapped. Instead, we tried to hit the outliers and champs we suspected would be a problem. Then we adjusted others over time as they showed up. This is pretty much the way we operate all of the time. We’d never be able to ship anything (including other balance changes) if we had to make a comprehensive pass at the entire game whenever we made changes. We definitely make a pass, but we don’t catch everything.

In big projects like this, whenever you make a change to it, things get tough. The moral of the story is, sometimes it makes sence to do just enough and ship out the product, then wait for feedback and make appropriate adjustments later. Don’t let this change make you change all the components of the project, from the very beginning up to now, which will take an expotentially long time to do, and if failed, you will waste tons of resources.