Fading Coder

One Final Commit for the Last Sprint

Solutions to CSP-S 2021 Programming Competition Problems

Solutions to CSP-S 2021 Programming Competition Problems Problem 1 Solution The problem involves resource allocation between two regions. If we precompute f₁, f₂, ..., fₘ₁ where fᵢ represents the maximum number of resources allocated to the domestic region with i resources, then fᵢ₊₁ will always inc...

Counting Unique Paths in a 2D Grid Matrix

Consider a scenario where an automated agent is situated at the top-left corner of a grid defined by m rows and n columns. The agent is strictly limited to movements either towards the right or downwards. The task is to calculate the total number of distinct routes the agent can take to arrive at th...

Sudoku Solver: Data Structures and Search Optimizations

Core Data Structures for Sudoku Solving When implementing a Sudoku solver, the key decision is how to represent placement constraints. A naive approach uses a 3D boolean array can[i][j][num] to indicate whether a number can be placed at position (i, j). While intuitive, this representation has a cri...

Dynamic Programming and Algorithm Problems Collection

Dynamic Programing Coin Change Problem def coin_change(coins, amount): dp = [float('inf')] * (amount + 1) dp[0] = 0 for coin in coins: for x in range(coin, amount + 1): dp[x] = min(dp[x], dp[x - coin] + 1) return dp[amount] if dp[amount] != float('inf') else -1 Predict the Winner def predict_winner(...

Optimizing Cryptarithmetic Puzzles in C: Iterative vs. Recursive Strategies

Naive Brute Force ImplementationThe initial approach involves utilizing nested loops to generate all possible permutations of the digits 1 through 9. This method iterates through every possible assignment for the nine variables representing the equation ABC + DEF = GHI. For each permutation, it chec...

Core Sorting Algorithms and Lua Patterns for Unity Engineers

Bubble Sort Implementation This algorithm iterates through the dataset multiple times, swapping adjacent elements if they are in the wrong order. An optimization flag is included to terminate early if the list becomes sorted before all passes complete. public static void ExecuteBubbleSortion(int[] d...

Implementing and Optimizing Shell Sort in C

Shell sort, often referred to as the diminishing increment sort, is a non-comparison based refinement of the insertion sort algorithm. By breaking the original list into several smaller sub-lists based on a specific gap, the algorithm sorts these sub-lists independently using insertion sort. As the...

N-Queens Problem: Five Recursive Approaches with Progressive Optimizations

Problem Statement Place N queens on an N×N chessboard such that no two queens threaten each other — i.e., no two share the same row, column, or diagoanl. 1. Basic Backtracking A straightforward recursive backtracking approach places one queen per row and validates column and diagonal constraints bef...

Eight Core Patterns for Arrays and Linked Lists

Array Manipulation Merge Sorted Arrays In-Place Given two integer arrays sorted in non-decreasing order, combine them into a single sorted sequence stored inside the first array. The first array has enough trailing buffer (initialized to zero) to hold all elements from the second array. Start fillin...

Solving Step-Climbing Problems with Dynamic Programming

Dynamic programming (DP) is an algorithmic technique for solving problems that exhibit overlapping subproblems and optimal substructure. Overlapping subproblems mean the same smaller instances are solved repeatedly, while optimal substructure implies that an optimal solution to the larger problem ca...