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

You are not logged in.

## #51 2011-10-05 07:34:26

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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
The knowledge of some things as a function of age is a delta function.

Offline

## #52 2011-10-05 07:35:46

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

Okay, did you fix the infinite loop?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #53 2011-10-05 07:37:48

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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
The knowledge of some things as a function of age is a delta function.

Offline

## #54 2011-10-05 07:38:36

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #55 2011-10-05 07:40:08

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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
The knowledge of some things as a function of age is a delta function.

Offline

## #56 2011-10-05 07:41:52

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #57 2011-10-05 07:42:51

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #58 2011-10-05 07:47:41

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #59 2011-10-05 07:53:38

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #60 2011-10-05 07:58:24

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #61 2011-10-05 08:02:16

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #62 2011-10-05 08:08:20

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #63 2011-10-05 08:11:36

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #64 2011-10-05 08:13:12

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #65 2011-10-05 08:15:32

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

i don't really understand the question.

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
The knowledge of some things as a function of age is a delta function.

Offline

## #66 2011-10-05 08:16:56

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

``````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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #67 2011-10-06 03:36:14

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #68 2011-10-06 03:53:27

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #69 2011-10-06 05:22:03

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

'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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #70 2011-10-06 05:49:35

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #71 2011-10-06 05:57:43

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #72 2011-10-06 07:59:46

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

When is the first error?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #73 2011-10-07 01:36:24

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #74 2011-10-07 01:41:42

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,435

### Re: Another programming problem!!!

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #75 2011-10-07 01:45:42

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,030

### Re: Another programming problem!!!

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## Board footer

Powered by FluxBB