FatimaAli10
Badges: 5
Rep:
?
#1
Report Thread starter 6 months ago
#1
Hi,
i am just trying to attempt with this extension task that was just given by my tutor to try but i am not sure how to tackle this
attachment is attached can someone help me so in future i'll be ready to do these when we learn about this. Its not like a class task its just for us to try so i really wanna try this.
much appreciated
thanks
Last edited by FatimaAli10; 5 months ago
0
reply
FatimaAli10
Badges: 5
Rep:
?
#2
Report Thread starter 6 months ago
#2
anyone to help me
0
reply
winterscoming
Badges: 19
Rep:
?
#3
Report 6 months ago
#3
Consider each of the problems that you need to tackle one-by-one and attempt to solve them individually. Maybe even solve them in separate programs. Remember that you don't need the full program in order to write one part of it - for example, you could write a program with some "hard-coded data" (i.e. data which is written into the code itself, such as a list or string, and not from a file or user) just to write and test one small function by itself.

The first thing to do is to choose a sensible data structure (e.g. a list) to store your numbers in. You could store it all in a single list, or you could store it in a "9x9" list-of-lists, whichever you feel is easier to visualise and work with. ). You should only need to read it once at the beginning of your program, then keep it in memory.

Next, solve the problem of reading the file into that "shape" (e.g. a list of 81 items, or list-of-9x9-lists). Have a search on Google for how to read numbers from a file into a list using Python - you will find loads of examples on StackOverflow. You might even find some which actually use sudokus as an example.

Next, consider writing separate functions which tackle each of the 'rules' of a sudoku. For example

- Take a 3x3 "grid" and check that each number from 1-9 appears exactly once (Remember a 3x3 grid could also be represented in Python as a simple list of 9 numbers.. your python data structure does not need to look the same as the physical real-world structure. Again, simple is usually better than complex)
- Take a "row" of 9 numbers and check that each number from 1-9 appears exactly once
- Take a "column" of 9 numbers and check that each number from 1-9 appears exactly once


(If you're paying attention, you might see that all 3 of these problems are actually the same programming problem, albeit phrased/framed in 3 different ways - but just because they mean different things in plain English doesn't mean the code for them needs to be different).

Consider how to pick a subset of numbers from the stored sudoku data - e.g. how would you just grab a 'row' of 9 numbers? or a 'column' of 9 numbers? or one of the '3x3 grids' (which is also 9 numbers..) -- it may be easier to solve everything in terms of those individual subsets.

Remember with programming, if you can solve a problem once, then you can repeat that solution as many times as you like, so always solve the simple case first without repetition - e.g. if you can solve for one row, then you already have the solution for all rows.

Lastly, do some Google research to see what kind of ideas other people have done - try searching something along the lines of "Python sudoku checker"
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • Regent's University London
    Postgraduate Open Evening Postgraduate
    Thu, 19 Sep '19
  • Durham University
    Pre-Application Open Days Undergraduate
    Fri, 20 Sep '19
  • Loughborough University
    Undergraduate Open Day Undergraduate
    Fri, 20 Sep '19

What's your favourite genre?

Rock (143)
24.49%
Pop (142)
24.32%
Jazz (26)
4.45%
Classical (32)
5.48%
Hip-Hop (103)
17.64%
Electronic (42)
7.19%
Indie (96)
16.44%

Watched Threads

View All