Welcome to the Code Playground! This solution contains multiple projects, each addressing a different problem or functionality. The projects included are:
- Percolation Problem
- Social Network Connectivity
- Egg Drop Problem
- Color Converter
This Code Playground allows you to explore and experiment with various algorithms and data structures implemented in these projects. Each project is designed to solve a specific problem, and you can run and modify the code to see how it works.
The Percolation Problem project simulates a percolation system using a grid. The goal is to determine if the system percolates, meaning there is a path from the top to the bottom of the grid through open cells.
- Program.cs: Contains the main logic for simulating the percolation system.
- UnionFind.cs: Implements the union-find data structure with path compression and union by rank.
- Open the solution in Visual Studio.
- Set the
PercolationProblem
project as the startup project. - Run the project.
Main(string[] args)
: Entry point of the application.MakeMatrixPercolateAndTest()
: Simulates the percolation process and tests if the system percolates.PrintMatrix(UnionFind uf, int virtualTopIndex)
: Prints the current state of the matrix.GenerateMatrix(int size, int maxWaterCells)
: Generates a random matrix with open and blocked cells.PerformPercolationTest()
: Tests if the system percolates.
The Social Network Connectivity project determines the earliest time at which all users in a social network are connected based on a series of connection events.
- Program.cs: Contains the main logic for reading connection data and determining connectivity.
- UnionFind.cs: Implements the union-find data structure with path compression and union by rank.
- FileManager.cs: Manages reading and writing connection data to and from a file.
- ConnectionChecker.cs: Contains the logic to determine the earliest time all users are connected.
- Open the solution in Visual Studio.
- Set the
SocialNetworkConnectivity
project as the startup project. - Run the project.
Main(string[] args)
: Entry point of the application.SetAmount()
: Sets the number of users and connections.GenerateConnections()
: Generates random connections between users.EarliestTime(int numberOfUsers, HashSet<Connection> connections)
: Determines the earliest time all users are connected.
The Egg Drop Problem project solves the classic egg drop problem, which involves determining the minimum number of trials needed to find the highest floor from which an egg can be dropped without breaking.
- Program.cs: Contains the main logic for solving the egg drop problem.
- EggDrop.cs: Implements the algorithms for solving the egg drop problem.
- Open the solution in Visual Studio.
- Set the
EggDropProblem
project as the startup project. - Run the project.
TwoEggDropProblem(int numberOfFloors)
: Solves the two-egg drop problem.MultiEggMultiFloorEggDropProblem(int numberOfFloors, int numberOfEggs)
: Solves the multi-egg, multi-floor egg drop problem.
The Color Converter project provides utilities for printing text in random colors in the console.
- ColorConsoleExtensions.cs: Contains extension methods for printing text in random colors.
- Open the solution in Visual Studio.
- Set the
ColorConverter
project as the startup project. - Run the project.
PrintRandomColor(string text, bool colorForeground = true, bool colorBackground = false)
: Prints text in random colors.
The UnionFind
class is used by multiple projects to manage disjoint sets efficiently. It supports path compression and union by rank to optimize the union-find operations.
UnionFind(int size)
: Initializes the union-find data structure.int Find(int x)
: Finds the root of the elementx
with path compression.bool Union(int x, int y)
: Unites the sets containingx
andy
.int Count()
: Returns the number of disjoint sets.
- Open the solution in Visual Studio.
- Build the solution to restore dependencies and compile the projects.
- Set the desired project as the startup project.
- Run the project.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please fork the repository and submit pull requests for any enhancements or bug fixes.
For any questions or issues, please open an issue in the repository or contact the project maintainers.