RosettaCodeData/Task/Hex-words/11l/hex-words.11l
2023-07-01 13:44:08 -04:00

20 lines
795 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

F digroot(=n)
L n > 9
n = sum(String(n).map(d -> Int(d)))
R n
V lines = File(unixdict.txt).read().split("\n")
V words = lines.filter(w -> w.len >= 4 & all(w.map(c -> c C abcdef)))
V results = words.map(w -> (w, Int(w, radix' 16), digroot(Int(w, radix' 16))))
print("Hex words in unixdict.txt:\nRoot Word Base 10\n "(- * 22))
L(a) sorted(results, key' x -> x[2])
print(f:{a[2]} {a[0]:<6}{a[1]:10})
print(Total count of these words: results.len)
print("\nHex words with > 3 distinct letters:\nRoot Word Base 10\n "(- * 22))
results = results.filter(a -> Set(Array(String(a[0]))).len > 3)
L(a) sorted(results, key' x -> x[2])
print(f:{a[2]} {a[0]:<6}{a[1]:10})
print(Total count of those words: results.len)