RosettaCodeData/Task/Hex-words/EasyLang/hex-words.easy
2025-06-11 20:16:52 -04:00

85 lines
1.2 KiB
Text

func ishex w$ .
c$ = ""
for c$ in strchars w$
h = strcode c$
if h < 97 or h > 102 : break 1
.
return if c$ = ""
.
global w$[] part2 .
func digsum num .
while num > 0
s += num mod 10
num = num div 10
.
return s
.
func digroot x .
while x > 9 : x = digsum x
return x
.
func dec w$ .
for c$ in strchars w$
r = r * 16 + strcode c$ - 87
.
return r
.
func comp a$ b$ .
if part2 = 1
return if dec a$ > dec b$
.
return if digroot dec a$ < digroot dec b$
.
proc sort .
for i = len w$[] - 1 downto 1
for j = 1 to i
if comp w$[j] w$[j + 1] = 1
swap w$[j] w$[j + 1]
.
.
.
.
proc init .
repeat
s$ = input
until s$ = ""
if len s$ >= 4 and ishex s$ = 1
w$[] &= s$
.
.
.
init
sort
proc show .
for w$ in w$[]
w = dec w$
print digroot w & " " & w$ & " " & w
.
print len w$[] & " words"
print ""
.
show
#
func dist w$ .
len d[] 6
for c$ in strchars w$
d[strcode c$ - 96] = 1
.
for e in d[] : s += e
return s
.
for w$ in w$[]
if dist w$ > 3 : w2$[] &= w$
.
swap w$[] w2$[]
part2 = 1
sort
show
#
# the content of unixdict.txt
input_data
10th
ababa
beebe
decade
facade