pad = function(n, width, rightJustify = false) if rightJustify then s = (" " * width + n)[-width:] else s = (n + " " * width)[:width] end if return s end function getDigitalRoot = function(n) while floor(log(n)) > 0 sum = 0 while n > 0 sum += n % 10 n = floor(n / 10) end while n = sum end while return sum end function hexToDec = function(hex) digits = "0123456789abcdef" result = digits.indexOf(hex[0]) for hdigit in hex[1:] result *= 16 result += digits.indexOf(hdigit) end for return result end function isHexWord = function(word) for ch in word.split("") if "abcdef".indexOf(ch) == null then return false end for return true end function distinctLetters = function(word) letters = {} for ch in word.split("") letters[ch] = 1 end for return letters.indexes end function wordList = http.get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt").split(char(10)) //wordList = file.readLines("unixdict.txt") hexWords = [] for word in wordList if word.len > 3 and isHexWord(word) then hexWords.push word end for roots = [] for hex in hexWords decimal = hexToDec(hex) root = getDigitalRoot(decimal) roots.push [root, hex, decimal] end for roots.sort(0) print "Hex words in unixdict.txt:" print pad("Root", 6) + pad("Word",10) + "Base 10" print "-" * 23 for root in roots print pad(root[0],6) + pad(root[1],7) + pad(root[2],9,true) end for print "Total count of words: " + roots.len cnt = 0 print print "Hext words with > 3 distinct letters:" print pad("Root", 6) + pad("Word",10) + "Base 10" print "-" * 23 for root in roots if distinctLetters(root[1]).len > 3 then cnt += 1 print pad(root[0],6) + pad(root[1],7) + pad(root[2],9,true) end if end for print "Total count of these words: " + cnt