interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / n-queens-problem.wiki

84 lines · 1532 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text t1 " queens: "
8text t2 " solutions\n"
9global cols uchar 8
10global d1 uchar 15
11global d2 uchar 15
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note emitu writes n in decimal; 20 digits hold every ulong
24fn emitu n ulong to void
25d = new uchar 20 0
26i = ulong 20
27v = n
28while true bound 20
29i = sub i 1
30put d i uchar add rem v 10 48
31v = div v 10
32if eq v 0
33break
34end
35end
36emit part d i sub 20 i
37end
38note counts placements for rows r .. n-1; d1 holds the r+c diagonals, d2 the r-c+7 ones
39fn place r ulong n ulong to ulong
40if eq r n
41ret 1
42end
43cnt = ulong 0
44for c ulong n
45a = add r c
46b = add r sub 7 c
47if eq get cols c 0
48if eq get d1 a 0
49if eq get d2 b 0
50put cols c 1
51put d1 a 1
52put d2 b 1
53cnt = add cnt place add r 1 n
54put cols c 0
55put d1 a 0
56put d2 b 0
57end
58end
59end
60end
61ret cnt
62end
63fn main to int
64for i ulong 8
65n = add i 1
66emitu n
67emit t1
68emitu place 0 n
69emit t2
70end
71ret 0
72end
73</syntaxhighlight>
74{{out}}
75<pre>
761 queens: 1 solutions
772 queens: 0 solutions
783 queens: 0 solutions
794 queens: 2 solutions
805 queens: 10 solutions
816 queens: 4 solutions
827 queens: 40 solutions
838 queens: 92 solutions
84</pre>