Below you will find pages that utilize the taxonomy term “Python”
Bron to Clique
Discovery of Bron-Kerbosch in AoC24-23
For part 2 of this challenge, I am actually ashamed of showing here what I initially tried to program without knowing what a clique was, nor that an algorithm existed to find the maximal cliques in a graph… Maybe one day when I add a Premium Pass to this blog, a few privileged users could see the pépite.

Part 1 - the piece of 🍰
As The Historians wander around a secure area at Easter Bunny HQ, you come across posters for a LAN party scheduled for today!
Maybe you can find it; you connect to a nearby datalink port and download a map of the local network (your puzzle input).
The network map provides a list of every connection between two computers. For example:
kh-tc
qp-kh
de-cg
ka-co
Each line of text in the network map represents a single connection; the line kh-tc represents a connection between the
computer named kh and the computer named tc. Connections aren't directional; tc-kh would mean exactly the same thing.
LAN parties typically involve multiplayer games, so maybe you can locate it by finding groups of connected computers.
Start by looking for sets of three computers where each computer in the set is connected to the other two computers.
If the Chief Historian is here, and he's at the LAN party, it would be best to know that right away. You're pretty
sure his computer's name starts with t, so consider only sets of three computers where at least one computer's name
starts with t. That narrows the list down to 7 sets of three inter-connected computers:
co,de,ta
co,ka,ta
de,ka,ta
qp,td,wh
tb,vc,wq
tc,td,wh
td,wh,yn
Find all the sets of three inter-connected computers. How many contain at least one computer with a name that starts
with t?
Initial Thoughts
Setting the “starts with t” requirement aside, the list of computers given is a list of edges connecting two computers (nodes).
Welcome to the Code Aviary: Where Ducks Debug and Canaries Die
Your survival guide to feathered philosophies in software development
Rubber Duck Debugging
Alright, we’re starting easy and light for this one.
It was popularised by the Pragmatic Programmer written by Andrew Hunt and David Thomas (an alumnus of Imperial College London). The idea is rather simple: instead of spending hours trying to debug something obscure, explain the code line-by-line to an inanimate object - a rubber duck named Chucky maybe? - to help you work out what the problem is.
Finishing your thoughts since... you started typing
Typeahead System
A little background
An autocomplete system, also called typeahead, is a feature often experienced by users while typing in a search bar (or your IDE for that matter). The software suggests the rest of a word or word sequence based on what the user has already typed.

These suggestions can be ranked depending on how often/popular a search is. Remember that gorgeous Versace dress J-Lo wore for the Grammy Awards back in 2000? Everyone googled it - in fact it became the most popular search query at the time and - fun fact - prompted Google engineers to develop the image search! The objective is to make user searches more efficient and reduce the amount of typing required, while keeping the suggestions relevant with current search trends.
No Huff and Puff—Just Compress!
The Huffman’s Algorithm
The Huffman’s algorithm was born in 1952 as a way to perform a lossless compression on data files. Its efficiency comes from the frequency analysis of characters present in the text to encode: shorter codes are used to encode more frequent characters while longer codes are used to encore less frequent ones.
It constitutes the foundation of modern text compression.
You can read more on variable-length encoding and tree representations under the Design tag on this blog.
`x = Pépin, y = x` I'm Pépin too, says y
Pass-by-Value or Reference: the Great Debate
Background on Heap and Stack
The stack referred to when talking about memory is the same as the run-time call stack. It is
composed of stack frames and stores things. It controls the function calls and program execution by
storing in its frames the function parameters, the return address, local variables - among other things.
The stack has a fixed-size so in some cases, for instance deep recursion, it can run out of memory.
Remember this one time you forgot a stopping condition in your code and got a StackOverflowError or
RecursionError: that’s the call stack telling you it’s full.
Stack frames only exist during the execution of a function. This means everything stored in it becomes
unavailable after the function has returned. This makes the allocation and de-allocation of memory
automatic, which helps prevent memory leaks.
Sorting Spree
LC23 - Merge k Sorted Lists
Problem Statement
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one sorted linked-list and return it.
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
Smelling like merge sort in the air?
We know each list is already in sorted order. Does it remind us of the merge step from a classic merge-sort algorithm?
Why compare when you can just count?
The Bucket Sort algorithm
LC75 - example of Sorting Colors
The problem statement is as below.
Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color
are adjacent, with the colors in the order red, white, and blue.
We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
You must solve this problem without using the library's sort function.
class Solution:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
# bucket sort
value_range = 3 #red, white or blue
counts = [0] * value_range
for i, n in enumerate(nums):
counts[n] += 1
i = 0
for value, freq in enumerate(counts):
print(value, freq)
for _ in range(freq):
nums[i] = value
i += 1
Quick rundown
The bucket sort algorithm relies on the fact that values belong to a known range. In this example it is [0,2] ∈ Z.
The input arrays have already been prepared, by encoding categorical values into numerical ones. The same
thing could be said about a different numerical range where the start of range is re-indexed or shifted back to 0.
Valentine's Matchmaker Algorithm 💖
LC765 - Couples holding hands
Problem Statement
There are n couples sitting in 2n seats arranged in a row and want to hold hands.
The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat.
The couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3),
and so on with the last couple being (2n - 2, 2n - 1).
Return the minimum number of swaps so that every couple is sitting side by side.
A swap consists of choosing any two people, then they stand up and switch seats.
Initial solution
The below solution provides an O(n) time complexity and memory. Relatively simply, checking for every pair of people, if the left-hand side person is not seated next to its beloved, then we swap the right person next to them.
AoC24 - Some stone blinking
Who said AoC25-11 should be complicated?
The Challenge
The ancient civilization on Pluto created stones that change every time you blink. Each stone follows specific transformation rules:
- A stone marked 0 becomes 1.
- A stone with an even number of digits splits into two stones, each half of the original number.
- Any other stone is replaced by a new one, with its number multiplied by 2024.
The stones remain in order, and their transformations continue with each blink. For example, the sequence [0, 1, 10, 99, 999] would change to [1, 2024, 1, 0, 9, 9, 2021976] after one blink.
Part 1: blink 25 times. Part 2: blink 75 times.
Full description available here.