Cantor set: Difference between revisions
Content deleted Content added
Line 1,576:
███ ███ ███ ███
█ █ █ █ █ █ █ █</pre>
=={{header|jq}}==
<lang jq># cantor(width; height)
def cantor($w; $h):
def init: [range(0; $h) | [range(0; $w) | "*"]];
def cantor($start; $leng; $ix):
($leng/3|floor) as $seg
| if $seg == 0 then .
else reduce range($ix; $h) as $i (.;
reduce range($start+$seg; $start + 2*$seg) as $j (.; .[$i][$j] = " "))
| cantor($start; $seg; $ix+1)
| cantor($start + 2*$seg; $seg; $ix+1)
end ;
init | cantor(0; $w; 1);
def pp: .[] | join("");
cantor($width; $height)
| pp</lang>
{{out}}
With the above in a file, cantor.jq, the following incantation
yields the same output as shown e.g. under `awk`, `julia`, etc.
jq -nr --argjson width 81 --argjson height 5 -f cantor.jq
=={{header|Julia}}==
|