Hex words: Difference between revisions
m
syntax highlighting fixup automation
(→{{header|J}}: flip second part to match (now clearly stated) requirement, also reduce vertical page space used) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 16:
{{trans|Python}}
<
L n > 9
n = sum(String(n).map(d -> Int(d)))
Line 35:
print(f:‘{a[2]} {a[0]:<6}{a[1]:10}’)
print(‘Total count of those words: ’results.len)</
{{out}}
Line 90:
=={{header|ALGOL 68}}==
<
IF FILE input file;
STRING file name = "unixdict.txt";
Line 214:
OD;
print( ( "Found ", whole( count 4, 0 ), " hex words with 4 or more distinct digits", newline ) )
FI</
{{out}}
<pre>
Line 263:
=={{header|Arturo}}==
<
hexWords: new []
Line 301:
printTable sort.by:'root hexWords
printTable sort.descending.by:'decimal select hexWords 'h ->
4 =< size unique split h\hex</
{{out}}
Line 355:
=={{header|AutoHotkey}}==
<
hexWords := Hex_words(wList)
Header := "Base 10`t`tWord`tRoot`n"
Line 398:
until (sum < 10)
return sum
}</
{{out}}
<pre>Base 10 Word Root
Line 445:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f HEX_WORDS.AWK unixdict.txt
{ nf += NF
Line 500:
return num + (length(s) ? 16*hex2dec(s) : 0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 551:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
math math.parser prettyprint sequences sets sorting ;
Line 572:
words [ cardinality 3 > ] filter [ hex> ] f info-by
" such words found which contain 4 or more different digits." print</
{{out}}
<pre>
Line 620:
=={{header|J}}==
<
26
│1│43966 │abbe │
Line 662:
│3│44013 │abed │
│1│14600926│decade│
│1│57007 │deaf │</
=={{header|jq}}==
Line 669:
'''Preliminaries'''
<
# . may be a decimal number or a string representing a decimal number
Line 691:
.[1] += $i * .[0]
| .[0] *= 16 )
| .[1]; </
'''The Task'''
<
def format: "\(.[0]|lpad(8)) -> \(.[1]|lpad(9)) -> \(.[2])";
Line 715:
(($digits4|sort_by(.[1])|reverse[] ) | format) ;
task</
{{out}}
'''Invocation'''
Line 767:
=={{header|Julia}}==
<
function hexwords(wordfile = "unixdict.txt")
Line 790:
hexwords()
</
<pre>
Hex words in unixdict.txt:
Line 843:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Hex_words
Line 863:
"total count = @{[ scalar @byroot ]} and @{[ scalar @bydecimal
]} have at least 4 distinct digits\n",
reverse nsort_by { (split ' ')[1] } @bydecimal;</
{{out}}
<pre>
Line 909:
=={{header|Phix}}==
<!--<
<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>
Line 938:
<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>
<!--</
{{out}}
<pre>
Line 987:
=={{header|Python}}==
<
while n > 9:
n = sum([int(d) for d in str(n)])
Line 1,010:
print("Total count of those words:", len(results))
</
<pre>
Hex words in unixdict.txt:
Line 1,064:
=={{header|Raku}}==
Sorted by digital root with a secondary alphabetical sort.
<syntaxhighlight lang="raku"
my %hex = './unixdict.txt'.IO.slurp.words.grep( *.chars > 3 )\
Line 1,075:
say "\nOf which {+%many} contain at least four distinct characters:";
printf "%6s ➡ %8d ➡ %d\n", .key, :16(.key), .value for %many.sort: { -:16(.key) }</
{{out}}
<pre>26 hex words longer than 3 characters found in unixdict.txt:
Line 1,122:
=={{header|Vlang}}==
{{trans|wren}}
<
import strconv
import math
Line 1,178:
}
println('$lines.len hex words with 4 or more distinct letters found')
}</
{{out}}
<pre>Same as wren entry</pre>
Line 1,187:
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
<
import "./fmt" for Conv, Fmt
import "./math" for Int
Line 1,213:
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.")</
{{out}}
|