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/anagrams.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 / anagrams.wiki`
133 lines ยท 2904 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 sp " "
8 note the word list (Rosetta Code reads unixdict.txt; this is a fixed sample of it), newline-terminated
9 text dict "abel\nable\nbale\nbela\nelba\nalger\nglare\nlager\nlarge\nregal\nangel\nangle\ngalen\nglean\nlange\ncaret\ncarte\ncater\ncrate\ntrace\nevil\nlevi\nlive\nveil\nvile\nelan\nlane\nlean\nlena\nneal\n"
10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11 fn emit a view uchar * to void
12 o = ulong 0
13 while lt o len a bound 4096
14 k = write 1 a o sub len a o
15 if le k 0
16 exit 1
17 end
18 o = add o ulong k
19 end
20 end
21 note key writes the letters of a sorted (insertion sort) into k; words are at most 16 letters
22 fn key a view uchar * k edit uchar 16 to void
23 for i ulong 16
24 put k i 0
25 end
26 for i ulong len a
27 c = get a i
28 j = i
29 while gt j 0 bound 16
30 if le get k sub j 1 c
31 break
32 end
33 put k j get k sub j 1
34 j = sub j 1
35 end
36 put k j c
37 end
38 end
39 fn same x view uchar 16 y view uchar 16 to bool
40 for i ulong 16
41 if ne get x i get y i
42 ret false
43 end
44 end
45 ret true
46 end
47 note index records each word's (start, length) and returns how many words there are
48 fn index st edit ulong 64 ln edit ulong 64 to ulong
49 k = ulong 0
50 s = ulong 0
51 for i ulong len dict
52 if eq get dict i 10
53 put st k s
54 put ln k sub i s
55 k = add k 1
56 s = add i 1
57 end
58 end
59 ret k
60 end
61 note count: how many words share word w's key
62 fn count st view ulong 64 ln view ulong 64 n ulong w ulong to ulong
63 a = new uchar 16 0
64 b = new uchar 16 0
65 key part dict get st w get ln w a
66 c = ulong 0
67 for v ulong n
68 key part dict get st v get ln v b
69 if same a b
70 c = add c 1
71 end
72 end
73 ret c
74 end
75 note first: no earlier word has word w's key
76 fn first st view ulong 64 ln view ulong 64 w ulong to bool
77 a = new uchar 16 0
78 b = new uchar 16 0
79 key part dict get st w get ln w a
80 for v ulong w
81 key part dict get st v get ln v b
82 if same a b
83 ret false
84 end
85 end
86 ret true
87 end
88 note print every group of the largest size, groups by first appearance, words in list order
89 fn show st view ulong 64 ln view ulong 64 n ulong best ulong to void
90 a = new uchar 16 0
91 b = new uchar 16 0
92 for w ulong n
93 if and first st ln w eq count st ln n w best
94 key part dict get st w get ln w a
95 f = true
96 for v ulong n
97 key part dict get st v get ln v b
98 if same a b
99 if not f
100 emit sp
101 end
102 emit part dict get st v get ln v
103 f = false
104 end
105 end
106 emit nl
107 end
108 end
109 end
110 fn main to int
111 st = new ulong 64 0
112 ln = new ulong 64 0
113 n = index st ln
114 best = ulong 0
115 for w ulong n
116 c = count st ln n w
117 if gt c best
118 best = c
119 end
120 end
121 show st ln n best
122 ret 0
123 end
124
125 {{out}}
126
127 abel able bale bela elba
128 alger glare lager large regal
129 angel angle galen glean lange
130 caret carte cater crate trace
131 evil levi live veil vile
132 elan lane lean lena neal
133