Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in. #1 2011-09-29 19:23:56
Another programming problem!!!hi guys 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:integer;
ok:boolean;
function row(a:matrica;i1,j1:integer):boolean;
var
j:integer;
b:boolean;
begin
b:=true;
for j:=1 to 9 do
if j<>j1 then
if a[i1][j]=a[i1][j1] then
b:=false;
red:=b;
end;
function column(a:matrica;i1,j1:integer):boolean;
var
i:integer;
b:boolean;
begin
b:=true;
for i:=1 to 9 do
if i<>i1 then
if a[i][j1]=a[i1][j1] then
b:=false;
vrsta:=b;
end;
function square(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 pos(a:matrica;i,j:integer):boolean;
begin
poz:=row(a,i,j) and column(a,i,j) and square(a,i,j);
end;
procedure sudoku(var a:matrica;n,i1,j1:integer;ok:boolean);
var
i,j,k:integer;
b:boolean;
begin
i:=i1;
j:=j1;
a[i][j]:=n;
ok:=false;
b:=true;
if poz(a,i,j) then
begin
ok:=true;
i:=0;
j:=0;
while (b=true) and (i<=max) do
begin
i:=i+1;
while (b=true) and (j<=max) do
begin
j:=j+1;
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 the Sudoku: ');
for i:=1 to 9 do
begin
for j:=1 to 9 do
read(a[i][j]);
readln;
end;
k:=0;
ok:=false;
while (k<=9) and not ok do
begin
k:=k+1;
sudoku(a,k,i,j,ok);
end;
if ok then
begin
writeln('The solution is: ')
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.note that functions row,column and square check if there are same numbers as the number we are looking at in the same row,column and square. Last edited by anonimnystefy (2011-10-01 07:14:47) 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #2 2011-09-29 22:27:16
Re: Another programming problem!!!Hi anonimnystefy; In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #3 2011-09-30 05:36:34
Re: Another programming problem!!!hi bobbym 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #4 2011-09-30 06:07:24
Re: Another programming problem!!!just for practice: Last edited by anonimnystefy (2011-09-30 06:13:23) 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #5 2011-09-30 06:35:11
Re: Another programming problem!!!Funny thing is my program does noot get that one either. In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #6 2011-09-30 06:53:23
Re: Another programming problem!!!but why won't it work? 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #7 2011-09-30 06:59:44
Re: Another programming problem!!!Hi; In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #8 2011-09-30 07:14:34
Re: Another programming problem!!!have you checked it compleely.it uses recursion. 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #9 2011-09-30 07:17:52
Re: Another programming problem!!!Hi anonimnystefy; In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #10 2011-09-30 07:27:03
Re: Another programming problem!!!what does it get? 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #11 2011-09-30 13:18:52
Re: Another programming problem!!!Spits it out as if it does not have a solution! Where does that solution come from? In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #12 2011-10-01 04:39:40
Re: Another programming problem!!!from me! 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #13 2011-10-01 05:27:28
Re: Another programming problem!!!That is what I was thinking. Did you try it on any others? In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #14 2011-10-01 06:37:54
Re: Another programming problem!!!nope! :embarrassed! 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #15 2011-10-01 06:38:56
Re: Another programming problem!!!I can give you some examples if you do not have any. In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #16 2011-10-01 06:56:06
Re: Another programming problem!!!i have bunch of them and i tried 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #17 2011-10-01 07:15:58
Re: Another programming problem!!!hi bobbym 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #18 2011-10-01 07:19:43
Re: Another programming problem!!!Hi; In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #19 2011-10-01 07:25:15
Re: Another programming problem!!!ya think? 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #20 2011-10-01 07:27:03
Re: Another programming problem!!!That is about all I can do. I do not speak Java. Even my C++ is too rusty. Use your debugger to go line by line watching the variables as you go. In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #21 2011-10-01 20:03:47
Re: Another programming problem!!!where did you get Java? 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #22 2011-10-01 20:34:51
Re: Another programming problem!!!Hi anonimnystefy; In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #23 2011-10-01 20:36:51
Re: Another programming problem!!!think so. 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón #24 2011-10-01 20:39:38
Re: Another programming problem!!!Does it have a variable pane? Or a variable watch? In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #25 2011-10-01 20:44:34
Re: Another programming problem!!!yes,yes it does. 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 “A secret's worth depends on the people from whom it must be kept.” ― Carlos Ruiz Zafón |