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

You are not logged in.

## #51 2011-10-06 06:34:26

anonimnystefy
Real Member

Offline

### Re: Another programming problem!!!

i wrote it.i would never lie to you.

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

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #52 2011-10-06 06:35:46

bobbym

Online

### Re: Another programming problem!!!

Okay, did you fix the infinite loop?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #53 2011-10-06 06:37:48

anonimnystefy
Real Member

Offline

### 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!

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #54 2011-10-06 06:38:36

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #55 2011-10-06 06:40:08

anonimnystefy
Real Member

Offline

### 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

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #56 2011-10-06 06:41:52

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #57 2011-10-06 06:42:51

anonimnystefy
Real Member

Offline

### Re: Another programming problem!!!

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

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #58 2011-10-06 06:47:41

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #59 2011-10-06 06:53:38

anonimnystefy
Real Member

Offline

### 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:

#### Code:

```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-06 06:53:57)

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #60 2011-10-06 06:58:24

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #61 2011-10-06 07:02:16

anonimnystefy
Real Member

Offline

### 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!

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #62 2011-10-06 07:08:20

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #63 2011-10-06 07:11:36

anonimnystefy
Real Member

Offline

### 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.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #64 2011-10-06 07:13:12

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #65 2011-10-06 07:15:32

anonimnystefy
Real Member

Offline

### Re: Another programming problem!!!

i don't really understand the question.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #66 2011-10-06 07:16:56

bobbym

Online

### Re: Another programming problem!!!

#### Code:

```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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #67 2011-10-07 02:36:14

anonimnystefy
Real Member

Offline

### 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:

#### Code:

```program Sudoku_solver;

{\$mode objfpc}{\$H+}

uses
{\$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;

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;
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
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!!!');
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'.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #68 2011-10-07 02:53:27

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #69 2011-10-07 04:22:03

anonimnystefy
Real Member

Offline

### 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.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #70 2011-10-07 04:49:35

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #71 2011-10-07 04:57:43

anonimnystefy
Real Member

Offline

### 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.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Online

### Re: Another programming problem!!!

When is the first error?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #73 2011-10-08 00:36:24

anonimnystefy
Real Member

Offline

### 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

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #74 2011-10-08 00:41:42

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #75 2011-10-08 00:45:42

anonimnystefy
Real Member

Offline

### 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.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment