
Here to give you guys a good read, in a different way with each blog. Not a niche-specific blogger. To be honest, I'm just blogging with the aim of applying knowledge to achieve practical goals.
Search for a command to run...

Here to give you guys a good read, in a different way with each blog. Not a niche-specific blogger. To be honest, I'm just blogging with the aim of applying knowledge to achieve practical goals.
No comments yet. Be the first to comment.
The advent of Code is an annual programming challenge event that occurs throughout the month of December. It was created by Eric Wastl and consists of a series of daily small programming puzzles.
Yet again as always while trying to solve the problem statement, logically I can easily do that but again I got lost on how to do the input processing. No idea let's look at it. For example, suppose the Elves finish writing their items' Calories and ...
Make a Github repo, and push the code to the repo. Login to the server by SSH Check if git is installed or not at the server, if not sudo apt update sudo apt install git Generate an SSH key on the VPS server, To establish a secure con...
If you're trying to install Node.js on your Ubuntu machine, you may have noticed that the version of Node.js you get is not always the latest one available. You might be wondering why that is the case. So why this happens? When you install Node.js on...

Hey there, In the past few days, I have been seeing here everyone is talking about debugging. I like the way Hashnode gives these writing goals which indeed will result in more technical writers. So here I am talking about the Debugging too. But let'...

Hey there, let me tell you something. I was tired of constantly switching between different operating systems on my computer. Windows for photoshop, Linux for coding - it was a never-ending cycle that I just couldn't seem to escape. That's why I deci...

This year, I've got a paper to write in Python, so I thought, why not choose Python for AOC as well? Again I need to go through the syntax and learn how we structure our ideas. So let's begin.
Challenges can be found here.
The Day 1: Trebuchet. Before doing that I need to update my local machine with my AOC GitHub repo, which has the solutions of previous years. Even last year I was not able to find time to do all the challenges. This time around, I aim to complete all the challenges. If you happen to come across this blog, please drop a reminder in the comments if I forget the deadline to submit my solutions. Thanks!
The plan so far looks simple, it's all about how the elves plan to lift up. They've got a tricky method, making the ride not as simple as it seems. Let's help them calibrate.
The input looks like this, and all we need to do is split it at the new line.
1abc2
pqr3stu8vwx
zoneight234
7pqrstsixteen
I guess we need to look at the first letters until we find a number, then go backward from the end until we find another number. For now, this is the idea that I can come up with.
def find_first_last_digits(input_string):
digits = [int(character) for character in input_string if character.isdigit()]
if digits:
first_digit = digits[0]
last_digit = digits[-1]
return int(first_digit), int(last_digit)
else:
return None, None
digits ➡️ It goes through each character in the sentence to see if it's a number and saves it.
Then we get first and last by index.
Elves use super logical codes, and the part of strings that we need to decode has words like "one," "two," and "three" instead of digits. So our earlier logic won't work here. I guess we could go for search and replace.
This will be slow as we will be searching for each string and then replacing it. Please do share if you have better solutions than these.
for str2 in lines:
str2 = str2.replace("one","o1ne")
str2 = str2.replace("two","t2wo")
str2 = str2.replace("three","th3ree")
str2 = str2.replace("four","fo4ur")
str2 = str2.replace("five","fiv5e")
str2 = str2.replace("six","si6x")
str2 = str2.replace("seven","sev7n")
str2 = str2.replace("eight","e8ight")
str2 = str2.replace("nine","nin9e")
first, last = find_first_last_digits(str2);
sum2 = sum2 + (first * 10) + last
Day 2: Cube Conundrum, Challenge can be found here. So we're in the sky now, a place called Snow Island and it has very little snow. The Elf who is about to accompany us offers to play a game with us.
For example input I tried by using Dictionary. We need to find how to process that input from a file. I find this more challenging at times.
with open('/home/nisnym/t/practice/Advent-of-Code/2023/Day 2/input.txt', 'r') as file:
# Read all lines from the file
lines = file.read().split('\n')
game_datas = {}
for line in lines:
# game_info = line.split("Game")
game_info = line.split(": ")
game_number = game_info[0][5:]
game_data = game_info[1].split("; ")
# print(game_number)
game_results = []
for result in game_data:
colors_counts = result.split(", ")
color_dict = {color: int(count) for count, color in [cc.split() for cc in colors_counts]}
game_results.append(color_dict)
game_datas[game_number] = game_results
Below compare the game_data Dictionary with the given values for possible games.
Let's figure out the games possible with 12 red cubes, 13 green cubes, and 14 blue cubes in the bag. After that, we'll add up the game IDs.
target_counts = {'red': 12, 'green': 13, 'blue': 14}
possible_games = []
for game_no, game_round in game_datas.items():
valid_games = True
for ins in game_round:
for color, count in ins.items():
if color not in target_counts or count > target_counts[color]:
valid_games = False
break
if valid_games:
possible_games.append(int(game_no))
The elf is creating things for himself now. The above conditions don't matter here now. All we need to do is to find the minimum number of balls needed for Game N to happen. This means that we need to find the max of every set and then finding the total sum of it.
answer = 0
for game_id, rounds in game_datas.items():
max_colurs = {'red': 0, 'green': 0, 'blue': 0}
for dict in rounds:
for color, count in dict.items():
max_colurs[color] = max(count,max_colurs[color])
answer += max_colurs['blue'] * max_colurs['green'] * max_colurs['red']
print(f"the power is {answer}")
Day 3: Gear Ratios, Challenge can be found here. After reaching the Gondola Lift, it doesn't work. Looks like everything is broken and now we need to help the Engineer Elf to fix the machine.