Determine if a string has all unique characters: Difference between revisions

→‎{{header|jq}}: general hex function
(→‎{{header|jq}}: general hex function)
Line 2,106:
 
Some helper functions for accomplishing other aspects of the task:
<lang jq>def# hex: of a number or a single (unicode) character
def hex:
def hx: [if . < 10 then 48 + . else 55 + . end] | implode ;
def stream:
explode[0] | "\(./16 | floor | hx)\(. % 16 | hx)";
recurse(if . > 0 then ./16|floor else empty end) | . % 16 ;
if type=="string" then explode[0] else . end
| if . == 0 then "0"
else [stream] | reverse | .[1:]
def hx: [| map(if . < 10 then 48 + . else 55. + .87 end]) | implode ;
end;
 
def lpad($len): tostring | ($len - length) as $l | (" " * ($llen - width)[:$l] + .;
 
def q: "«\(.)»";
Line 2,135 ⟶ 2,141:
«abcABC» : 6 : : []
«XYZ ZYX» : 7 : Z : 5A [2,4]
«1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ» : 36 : 0 : 30 [9,24]</lang>
 
=={{header|Julia}}==
2,469

edits