#Weekly Lua Challenge #01 - Sudoku Solver

1 messages · Page 1 of 1 (latest)

hard merlin
#

I'm not Spar - but I do like his lua challenge and it inspired me to do something similar. I'm going to (if I remember) post a weekly little challenge to maybe spark a bit of fun/discussion, talk about various methods - and hopefully give some new developers an idea for something to help them learn.

The 'Challenge': Sudoku Solver

Write a Lua function to solve a given Sudoku puzzle. The function should take a [9][9] table, where empty zells are represented by zeros. The function should fill the grid (change the zeros) to it's corresponding number based on the traditional rules of Sudoku and then print the solved grid

Rules/Requirements:

  • Your function should be called solveSudoku and take only a single argument, the board table. solveSudoku(board)
  • No outside libraries should be used
  • The puzzle should return true if the puzzle is solved, otherwise false if not.
  • You can use glua syntax/functions if you want

Bonus/show-off points:

  • Solve in the least amount of iterations to solve possible
  • Generate a sudoku table based on a difficulty (you chose how many)
  • Nice output (honestly go wild, I'm prepared to see some cool ASCII grids)
  • Handle multiple solutions
  • Handle impossible boards

The base code:

local board = {
    {0, 3, 2, 6, 0, 5, 4, 7, 0},
    {5, 0, 0, 0, 3, 0, 0, 0, 0},
    {7, 0, 0, 0, 0, 0, 0, 0, 8},
    {2, 5, 0, 0, 0, 0, 0, 0, 0},
    {0, 4, 0, 0, 0, 0, 0, 0, 6},
    {8, 0, 0, 9, 2, 0, 0, 0, 5},
    {0, 2, 0, 5, 0, 0, 0, 1, 3},
    {0, 0, 0, 3, 0, 0, 6, 0, 7},
    {0, 8, 0, 0, 9, 7, 0, 5, 4}
}

function solveSudoku(board)
    -- TODO: implement
    return false
end

solveSudoku(board)

p.s the example board is 100% solvable, I did it myself.. manually..

hard merlin
#

Update: Nobody was interested 😦 I think this would be a good fun code exercise so I'm willing to offer a small cash incentive for different categories.

Prizes
Least lines* of code: $5 USD
Most efficient (least iterations* to solve current base sudoku board): $5 USD

Rewards will be provided via PayPal or steam wallet ONLY - by choice of winner per category

Judging
To avoid bias or any form of favouritism, @twilit walrus has offered to judge the winners by category.
Entries close 1 week after the initial posting of the challenge (Entries close: <t:1719270120:R>)
If any other moderators of this discord wish to be involved *cough* @real vine *cough* please reach out :)

Submissions
You may submit multiple solutions, however, you must pick which one is your primary one to be judged - this is global for the challenge, you cannot submit one submission for one prize category, and one for another.
Your most recent submission OR message clarifying which one is your primary submission by the time of the end date is the one that will be judged.
Submissions must be sent to myself privately OR in this thread - these will be then collected at the time of judging.

#

@twilit walrus pin the first and last msg pls

hard merlin
#

Small print
Least lines of code prize requires code to be REASONABLY written. This means you cannot cram multiple lines of code into a single line. (no ; or minification!)
'Iterations'* means a run-through of a scope, this includes recursive function calls, loops etc.
I'm broke ok, 10$ a week is all I can afford - five bucks is five bucks
Do not edit your message containing your submission - this rules out any potential code swapping (unlikely, but you never know these days)
If there aren't enough submissions, and we do not deem the code to be of enough quality to meet a prize category, it will not win by default - there will simply be no winner.
You may use my solution as an example, however code deemed too close/similar will be disqualified.
If you can think of a loophole, you'll probably be disqualified - if unsure, ASK!
Judges may enter, but their submission will not be considered for any prizes (sorry)

#

p.s y'all are welcome to talk in this thread..

terse merlin
#

what the rizz

hard merlin
# terse merlin what the rizz

ong post a submission you have a very high chance of being a winner rn if nobody else submits lmao free five bucks

terse merlin
void fractal
#

imma try this even tho i have 0 experience in lua 🔥

#

where can i see sudoku rules

hard merlin
void fractal
#

thx

hearty marlin
#

Love the idea but I've got no time for this. Would be happy to see some community engagement.

hard merlin
dry river
#

@hard merlin how is the table formatted

#

is each row in the table a square in the sudoku board or is it meant to be read like an actual sudoku board

hard merlin
#

So the table visually looks like how it would be on a sudoku board

dry river
#

why make it a 2d table then smh

hard merlin
#

For the glory of satan

#

(With each row being its own table it makes one of the checks significantly easier)

dry river
#

it'd be just as easy with a 1d table with the benefits of being faster and using less memory

hard merlin
#

Were talking about saving a few bytes or memory

#

I paid for them all ima use them all

dry river
#

we're talking about skipping out on an entire for loop

#

if you use a 1d table you can get the x,y with a single for loop

hard merlin
#

good point. however, this is where creative design comes in

dry river
#

am I allowed to change the base code or do I have to convert it to a 1d table myself

hard merlin