Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

i wrote it.i would never lie to you.

btw the name of the function is 'vrsta'.sorry.

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

Okay, did you fix the infinite loop?

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

yes i did.

the problem is that it solves only the first line.actually it tries to solve,but doesn't mean that the final solution is like that.

it won't go to the next line and i don't know why!

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

Copy the code that you think is causing the problem. The minimum amount please.

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

i don't know the code where the problem is in.if i did i would probably know how to correct it.but i don't

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

You said you fixed it. Where did you do the fixing? Did your friend tell you about where?

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

no i fixed the infinite loop problem.but there is still this one.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

Do you know the part of the code that handles the rows?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

part of the code in the sudoku procedure finds the first element equal to 0,because the spaces are represented that way.

here it is:

```
while (b=true) and (i<=max) do
begin
i:=i+1;
while (b=true) and (j<=max) do
begin
j:=j+1;
writeln(i);
writeln(j);
if a[i][j]=0 then
b:=false;
end;
```

but i don't see the problem.

*Last edited by anonimnystefy (2011-10-05 07:53:57)*

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

That looks like code to print the answer.

but i don't see the problem.

I do not think you are understanding me. Looking can only find syntax errors. The compiler finds them too. To find logic errors you have to single step through a piece of code.

You can do it by hand or by using the debugger. There is no other way.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

i do it in my head.and i understand you perfectly.

the writeln(i/j) statements are printing how i and j change.that's what you told me to do!

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

That is where you are not following me. I say there is only 2 ways and you try to come up with a third way! But let's forget that for right now.

Is this all you put in?

writeln(i);

writeln(j);

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

you said to print out values of i and j.

besides that it finds the place of the first zero element,so it can try out different values for it.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

But you did not answer the question, are those the only two lines you put in?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

i don't really understand the question.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

```
while (b=true) and (i<=max) do
begin
i:=i+1;
while (b=true) and (j<=max) do
begin
j:=j+1;
writeln(i);
writeln(j);
if a[i][j]=0 then
b:=false;
end;
```

In the above routine which is what I told you to put in?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

hi bobbym

sorry for not answering right away,but in my head i pictured you being frustrated,so i thought i should lay of for a day.

i don't think it matters anymore.a problem was that j was stuck at 10 and i should have set it to 1 every time i entered the outer loop.anyway here's the new code:

