Sierpinski triangle: Difference between revisions

Line 3,510:
* * * * * * * *
* * * * * * * * * * * * * * * *</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
'''Preliminaries'''
<lang jq>def elementwise(f):
transpose | map(f) ;
 
# input: an array of decimal numbers
def bitwise_and:
# Input: an integer
# Output: a stream of 0s and 1s
def stream:
recurse(if . > 0 then ./2|floor else empty end) | . % 2 ;
 
# Input: a 0-1 array
def toi:
reduce .[] as $c ( {power:1 , ans: 0};
.ans += ($c * .power) | .power *= 2 )
| .ans;
 
if any(.==0) then 0
else map([stream])
| (map(length) | min) as $min
| map( .[:$min] ) | elementwise(min) | toi
end;</lang>
<lang jq>
def sierpinski:
pow(2; .) as $size
| range($size-1; -1; -1) as $y
| reduce range(0; $size - $y) as $x ( (" " * $y);
. + (if ([$x,$y]|bitwise_and) == 0 then "* " else " " end));
 
4 | sierpinski</lang>
{{out}}
As elsewhere.
 
=={{header|Julia}}==
2,478

edits