Skip to content

A C# brute-force solver for the order-3 magic hexagon puzzle. This university project finds the arrangement of numbers 1-19 where all rows sum to 38, demonstrating combinatorial algorithm design and performance considerations.

Notifications You must be signed in to change notification settings

NachoLZ/magic-hexagon-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Magic Hexagon Solver

This C# project contains a brute-force algorithm to solve a magic hexagon puzzle of order 3.

The Puzzle

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.

Algorithm

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.

How to Run

  1. Compile the brutacsharp.cs file using a C# compiler (like csc from the .NET SDK).
    csc brutacsharp.cs
  2. 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.

About

A C# brute-force solver for the order-3 magic hexagon puzzle. This university project finds the arrangement of numbers 1-19 where all rows sum to 38, demonstrating combinatorial algorithm design and performance considerations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages