A long time ago, when someone mistakenly broke fiber-optic cable of my office and I had to wait there with no connection all day long. After I tried to get rid of playing sudoku game on Ubuntu, I decided to make my own game. I did not expect that it would be that complex. Anyways, it was a simple class until this morning but I decided to modernize and improve it with Scrutinizer-CI. It's also composer
friendly now. So I hope you think that, it deserves to be shared.
Before I start
Commits of the Day
New Features
- Composer compatibility added
Packagist link is here. - PHPDocs added
Related commit link is here.
Improvements
- Scrutinizer-CI rank improvement
- Bug fixes to improve Scrutinizer-CI rank
- Sample usage added
Installation
Run the command in your project folder:
composer require frnxstd/sudoxu
And then introduce your class to your code
use Sudoxu\Sudoku;
$Sudoku = new Sudoku();
And run the code!
$json = $Sudoku->generate('json');
$array = $Sudoku->generate('array');
$serialize = $Sudoku->generate('serialize');
Would you like to see it in action? You can check out sudoxu.com and it has jQuery flavor for a better user experience. By the way, it also provides better development experience.
Algorithm
Basically generate() function makes everything in a row. I will explain the steps one-by-one
- It loops until it's solved in while()
- Finds available
items
(we use numbers 1 to 9 in this example) to place - In previous step, it finds the items, these are going to be unique in the row, column and in the block
- It tries one of available items
- If it's all okay, pushes into an array and keeps on looping until
Sudoku::is_solved_sudoku()
returnstrue
How to contribute?
The code is able to create up to 6^2 sudokus with extra characters rather than numbers. But I do have performance issue here. If anyone could help me to solve this complexity, we could create deeper sudokus.
Proof-of-work
Kind regards!
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
Very informative, I like the level of details you went into.
I was not able to build the project as per the README but rather doing a simple
composer install
.You can contact us on Discord.
[utopian-moderator]
Dear helo!
Thanks for your feedback. Actually it was not a bug, it was about the released version. It was not marked as stable. But it has no security issue from my point of view so I marked it as stable. So I want you to clear your composer cache with following code
then give a try once again
see my terminal window below,
thanks advance!
Hey @ikidnapmyself I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x