39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
#lang transd
|
|
|
|
MainModule: {
|
|
maxwLen: 9,
|
|
minwLen: 3,
|
|
dict: Vector<String>(),
|
|
subWords: Vector<String>(),
|
|
|
|
procGrid: (λ grid String() cent String() subs Bool()
|
|
(with cnt 0 (sort grid)
|
|
(for w in dict where (and (neq (index-of w cent) -1)
|
|
(match w "^[[:alpha:]]+$")) do
|
|
(if (is-subset grid (sort (cp w))) (+= cnt 1)
|
|
(if subs (append subWords w))
|
|
)
|
|
)
|
|
(ret cnt)
|
|
)),
|
|
|
|
_start: (λ locals: res 0 maxRes 0
|
|
(with fs FileStream()
|
|
(open-r fs "/mnt/proj/res/unixdict.txt")
|
|
(for w in (read-lines fs)
|
|
where (within (size w) minwLen maxwLen) do
|
|
(append dict w))
|
|
)
|
|
|
|
(lout "Main part of task:\n")
|
|
(procGrid "ndeokgelw" "k" true)
|
|
(lout "Number of words: " (size subWords) ";\nword list: " subWords)
|
|
|
|
(lout "\n\nOptional part of task:\n")
|
|
(for w in dict where (eq (size w) maxwLen) do
|
|
(for centl in (split (unique (sort (cp w))) "") do
|
|
(if (>= (= res (procGrid (cp w) centl false)) maxRes) (= maxRes res)
|
|
(lout "New max. number: " maxRes ", word: " w ", central letter: " centl)
|
|
) ) ) )
|
|
}
|