File: reines.p

package info (click to toggle)
ocaml-doc 3.09-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 10,428 kB
  • ctags: 4,963
  • sloc: ml: 9,244; makefile: 2,413; ansic: 122; sh: 49; asm: 17
file content (51 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
program huitReines;

var col: array [1..8] of integer;
var nsol: integer;
var ligne: integer;
var colonne: integer;
var l: integer;

function conflit(c:integer, l:integer):boolean;
  var dl: integer;
  var k: integer;
  begin
    conflit := false;
    k := 1;
    while k <= c do begin
      dl := col[k] - l;
      if dl < 0 then dl := - dl;
      if dl * (dl - c - 1 + k) = 0 then conflit := true;
      k := k + 1
    end
  end;

begin
  nsol := 0;
  l := 1;
  while l <= 8 do begin
    col[1] := l; colonne := 1; ligne := 1;
    while colonne <> 0 do begin
      while ligne <= 8 do begin
        if conflit(colonne, ligne) then
          ligne := ligne + 1
        else begin
          col[colonne + 1] := ligne;
          colonne := colonne + 1;
          if colonne <= 7 then
            ligne := 1
          else begin
            nsol := nsol + 1;
            ligne := 9
          end
        end
      end;
      while (ligne > 8) and (colonne <> 0) do begin
        colonne := colonne - 1;
        ligne := col[colonne + 1] + 1
      end
    end;
    l := l + 1
  end;
  write(nsol)
end