Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/n-queens-problem.wiki
# omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
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}}
3 Omega has no imports, so the small output helpers (emit and friends) are part of the program.
4
5 om2
6 text nl "\n"
7 text t1 " queens: "
8 text t2 " solutions\n"
9 global cols uchar 8
10 global d1 uchar 15
11 global d2 uchar 15
12 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13 fn emit a view uchar * to void
14 o = ulong 0
15 while lt o len a bound 4096
16 k = write 1 a o sub len a o
17 if le k 0
18 exit 1
19 end
20 o = add o ulong k
21 end
22 end
23 note emitu writes n in decimal; 20 digits hold every ulong
24 fn emitu n ulong to void
25 d = new uchar 20 0
26 i = ulong 20
27 v = n
28 while true bound 20
29 i = sub i 1
30 put d i uchar add rem v 10 48
31 v = div v 10
32 if eq v 0
33 break
34 end
35 end
36 emit part d i sub 20 i
37 end
38 note counts placements for rows r .. n-1; d1 holds the r+c diagonals, d2 the r-c+7 ones
39 fn place r ulong n ulong to ulong
40 if eq r n
41 ret 1
42 end
43 cnt = ulong 0
44 for c ulong n
45 a = add r c
46 b = add r sub 7 c
47 if eq get cols c 0
48 if eq get d1 a 0
49 if eq get d2 b 0
50 put cols c 1
51 put d1 a 1
52 put d2 b 1
53 cnt = add cnt place add r 1 n
54 put cols c 0
55 put d1 a 0
56 put d2 b 0
57 end
58 end
59 end
60 end
61 ret cnt
62 end
63 fn main to int
64 for i ulong 8
65 n = add i 1
66 emitu n
67 emit t1
68 emitu place 0 n
69 emit t2
70 end
71 ret 0
72 end
73
74 {{out}}
75
76 1 queens: 1 solutions
77 2 queens: 0 solutions
78 3 queens: 0 solutions
79 4 queens: 2 solutions
80 5 queens: 10 solutions
81 6 queens: 4 solutions
82 7 queens: 40 solutions
83 8 queens: 92 solutions
84