def count(s): reduce s as $x (0; .+1); # For pretty-printing def nwise($n): def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end; n; def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;