```
program Sudoku_solver;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
{$IFDEF WINDOWS}{$R Sudoku.rc}{$ENDIF}
const
max=9;
type
niz=array[1..max] of integer;
matrica=array[1..max] of niz;
var
a:matrica;
i,j,k:integer;
ok:boolean;
function red(a:matrica;i1,j1:integer):boolean;
var
j:integer;
b:boolean;
begin
b:=true;
j:=1;
while (j<=max) and (b=true) do
begin
if j<>j1 then
if a[i1][j]=a[i1][j1] then
b:=false;
j:=j+1;
end;
red:=b;
end;
function kolona(a:matrica;i1,j1:integer):boolean;
var
i:integer;
b:boolean;
begin
b:=true;
i:=1;
while (i<=max) and (b=true) do
begin
if i<>i1 then
if a[i][j1]=a[i1][j1] then
b:=false;
i:=i+1;
end;
kolona:=b;
end;
function kvadrat(a:matrica;i1,j1:integer):boolean;
var
i,j,k,l:integer;
b:boolean;
begin
b:=true;
case i1 of
1,2,3: begin
k:=1;
i:=3;
end;
4,5,6: begin
k:=4;
i:=6;
end;
7,8,9: begin
k:=7;
i:=9;
end;
end;
while (k<=i) and (b=true) do
begin
case j1 of
1,2,3: begin
l:=1;
j:=3;
end;
4,5,6: begin
l:=4;
j:=6;
end;
7,8,9: begin
l:=7;
j:=9;
end;
end;
while (l<=j) and (b=true) do
begin
if (k<>i1) or (l<>j1) then
if a[k][l]=a[i1][j1] then
b:=false;
l:=l+1;
end;
k:=k+1;
end;
kvadrat:=b;
end;
function poz(a:matrica;i,j:integer):boolean;
begin
poz:=red(a,i,j) and kolona(a,i,j) and kvadrat(a,i,j);
end;
procedure sudoku(var a:matrica;n,i1,j1:integer;var ok:boolean);
var
i,j,k:integer;
b:boolean;
begin
i:=i1;
j:=j1;
a[i][j]:=n;
ok:=false;
if poz(a,i,j) then
begin
ok:=true;
i:=1;
b:=true;
while (b=true) and (i<=max) do
begin
j:=1;
while (b=true) and (j<=max) do
begin
writeln(i);
writeln(j);
if a[i][j]=0 then
b:=false
else j:=j+1;
end;
if b=true then
i:=i+1;
end;
if b=false then
begin
k:=1;
ok:=false;
while (k<=max) and not ok do
begin
sudoku(a,k,i,j,ok);
k:=k+1;
end;
end;
end;
end;
begin
writeln('Unesite sudoku: ');
for i:=1 to 9 do
begin
for j:=1 to 9 do
read(a[i][j]);
readln;
end;
for i:=1 to 9 do
begin
for j:=1 to 9 do
write(a[i][j],' ');
writeln;
end;
k:=0;
ok:=false;
while (k<=9) and not ok do
begin
k:=k+1;
sudoku(a,k,1,1,ok);
end;
if ok then
begin
writeln('Resenje je: ');
for i:=1 to 9 do
begin
for j:=1 to 9 do
write(a[i][j],' ');
writeln;
end;
end
else writeln('Sudoku se ne moze resiti!!!');
readln;
end.
```

but this time the problem seems to be that the functions for checking if a number can be in the given row column and square aren't doing what they should.those are 'red','kolona' and 'kvadrat'.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

Hi;

Put some write statements in there. Make sure the indices line up. And for heavens sake please learn how to use the debugger.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

'Put some write statements in there.' - why?

'indices' - what?

'And for heavens sake please learn how to use the debugger.' - if by that you mean using 'step into' and watches then i do.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

i and j are called indices. Make sure you are cycling through every element of the matrix.

If you can use it then why aren't you?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

i tested the first few elements,but this problem seems like it's something to do with nines.

i tried it.but there's too much to go until the first mistake.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

When is the first error?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

hi bobbym

i had to go to sleep

for example if i put in:

0 2 0 0 0 9 1 4 6

9 0 6 8 0 0 0 0 2

0 5 0 6 0 0 9 0 0

0 0 0 4 9 0 7 0 0

0 0 5 7 6 8 4 0 0

0 0 3 0 2 1 0 0 0

0 0 8 0 0 4 0 9 0

7 0 0 0 0 5 2 0 4

2 4 1 9 0 0 0 3 0

it puts out:

8 2 9 9 9 9 1 4 6

9 1 6 8 4 9 9 9 2

3 5 4 6 1 2 9 7 8

6 9 9 4 9 9 7 9 9

9 9 5 7 6 8 4 1 3

4 7 3 5 2 1 8 9 9

5 6 8 9 9 4 9 9 9

7 9 9 1 3 5 2 6 4

2 4 1 9 8 9 9 3 9

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,879

Hi;

No problem. The first row is obviously wrong. Too many nines! Each row has that problem.

You can start there. Do you want the answer to that sudoku?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,673

hi

all rows are obviously wrong,which means that the columns and squares are obviously wrong.don't you think i already know that?isn't it obvious.i told you that there is problem around nines.

nah,i want it to put out a random matrix that will have the elements that i have put in but that it has a lot of nines...of course i do.that's why it is called Sudoku_solver.

Here lies the reader who will never open this book. He is forever dead.

Offline