Math Is Fun Forum

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

You are not logged in.

#26 2011-09-30 22:47:42

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

Re: Another programming problem!!!

Hi;

Do you know how to use them?


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

#27 2011-09-30 22:49:31

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

Re: Another programming problem!!!

yes,but it takes so long!

anyway i noticed that the program acts weirdly around ones.


“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

#28 2011-09-30 22:54:42

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

Re: Another programming problem!!!

Hi anonimnystefy;

I know it takes a long time. Debugging a program is a very personal thing. You have to single step through the program checking the variables after each step. Or go through your code by hand writing down what each line does. Seeing whether or not it actually does what you think it should. Then you will find the offending line. 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

#29 2011-09-30 23:24:47

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

Re: Another programming problem!!!

but,do you know why the program won't go to the next line?


“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

#30 2011-09-30 23:29:48

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

Re: Another programming problem!!!

Hi;

Probably because your looping structure is not going throw every row like it is supposed to. Check your loops or your recursive subroutine.


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

#31 2011-09-30 23:35:57

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

Re: Another programming problem!!!

checked the loops,seem okay.

what's recursive subroutine?


“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

#32 2011-09-30 23:40:58

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

Re: Another programming problem!!!

Just a term. A recursive program is one that calls itself. You must make sure you have a base case so that the recursion stops, else it will exhaust all your memory, crash or go on forever.


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

#33 2011-09-30 23:48:08

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

Re: Another programming problem!!!

well do you think it is correct?

i was just confused by the subroutine part.


“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

#34 2011-09-30 23:54:32

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

Re: Another programming problem!!!

There is definitely an error somewhere. But you will not make much progress just by looking at it. That can help clean up syntax errors but the compiler usually spots them.

Perhaps your while loops are terminating prematurely. Is your input routine working? Have you checked?


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

#35 2011-09-30 23:56:57

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

Re: Another programming problem!!!

input routine?


“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

#36 2011-09-30 23:59:02

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

Re: Another programming problem!!!

Yes, the one that accepts your sudoku problem.


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

#37 2011-10-01 00:01:36

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

Re: Another programming problem!!!

it looks good.


“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

#38 2011-10-01 00:03:20

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

Re: Another programming problem!!!

Not good enough! Put a print or display statement at the end of it to make sure it has the correct structure.


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

#39 2011-10-01 00:21:46

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

Re: Another programming problem!!!

did it.it loaded.


“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

#40 2011-10-01 00:24:45

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

Re: Another programming problem!!!

Which variables represent your row and columns?


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

#41 2011-10-01 00:26:22

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

Re: Another programming problem!!!

i use a two-dimensional array for the values and variables i and j to run through them.


“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

#42 2011-10-01 00:28:18

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

Re: Another programming problem!!!

Are i and j cycling through 1 and 9? Put a display statement inside those loops and then run a test 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

#43 2011-10-01 00:39:03

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

Re: Another programming problem!!!

i inputted a sudoku and it looks like it is calculating because i cannot type anything and nothing happens when i press enter,but could it mean anything else?


“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

#44 2011-10-01 00:40:15

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

Re: Another programming problem!!!

Did you put output statements to see what i and j are doing?


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

#45 2011-10-01 00:41:59

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

Re: Another programming problem!!!

oh that's what you meant!


“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

#46 2011-10-01 00:43:01

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

Re: Another programming problem!!!

Yes, or open up the debugger and see what is happening there.


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

#47 2011-10-05 06:19:42

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

Re: Another programming problem!!!

help me!


“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

#48 2011-10-05 07:13:15

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

Re: Another programming problem!!!

Hi anonimnystefy;

What is wrong?


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

#49 2011-10-05 07:28:49

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

Re: Another programming problem!!!

well it's still the same problem but this time thanks to my friend i found an infinite lup in one of the procedures.it's named 'kolona':

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:=0;
  while (j<=max) and (b=true) do
  begin
    j:=j+1;
    if j<>j1 then
      if a[i1][j]=a[i1][j1] then
        b:=false;
  end;
  red:=b;
end;

function vrsta(a:matrica;i1,j1:integer):boolean;
var
  i:integer;
  b:boolean;
begin
  b:=true;
  i:=0;
  while(i<=max) and(b=true) do
  begin
    i:=i+1;
    if i<>i1 then
      if a[i][j1]=a[i1][j1] then
        b:=false;
  end;
  vrsta:=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:=0;
             i:=3
           end;
    4,5,6: begin
             k:=3;
             i:=6;
           end;
    7,8,9: begin
             k:=6;
             i:=9;
           end;
  end;
  case j1 of
    1,2,3: begin
             l:=0;
             j:=3
           end;
    4,5,6: begin
             l:=3;
             j:=6;
           end;
    7,8,9: begin
             l:=6;
             j:=9;
           end;
  end;
  while (k<=i) do
  begin
    k:=k+1;
    while (l<=j) do
    begin
      l:=l+1;
      if (k<>i1) and (l<>j1) then
        if a[k][l]=a[i1][j1] then
          b:=false;
    end;
  end;
  kvadrat:=b;
end;

function poz(a:matrica;i,j:integer):boolean;
begin
  poz:=red(a,i,j) and vrsta(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:=0;
    j:=0;
    b:=true;
    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;
    end;
    if b=false then
    begin
      k:=0;
      ok:=false;
      while (k<=9) and not ok do
      begin
        k:=k+1;
        sudoku(a,k,i,j,ok);
      end;
    end;
  end;
end;

begin
  writeln('Enter 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 cannot be solved!!!');
  readln;
end.

“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

#50 2011-10-05 07:30:44

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

Re: Another programming problem!!!

Hi;

Answer me honestly, did you write this code or did you use what was at the Lazarus site?


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

Board footer

Powered by FluxBB