This C# project contains a brute-force algorithm to solve a magic hexagon puzzle of order 3.
A magic hexagon of order n is an arrangement of numbers in a hexagonal pattern with n cells on each side, such that the sum of the numbers in each row (in all three directions) is the same. This constant sum is called the magic constant.
This specific solver finds a solution for an order-3 hexagon using the integers from 1 to 19. The magic constant required for this puzzle is 38.
The program uses a brute-force approach to find a valid arrangement of the numbers. It iterates through all possible permutations of the numbers 1 through 19, placing them in the 19 cells of the hexagon. For each permutation, it checks if the sum of the numbers in every row equals the magic constant of 38.
Due to the massive number of permutations, this method is computationally intensive but will eventually find a solution.
- Compile the
brutacsharp.csfile using a C# compiler (likecscfrom the .NET SDK).csc brutacsharp.cs
- Execute the compiled program.
brutacsharp.exe
The program will print "Success" followed by the 19 numbers in their correct positions for the magic hexagon. It will also display the total time taken to find the solution.