Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Hex-words/00-META.yaml
Normal file
2
Task/Hex-words/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Hex_words
|
||||
13
Task/Hex-words/00-TASK.txt
Normal file
13
Task/Hex-words/00-TASK.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
;Definition
|
||||
For the purposes of this task a '''hex word''' means a word which (in lower case form) consists entirely of the letters '''a, b, c, d, e''' and '''f'''.
|
||||
|
||||
;Task
|
||||
Using [http://wiki.puzzlers.org/pub/wordlists/unixdict.txt unixdict.txt], find all hex words with '''4''' letters or more.
|
||||
|
||||
Convert each such word to its decimal equivalent and compute its base 10 [[Digital_root|digital root]].
|
||||
|
||||
Display all three in increasing order of digital root and show the total count of such words.
|
||||
|
||||
Keeping only words which contain at least '''4''' distinct letters, display the same statistics but in decreasing order of decimal equivalent together with their total count.
|
||||
<br><br>
|
||||
|
||||
20
Task/Hex-words/11l/hex-words.11l
Normal file
20
Task/Hex-words/11l/hex-words.11l
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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)
|
||||
125
Task/Hex-words/ALGOL-68/hex-words.alg
Normal file
125
Task/Hex-words/ALGOL-68/hex-words.alg
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
# find words that contain only hex digits a-f #
|
||||
IF FILE input file;
|
||||
STRING file name = "unixdict.txt";
|
||||
open( input file, file name, stand in channel ) /= 0
|
||||
THEN
|
||||
# failed to open the file #
|
||||
print( ( "Unable to open """ + file name + """", newline ) )
|
||||
ELSE
|
||||
# file opened OK #
|
||||
BOOL at eof := FALSE;
|
||||
# set the EOF handler for the file #
|
||||
on logical file end( input file, ( REF FILE f )BOOL:
|
||||
BEGIN
|
||||
# note that we reached EOF on the #
|
||||
# latest read #
|
||||
at eof := TRUE;
|
||||
# return TRUE so processing can continue #
|
||||
TRUE
|
||||
END
|
||||
);
|
||||
INT count := 0;
|
||||
INT max words = 100; # guess at the maximum number of words #
|
||||
MODE HEXWORD = STRUCT( STRING word, LONG INT value, INT root, INT len );
|
||||
[ 1 : max words ]HEXWORD hw;
|
||||
WHILE STRING word;
|
||||
get( input file, ( word, newline ) );
|
||||
NOT at eof
|
||||
DO
|
||||
# check the word contains only a-f and compute its decimal value #
|
||||
IF INT word len = ( UPB word + 1 ) - LWB word;
|
||||
word len >= 4
|
||||
THEN
|
||||
# the word is at least 4 characters long #
|
||||
BOOL is hex word := word /= "";
|
||||
LONG INT int word := 0;
|
||||
FOR i FROM LWB word TO UPB word
|
||||
WHILE is hex word := word[ i ] >= "a" AND word[ i ] <= "f"
|
||||
DO
|
||||
int word *:= 16;
|
||||
int word +:= ( ABS word[ i ] - ABS "a" ) + 10
|
||||
OD;
|
||||
IF is hex word
|
||||
THEN
|
||||
# have a hex word #
|
||||
count +:= 1;
|
||||
# compute the digital root #
|
||||
LONG INT r := int word;
|
||||
WHILE r > 9 DO
|
||||
LONG INT dr := r MOD 10;
|
||||
WHILE ( r OVERAB 10 ) > 0 DO dr +:= r MOD 10 OD;
|
||||
r := dr
|
||||
OD;
|
||||
word OF hw[ count ] := word;
|
||||
value OF hw[ count ] := int word;
|
||||
root OF hw[ count ] := SHORTEN r;
|
||||
len OF hw[ count ] := word len
|
||||
FI
|
||||
FI
|
||||
OD;
|
||||
close( input file );
|
||||
# prints the HEXWORD hw #
|
||||
PROC show = ( HEXWORD hw )VOID:
|
||||
BEGIN
|
||||
STRING pad = IF len OF hw >= 12 THEN "" ELSE ( 12 - len OF hw ) * " " FI;
|
||||
print( ( word OF hw, ": ", pad, whole( value OF hw, -10 ), " [ ", whole( root OF hw, 0 ), " ]", newline ) )
|
||||
END # show # ;
|
||||
# Quicksorts in-place the array of HEXWORDS a, from lb to ub on ascending value #
|
||||
PROC quicksort = ( REF[]HEXWORD a, INT lb, ub )VOID:
|
||||
IF ub > lb THEN
|
||||
# more than one element, so must sort #
|
||||
INT left := lb;
|
||||
INT right := ub;
|
||||
# choosing the middle element of the array as the pivot #
|
||||
LONG INT pivot := value OF a[ left + ( ( right + 1 ) - left ) OVER 2 ];
|
||||
WHILE
|
||||
WHILE IF left <= ub THEN value OF a[ left ] < pivot ELSE FALSE FI DO left +:= 1 OD;
|
||||
WHILE IF right >= lb THEN value OF a[ right ] > pivot ELSE FALSE FI DO right -:= 1 OD;
|
||||
left <= right
|
||||
DO
|
||||
HEXWORD t := a[ left ];
|
||||
a[ left ] := a[ right ];
|
||||
a[ right ] := t;
|
||||
left +:= 1;
|
||||
right -:= 1
|
||||
OD;
|
||||
quicksort( a, lb, right );
|
||||
quicksort( a, left, ub )
|
||||
FI # quicksort # ;
|
||||
# show the hex words in ascending order of digital root #
|
||||
FOR r FROM 1 TO 9 DO
|
||||
FOR i FROM 1 TO count DO
|
||||
IF root OF hw[ i ] = r THEN show( hw[ i ] ) FI
|
||||
OD
|
||||
OD;
|
||||
print( ( "Found ", whole( count, 0 ), " hex words", newline, newline ) );
|
||||
# show the words in descending value order excluding those with less than 4 unique letters #
|
||||
quicksort( hw, 1, count );
|
||||
INT count 4 := 0;
|
||||
FOR i FROM count BY -1 TO 1 DO
|
||||
# check the word has at least four different digits #
|
||||
INT a := 0, b := 0, c := 0, d := 0, e := 0, f := 0;
|
||||
FOR c pos FROM LWB word OF hw[ i ] TO UPB word OF hw[ i ] DO
|
||||
IF CHAR ch = ( word OF hw[ i ] )[ c pos ];
|
||||
ch = "a"
|
||||
THEN a := 1
|
||||
ELIF ch = "b"
|
||||
THEN b := 1
|
||||
ELIF ch = "c"
|
||||
THEN c := 1
|
||||
ELIF ch = "d"
|
||||
THEN d := 1
|
||||
ELIF ch = "e"
|
||||
THEN e := 1
|
||||
ELSE f := 1
|
||||
FI
|
||||
OD;
|
||||
IF a + b + c + d + e + f >= 4
|
||||
THEN
|
||||
# have a hex word with at least 4 different digits #
|
||||
count 4 +:= 1;
|
||||
show( hw[ i ] )
|
||||
FI
|
||||
OD;
|
||||
print( ( "Found ", whole( count 4, 0 ), " hex words with 4 or more distinct digits", newline ) )
|
||||
FI
|
||||
54
Task/Hex-words/AWK/hex-words.awk
Normal file
54
Task/Hex-words/AWK/hex-words.awk
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# syntax: GAWK -f HEX_WORDS.AWK unixdict.txt
|
||||
{ nf += NF
|
||||
if (length($1) >= 4) {
|
||||
if ($0 ~ /^[a-fA-F]{4,}$/) {
|
||||
base10 = hex2dec($1)
|
||||
dr = digital_root(base10)
|
||||
arr[dr " " $1] = base10
|
||||
}
|
||||
}
|
||||
}
|
||||
ENDFILE {
|
||||
printf("%s: %d records, %d fields\n\n",FILENAME,FNR,nf)
|
||||
}
|
||||
END {
|
||||
PROCINFO["sorted_in"] = "@ind_str_asc"
|
||||
for (i in arr) {
|
||||
printf("%-8s %10d \n",i,arr[i])
|
||||
count1++
|
||||
}
|
||||
printf("Found %d hex words\n\n",count1)
|
||||
PROCINFO["sorted_in"] = "@val_num_desc"
|
||||
for (i in arr) {
|
||||
if (distinct(substr(i,3)) >= 4) {
|
||||
printf("%-8s %10d \n",i,arr[i])
|
||||
count2++
|
||||
}
|
||||
}
|
||||
printf("Found %d hex words with 4 or more distinct\n\n",count2)
|
||||
exit(0)
|
||||
}
|
||||
function digital_root(n, i,sum) {
|
||||
while (1) {
|
||||
sum = 0
|
||||
for (i=1; i<=length(n); i++) {
|
||||
sum += substr(n,i,1)
|
||||
}
|
||||
if (sum < 10) {
|
||||
break
|
||||
}
|
||||
n = sum
|
||||
}
|
||||
return(sum)
|
||||
}
|
||||
function distinct(str, arr,i) {
|
||||
for (i=1; i<=length(str); i++) {
|
||||
arr[substr(str,i,1)]++
|
||||
}
|
||||
return(length(arr))
|
||||
}
|
||||
function hex2dec(s, num) {
|
||||
num = index("0123456789ABCDEF",toupper(substr(s,length(s)))) - 1
|
||||
sub(/.$/,"",s)
|
||||
return num + (length(s) ? 16*hex2dec(s) : 0)
|
||||
}
|
||||
97
Task/Hex-words/AppleScript/hex-words-1.applescript
Normal file
97
Task/Hex-words/AppleScript/hex-words-1.applescript
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
|
||||
use framework "Foundation"
|
||||
use scripting additions
|
||||
use sorter : script ¬
|
||||
"Custom Iterative Ternary Merge Sort" -- <www.macscripter.net/t/timsort-and-nigsort/71383/3>
|
||||
|
||||
on hexToInt(hex)
|
||||
set digits to "0123456789ABCDEF"
|
||||
set n to 0
|
||||
set astid to AppleScript's text item delimiters
|
||||
ignoring case
|
||||
repeat with thisDigit in hex
|
||||
set AppleScript's text item delimiters to thisDigit
|
||||
set n to n * 16 + (count digits's first text item)
|
||||
end repeat
|
||||
end ignoring
|
||||
set AppleScript's text item delimiters to astid
|
||||
return n
|
||||
end hexToInt
|
||||
|
||||
on digitalRoot(r, base)
|
||||
repeat until (r < base)
|
||||
set n to r
|
||||
set r to 0
|
||||
repeat until (n = 0)
|
||||
set r to r + n mod base
|
||||
set n to n div base
|
||||
end repeat
|
||||
end repeat
|
||||
return r as integer
|
||||
end digitalRoot
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
on task()
|
||||
set ca to current application
|
||||
set unixdictPath to (path to desktop as text) & "unixdict.txt"
|
||||
set allWords to (read (unixdictPath as «class furl») from 1 as «class utf8»)'s words
|
||||
set hexwordFilter to ca's class "NSPredicate"'s ¬
|
||||
predicateWithFormat:("self MATCHES '^[a-f]{4,}+$'")
|
||||
set hexwords to ((ca's class "NSArray"'s arrayWithArray:(allWords))'s ¬
|
||||
filteredArrayUsingPredicate:(hexwordFilter))
|
||||
|
||||
set {list1, list2} to {{}, {}}
|
||||
repeat with thisWord in hexwords
|
||||
set thisWord to thisWord as text
|
||||
set decimal to hexToInt(thisWord)
|
||||
set root to digitalRoot(decimal, 10)
|
||||
set thisEntry to {thisWord, decimal, root}
|
||||
set end of list1 to thisEntry
|
||||
set distinctChars to (ca's class "NSSet"'s setWithArray:(thisWord's characters))
|
||||
if (distinctChars's |count|() > 3) then set end of list2 to thisEntry
|
||||
end repeat
|
||||
|
||||
-- Sort list1 on its sublists' digital root values.
|
||||
script
|
||||
on isGreater(a, b)
|
||||
return (a's end > b's end)
|
||||
end isGreater
|
||||
end script
|
||||
tell sorter to sort(list1, 1, -1, {comparer:result})
|
||||
-- Reverse sort list2 on its sublists' decimal equivalent values.
|
||||
script
|
||||
on isGreater(a, b)
|
||||
return (a's 2nd item < b's 2nd item)
|
||||
end isGreater
|
||||
end script
|
||||
tell sorter to sort(list2, 1, -1, {comparer:result})
|
||||
|
||||
-- Format for display and output.
|
||||
set padding to " "
|
||||
repeat with thisList in {list1, list2}
|
||||
repeat with thisEntry in thisList
|
||||
tell thisEntry to set its contents to ¬
|
||||
text 1 thru 9 of (its beginning & padding) & ¬
|
||||
text -9 thru -1 of (padding & its 2nd item) & ¬
|
||||
text -9 thru -1 of (padding & its end)
|
||||
end repeat
|
||||
set thisList's beginning to "
|
||||
Word Decimal Root
|
||||
----------------------------"
|
||||
end repeat
|
||||
set beginning of list1 to linefeed & ((count list1) - 1) & ¬
|
||||
" 4+-character hexwords, sorted on their decimal equivalents' digital roots:"
|
||||
set beginning of list2 to linefeed & "The " & ((count list2) - 1) & ¬
|
||||
" with at least 4 /different/ characters, reverse sorted on their decimal equivalents:"
|
||||
|
||||
return join({list1, list2}, linefeed)
|
||||
end task
|
||||
|
||||
task()
|
||||
49
Task/Hex-words/AppleScript/hex-words-2.applescript
Normal file
49
Task/Hex-words/AppleScript/hex-words-2.applescript
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
"
|
||||
26 4+-character hexwords, sorted on their decimal equivalents' digital roots:
|
||||
|
||||
Word Decimal Root
|
||||
----------------------------
|
||||
ababa 703162 1
|
||||
abbe 43966 1
|
||||
dada 56026 1
|
||||
deaf 57007 1
|
||||
decade 14600926 1
|
||||
cede 52958 2
|
||||
feed 65261 2
|
||||
abed 44013 3
|
||||
added 712173 3
|
||||
bade 47838 3
|
||||
beebe 782014 4
|
||||
decca 912586 4
|
||||
dade 56030 5
|
||||
bead 48813 6
|
||||
deface 14613198 6
|
||||
babe 47806 7
|
||||
fade 64222 7
|
||||
dead 57005 8
|
||||
efface 15727310 8
|
||||
facade 16435934 8
|
||||
accede 11325150 9
|
||||
beef 48879 9
|
||||
cafe 51966 9
|
||||
dacca 896202 9
|
||||
deed 57069 9
|
||||
face 64206 9
|
||||
|
||||
The 13 with at least 4 /different/ characters, reverse sorted on their decimal equivalents:
|
||||
|
||||
Word Decimal Root
|
||||
----------------------------
|
||||
facade 16435934 8
|
||||
efface 15727310 8
|
||||
deface 14613198 6
|
||||
decade 14600926 1
|
||||
accede 11325150 9
|
||||
decca 912586 4
|
||||
fade 64222 7
|
||||
face 64206 9
|
||||
deaf 57007 1
|
||||
cafe 51966 9
|
||||
bead 48813 6
|
||||
bade 47838 3
|
||||
abed 44013 3"
|
||||
39
Task/Hex-words/Arturo/hex-words.arturo
Normal file
39
Task/Hex-words/Arturo/hex-words.arturo
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
words: map read.lines relative "unixdict.txt" => strip
|
||||
hexWords: new []
|
||||
|
||||
digRoot: function [num][
|
||||
res: num
|
||||
while [1 < size digits res][
|
||||
res: sum digits res
|
||||
]
|
||||
return res
|
||||
]
|
||||
|
||||
printTable: function [wrds][
|
||||
print [pad.center "Root" 10 pad.right "Word" 10 pad "Base-10" 15]
|
||||
print repeat "-" 38
|
||||
loop wrds 'wrd [
|
||||
print [pad.center to :string wrd\root 10 pad.right wrd\hex 10 pad to :string wrd\decimal 15]
|
||||
]
|
||||
print repeat "-" 38
|
||||
print [" Total count:" size wrds "\n"]
|
||||
]
|
||||
|
||||
loop words 'word [
|
||||
if 4 > size word ->
|
||||
continue
|
||||
|
||||
if not? empty? match word {/^[a-f]+$/} [
|
||||
base10: from.hex word
|
||||
droot: digRoot base10
|
||||
'hexWords ++ #[
|
||||
root: droot
|
||||
hex: word
|
||||
decimal: base10
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
printTable sort.by:'root hexWords
|
||||
printTable sort.descending.by:'decimal select hexWords 'h ->
|
||||
4 =< size unique split h\hex
|
||||
44
Task/Hex-words/AutoHotkey/hex-words.ahk
Normal file
44
Task/Hex-words/AutoHotkey/hex-words.ahk
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
FileRead, wList, % A_Desktop "\unixdict.txt"
|
||||
hexWords := Hex_words(wList)
|
||||
Header := "Base 10`t`tWord`tRoot`n"
|
||||
for dr, obj in hexWords
|
||||
for word, dec in obj
|
||||
result .= dec "`t" (StrLen(dec) < 8 ? "`t" : "") word "`t" dr "`n"
|
||||
|
||||
MsgBox, 262144, ,% result := Header . result . "`n4 distinct letter words:`n" . Header . filter(result, "abcdef", 4)
|
||||
return
|
||||
;-------------------------------------------
|
||||
filter(result, letters, Count){
|
||||
for i, line in StrSplit(result, "`n", "`r") {
|
||||
counter := 0
|
||||
for j, letter in StrSplit(letters)
|
||||
StrReplace(line, letter, letter, cnt, 1), counter += cnt
|
||||
if (counter >= Count)
|
||||
filtered .= line "`n"
|
||||
}
|
||||
Sort, filtered, RN
|
||||
return filtered
|
||||
}
|
||||
;-------------------------------------------
|
||||
Hex_words(wList){
|
||||
hexWords := []
|
||||
for i, w in StrSplit(wList, "`n", "`r") {
|
||||
if (StrLen(w) < 4 || w ~= "i)[^abcdef]")
|
||||
continue
|
||||
dec := hex2dec(w)
|
||||
dr := digital_root(dec)
|
||||
hexWords[dr, w] := dec
|
||||
}
|
||||
return hexWords
|
||||
}
|
||||
;-------------------------------------------
|
||||
digital_root(n){
|
||||
loop {
|
||||
sum := 0, i := 1
|
||||
while (i <= StrLen(n))
|
||||
sum += SubStr(n, i++, 1)
|
||||
n := sum
|
||||
}
|
||||
until (sum < 10)
|
||||
return sum
|
||||
}
|
||||
22
Task/Hex-words/Factor/hex-words.factor
Normal file
22
Task/Hex-words/Factor/hex-words.factor
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
USING: formatting io io.encodings.ascii io.files kernel literals
|
||||
math math.parser prettyprint sequences sets sorting ;
|
||||
|
||||
CONSTANT: words $[
|
||||
"unixdict.txt" ascii file-lines
|
||||
[ length 3 > ] filter
|
||||
[ "abcdef" subset? ] filter
|
||||
]
|
||||
|
||||
: droot ( m -- n ) 1 - 9 mod 1 + ;
|
||||
|
||||
: info. ( str -- ) dup hex> dup droot "%-8s-> %-10d-> %d\n" printf ;
|
||||
|
||||
: info-by ( quot ? -- )
|
||||
[ sort-with ] [ inv-sort-with ] if [ length ] keep
|
||||
[ info. ] each pprint ; inline
|
||||
|
||||
words [ hex> droot ] t info-by
|
||||
" hex words with 4 or more letters found." print nl
|
||||
|
||||
words [ cardinality 3 > ] filter [ hex> ] f info-by
|
||||
" such words found which contain 4 or more different digits." print
|
||||
43
Task/Hex-words/J/hex-words.j
Normal file
43
Task/Hex-words/J/hex-words.j
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(#~$&1 0@#)(#,&":])/:~((+/@(".&>@":)^:_@]; ;~) dfh)@> (#~ (*/@e.&'abcdef' * 3<#)@>) cutLF fread'unixdict.txt'
|
||||
26
|
||||
│1│43966 │abbe │
|
||||
│1│56026 │dada │
|
||||
│1│57007 │deaf │
|
||||
│1│703162 │ababa │
|
||||
│1│14600926│decade│
|
||||
│2│52958 │cede │
|
||||
│2│65261 │feed │
|
||||
│3│44013 │abed │
|
||||
│3│47838 │bade │
|
||||
│3│712173 │added │
|
||||
│4│782014 │beebe │
|
||||
│4│912586 │decca │
|
||||
│5│56030 │dade │
|
||||
│6│48813 │bead │
|
||||
│6│14613198│deface│
|
||||
│7│47806 │babe │
|
||||
│7│64222 │fade │
|
||||
│8│57005 │dead │
|
||||
│8│15727310│efface│
|
||||
│8│16435934│facade│
|
||||
│9│48879 │beef │
|
||||
│9│51966 │cafe │
|
||||
│9│57069 │deed │
|
||||
│9│64206 │face │
|
||||
│9│896202 │dacca │
|
||||
│9│11325150│accede│
|
||||
(#~ $&1 0@#)(#,&":])\:~((+/@(".&>@":)^:_@]; ;~) dfh)@> (#~ (*/@e.&'abcdef' * 3 < #@~.)@>) cutLF fread'unixdict.txt'
|
||||
13
|
||||
│9│11325150│accede│
|
||||
│9│64206 │face │
|
||||
│9│51966 │cafe │
|
||||
│8│16435934│facade│
|
||||
│8│15727310│efface│
|
||||
│7│64222 │fade │
|
||||
│6│14613198│deface│
|
||||
│6│48813 │bead │
|
||||
│4│912586 │decca │
|
||||
│3│47838 │bade │
|
||||
│3│44013 │abed │
|
||||
│1│14600926│decade│
|
||||
│1│57007 │deaf │
|
||||
23
Task/Hex-words/Jq/hex-words-1.jq
Normal file
23
Task/Hex-words/Jq/hex-words-1.jq
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
|
||||
|
||||
# . may be a decimal number or a string representing a decimal number
|
||||
def digital_root:
|
||||
# string-only version
|
||||
def dr:
|
||||
# state: [mdr, persist]
|
||||
until( .[0] | length == 1;
|
||||
[ (.[0] | explode | map(.-48) | add | tostring), .[1] + 1 ]
|
||||
);
|
||||
[tostring, 0] | dr | .[0] | tonumber;
|
||||
|
||||
# lowercase a-f
|
||||
def isHexWord:
|
||||
all(explode[]; 97 <= . and . <= 102);
|
||||
|
||||
# Input: a valid hex number (all lowercase)
|
||||
def hex2i:
|
||||
def toi: if . >= 87 then .-87 else . - 48 end;
|
||||
reduce (explode | map(toi) | reverse[]) as $i ([1, 0]; # [power, sum]
|
||||
.[1] += $i * .[0]
|
||||
| .[0] *= 16 )
|
||||
| .[1];
|
||||
23
Task/Hex-words/Jq/hex-words-2.jq
Normal file
23
Task/Hex-words/Jq/hex-words-2.jq
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
def task:
|
||||
|
||||
def format: "\(.[0]|lpad(8)) -> \(.[1]|lpad(9)) -> \(.[2])";
|
||||
|
||||
INDEX(inputs | select(length>=4 and isHexWord); .)
|
||||
| reduce keys_unsorted[] as $word ([];
|
||||
($word | hex2i) as $num
|
||||
| ($num | digital_root) as $dr
|
||||
| . + [[ $word, $num, $dr]])
|
||||
| sort_by( .[-1] )
|
||||
| . as $details
|
||||
|
||||
| (reduce .[] as $line ([];
|
||||
if $line[0] | explode | unique | length >= 4
|
||||
then . + [$line] else . end)) as $digits4
|
||||
|
||||
| "\($details|length) hex words with 4 or more letters were found:",
|
||||
($details[] | format),
|
||||
"",
|
||||
"\($digits4|length) such words contain 4 or more different letters:",
|
||||
(($digits4|sort_by(.[1])|reverse[] ) | format) ;
|
||||
|
||||
task
|
||||
23
Task/Hex-words/Julia/hex-words.julia
Normal file
23
Task/Hex-words/Julia/hex-words.julia
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
digroot(n) = (while n > 9 n = sum(digits(n)) end; n)
|
||||
|
||||
function hexwords(wordfile = "unixdict.txt")
|
||||
words = lowercase.(split(read(wordfile, String), r"\s+"))
|
||||
filter!(w -> length(w) >= 4 && all(c -> c in "abcdef", w), words)
|
||||
results = [[w, parse(Int, w, base = 16)] for w in words]
|
||||
for a in results
|
||||
pushfirst!(a, digroot(a[2]))
|
||||
end
|
||||
println("Hex words in $wordfile:\nRoot Word Base 10\n", "-"^30)
|
||||
for a in sort!(results)
|
||||
println(rpad(a[1], 6), rpad(a[2], 10), a[3])
|
||||
end
|
||||
println("Total count of these words: $(length(results)).")
|
||||
println("\nHex words with > 3 distinct letters:\nRoot Word Base 10\n", "-"^30)
|
||||
filter!(a -> length(unique(a[2])) > 3, results)
|
||||
for a in results
|
||||
println(rpad(a[1], 6), rpad(a[2], 10), a[3])
|
||||
end
|
||||
println("Total count of those words: $(length(results)).")
|
||||
end
|
||||
|
||||
hexwords()
|
||||
55
Task/Hex-words/Nim/hex-words.nim
Normal file
55
Task/Hex-words/Nim/hex-words.nim
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import std/[algorithm, setutils, strformat, strutils]
|
||||
|
||||
const LowerHexDigits = {'a'..'f'}
|
||||
|
||||
type Item = tuple[word: string; value, droot: int]
|
||||
|
||||
iterator digits(n: Natural): Natural =
|
||||
## Yield the digits of a natural.
|
||||
var n = n
|
||||
while true:
|
||||
yield n mod 10
|
||||
n = n div 10
|
||||
if n == 0:
|
||||
break
|
||||
|
||||
func digitalRoot(n: Natural): Natural =
|
||||
## Return the digital root of a natural.
|
||||
var n = n
|
||||
while true:
|
||||
result = 0
|
||||
for d in n.digits:
|
||||
result += d
|
||||
if result <= 9:
|
||||
break
|
||||
n = result
|
||||
|
||||
proc display(items: seq[Item]) =
|
||||
## Display the items.
|
||||
echo "Word Decimal value Digital root"
|
||||
echo repeat("─", 39)
|
||||
for item in items:
|
||||
echo &"{item.word:<8}{item.value:>12}{item.droot:12}"
|
||||
echo "\nTotal count: ", items.len
|
||||
|
||||
# Build the list of items.
|
||||
var items: seq[Item]
|
||||
for word in lines("unixdict.txt"):
|
||||
if word.len >= 4 and card(word.toSet - LowerHexDigits) == 0:
|
||||
let val = word.parseHexInt()
|
||||
items.add (word, val, val.digitalRoot)
|
||||
|
||||
# Sort the items by increasing digital root and display the result.
|
||||
echo "Hex words in “unixdict.txt”:\n"
|
||||
items = items.sortedByIt(it.droot)
|
||||
items.display()
|
||||
|
||||
# Remove the items with less than 4 distinct letters.
|
||||
for i in countdown(items.high, 0):
|
||||
if card(items[i].word.toSet) < 4:
|
||||
items.delete i
|
||||
|
||||
# Sort the items by decreasing value and display the result.
|
||||
echo "\n\nHex words with more than three distinct letters:\n"
|
||||
items = items.sortedByIt(-it.value)
|
||||
items.display()
|
||||
21
Task/Hex-words/Perl/hex-words.pl
Normal file
21
Task/Hex-words/Perl/hex-words.pl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict; # https://rosettacode.org/wiki/Hex_words
|
||||
use warnings;
|
||||
use List::AllUtils qw( nsort_by uniq );
|
||||
|
||||
sub root
|
||||
{
|
||||
local $_ = shift;
|
||||
$_ = eval while s/\B/+/g;
|
||||
return $_;
|
||||
}
|
||||
|
||||
my @bydecimal = grep +(uniq /[a-f]/g)[3],
|
||||
my @byroot = map { sprintf "%10s %10d %3d\n", $_, hex $_, root hex $_
|
||||
} do { local(@ARGV, $/) = 'unixdict.txt'; <> =~ /^[a-f]{4,}$/gm };
|
||||
|
||||
print +(nsort_by { (split ' ')[2] } @byroot),
|
||||
"total count = @{[ scalar @byroot ]} and @{[ scalar @bydecimal
|
||||
]} have at least 4 distinct digits\n",
|
||||
reverse nsort_by { (split ' ')[1] } @bydecimal;
|
||||
30
Task/Hex-words/Phix/hex-words.phix
Normal file
30
Task/Hex-words/Phix/hex-words.phix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">af</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)<=</span><span style="color: #008000;">'f'</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">min</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)>=</span><span style="color: #008000;">'a'</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">digital_root</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">></span><span style="color: #000000;">9</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">tot</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">tot</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
<span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tot</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">n</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">words</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">unix_dict</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">),</span><span style="color: #000000;">af</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">decml</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">to_integer</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">words</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">16</span><span style="color: #0000FF;">}),</span>
|
||||
<span style="color: #000000;">roots</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">decml</span><span style="color: #0000FF;">,</span><span style="color: #000000;">digital_root</span><span style="color: #0000FF;">),</span>
|
||||
<span style="color: #000000;">tags</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">custom_sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">roots</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">roots</span><span style="color: #0000FF;">)))</span>
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">caejasp</span><span style="color: #0000FF;">()</span> <span style="color: #000080;font-style:italic;">-- columnize/apply/extract/join/apply/sprint(...)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">extract</span><span style="color: #0000FF;">,{{</span><span style="color: #000000;">words</span><span style="color: #0000FF;">,</span><span style="color: #000000;">decml</span><span style="color: #0000FF;">,</span><span style="color: #000000;">roots</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">}}))</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%6s -> %8d -> %d\n"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">s</span><span style="color: #0000FF;">}))</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %s\n %d hex words with 4 or more letters found,\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">caejasp</span><span style="color: #0000FF;">(),</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">ge4</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #000000;">words</span><span style="color: #0000FF;">[</span><span style="color: #000000;">t</span><span style="color: #0000FF;">]))>=</span><span style="color: #000000;">4</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
<span style="color: #000000;">tags</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ge4</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">tags</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">extract</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">custom_sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">extract</span><span style="color: #0000FF;">(</span><span style="color: #000000;">decml</span><span style="color: #0000FF;">,</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">)))))</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %d with 4 or more distinct characters:\n\n %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tags</span><span style="color: #0000FF;">),</span><span style="color: #000000;">caejasp</span><span style="color: #0000FF;">()})</span>
|
||||
<!--
|
||||
23
Task/Hex-words/Python/hex-words.py
Normal file
23
Task/Hex-words/Python/hex-words.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
def digroot(n):
|
||||
while n > 9:
|
||||
n = sum([int(d) for d in str(n)])
|
||||
return n
|
||||
|
||||
with open('unixdict.txt') as f:
|
||||
lines = [w.strip() for w in f.readlines()]
|
||||
words = [w for w in lines if len(w) >= 4 and all(c in 'abcdef' for c in w)]
|
||||
results = [[w, int(w, 16)] for w in words]
|
||||
for a in results:
|
||||
a.append(digroot(a[1]))
|
||||
|
||||
print(f"Hex words in unixdict.txt:\nRoot Word Base 10\n", "-"*22)
|
||||
for a in sorted(results, key=lambda x:x[2]):
|
||||
print(f"{a[2]} {a[0]:6}{a[1]:10}")
|
||||
|
||||
print("Total count of these words:", len(results))
|
||||
print("\nHex words with > 3 distinct letters:\nRoot Word Base 10\n", "-"*22)
|
||||
results = [a for a in results if len(set(str(a[0]))) > 3]
|
||||
for a in sorted(results, key=lambda x:x[2]):
|
||||
print(f"{a[2]} {a[0]:6}{a[1]:10}")
|
||||
|
||||
print("Total count of those words:", len(results))
|
||||
55
Task/Hex-words/Quackery/hex-words.quackery
Normal file
55
Task/Hex-words/Quackery/hex-words.quackery
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
[ 1 - 9 mod 1+ ] is digitalroot ( n --> n )
|
||||
|
||||
[ 0 swap witheach
|
||||
[ bit | ]
|
||||
0 swap
|
||||
[ dup while
|
||||
tuck 1 & +
|
||||
swap 1 >>
|
||||
again ]
|
||||
drop ] is uniques ( $ --> n )
|
||||
|
||||
[ tuck space swap of
|
||||
join
|
||||
swap split drop echo$ ] is lecho$ ( $ n --> )
|
||||
|
||||
|
||||
$ 'rosetta/unixdict.txt' sharefile drop
|
||||
nest$
|
||||
[] swap witheach
|
||||
[ dup size 4 < iff drop done
|
||||
true over witheach
|
||||
[ char a char g within
|
||||
not if [ conclude not ] ]
|
||||
iff [ nested join ]
|
||||
else drop ]
|
||||
16 base put
|
||||
[] swap witheach
|
||||
[ dup dip nested
|
||||
$->n drop join
|
||||
nested join ]
|
||||
base release
|
||||
[] swap witheach
|
||||
[ dup 1 peek
|
||||
digitalroot
|
||||
join nested join ]
|
||||
dup
|
||||
sortwith [ 2 peek swap 2 peek < ]
|
||||
witheach
|
||||
[ unpack echo sp
|
||||
swap 6 lecho$
|
||||
sp echo cr ]
|
||||
dup size echo say " words"
|
||||
cr cr
|
||||
[] swap witheach
|
||||
[ dup 0 peek
|
||||
uniques 4 < iff
|
||||
drop
|
||||
else [ nested join ] ]
|
||||
sortwith [ 1 peek swap 1 peek > ]
|
||||
dup
|
||||
witheach
|
||||
[ unpack echo sp
|
||||
swap 6 lecho$
|
||||
sp echo cr ]
|
||||
size echo say " words"
|
||||
12
Task/Hex-words/Raku/hex-words.raku
Normal file
12
Task/Hex-words/Raku/hex-words.raku
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
sub dr (Int $_ is copy) { $_ = dr(.comb.sum) while .chars > 1; $_ }
|
||||
|
||||
my %hex = './unixdict.txt'.IO.slurp.words.grep( *.chars > 3 )\
|
||||
.grep({ not / <-[abcdef]> / }).map: { $_ => dr :16($_).comb.sum }
|
||||
|
||||
say "{+%hex} hex words longer than 3 characters found in unixdict.txt:";
|
||||
printf "%6s ➡ %8d ➡ %d\n", .key, :16(.key), .value for %hex.sort: { .value, .key }
|
||||
|
||||
my %many = %hex.grep: +*.key.comb.Set > 3;
|
||||
|
||||
say "\nOf which {+%many} contain at least four distinct characters:";
|
||||
printf "%6s ➡ %8d ➡ %d\n", .key, :16(.key), .value for %many.sort: { -:16(.key) }
|
||||
10
Task/Hex-words/Ruby/hex-words.rb
Normal file
10
Task/Hex-words/Ruby/hex-words.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
def report(a)
|
||||
puts
|
||||
a.each {|hexword| puts "%6s %8d %d" % hexword}
|
||||
puts "Total count of these words: #{a.size}"
|
||||
end
|
||||
|
||||
hexwords = File.readlines("unixdict.txt", chomp: true).reject{|w| w.size < 4 || w.match?(/[^abcdef]/) }
|
||||
res = hexwords.map{|hw| [hw, hw.to_i(16), 1 + (hw.to_i(16) - 1) % 9]}.sort_by(&:last)
|
||||
report( res )
|
||||
report( res.reject{|hw| hw[0].chars.uniq.size < 4}.sort_by{|w| -w[1]} )
|
||||
57
Task/Hex-words/V-(Vlang)/hex-words.v
Normal file
57
Task/Hex-words/V-(Vlang)/hex-words.v
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import os
|
||||
import strconv
|
||||
import math
|
||||
|
||||
fn digital_root(nn i64) i64 {
|
||||
mut n := nn
|
||||
for n>9 {
|
||||
mut tot := i64(0)
|
||||
for n>0 {
|
||||
tot += n%10
|
||||
n = int(math.floor(n/10))
|
||||
}
|
||||
n = tot
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
fn main() {
|
||||
hex_digits := 'abcdef'
|
||||
words := os.read_lines('unixdict.txt')?
|
||||
mut lines := [][]string{}
|
||||
//println(words)
|
||||
for word in words {
|
||||
if word.len < 4 {
|
||||
continue
|
||||
}
|
||||
if word.split('').all(hex_digits.index(it) or {-1} >= 0) {
|
||||
num := strconv.parse_int(word, 16, 32) or {-1}
|
||||
lines << [word, num.str(), digital_root(num).str()]
|
||||
}
|
||||
}
|
||||
lines.sort_with_compare(fn(mut a []string, mut b []string) int {
|
||||
if a[2].int()<b[2].int(){
|
||||
return -1
|
||||
}else if a[2].int()>b[2].int(){
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
})
|
||||
for line in lines {
|
||||
println('${line[0]:8} -> ${line[1]:9} -> ${line[2]}')
|
||||
}
|
||||
println('$lines.len hex words with 4 or more letters found')
|
||||
lines = lines.filter(fn (a []string) bool {
|
||||
mut s := map[string]bool{}
|
||||
for t in a[0].split('') {
|
||||
if t !in s {
|
||||
s[t] = true
|
||||
}
|
||||
}
|
||||
return s.len > 3
|
||||
})
|
||||
for line in lines {
|
||||
println('${line[0]:8} -> ${line[1]:9} -> ${line[2]}')
|
||||
}
|
||||
println('$lines.len hex words with 4 or more distinct letters found')
|
||||
}
|
||||
27
Task/Hex-words/Wren/hex-words.wren
Normal file
27
Task/Hex-words/Wren/hex-words.wren
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import "./ioutil" for FileUtil
|
||||
import "./fmt" for Conv, Fmt
|
||||
import "./math" for Int
|
||||
import "./seq" for Lst
|
||||
|
||||
var words = FileUtil.readLines("unixdict.txt").where { |w| w.count > 0 && w[0].bytes[0] < 103 }
|
||||
var hexDigits = "abcdef"
|
||||
var lines = []
|
||||
for (word in words) {
|
||||
if (word.count < 4) continue
|
||||
if (word.all { |c| hexDigits.contains(c) }) {
|
||||
var num = Conv.atoi(word, 16)
|
||||
var dr = Int.digitalRoot(num)[0]
|
||||
lines.add(Fmt.swrite("$-7s -> $-9s -> $d", word, num, dr))
|
||||
}
|
||||
}
|
||||
lines.sort { |a, b| a[-1].bytes[0] < b[-1].bytes[0] }
|
||||
System.print(lines.join("\n"))
|
||||
System.print("\n%(lines.count) hex words with 4 or more letters found.\n")
|
||||
var digits4 = []
|
||||
for (line in lines) {
|
||||
var word = line.split("->")[0].trimEnd()
|
||||
if (Lst.distinct(word.toList).count >= 4) digits4.add(line)
|
||||
}
|
||||
digits4.sort { |a, b| Num.fromString(a.split("->")[1]) > Num.fromString(b.split("->")[1]) }
|
||||
System.print(digits4.join("\n"))
|
||||
System.print("\n%(digits4.count) such words found which contain 4 or more different digits.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue