Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
11
Task/Sierpinski-carpet/UNIX-Shell/sierpinski-carpet-1.sh
Normal file
11
Task/Sierpinski-carpet/UNIX-Shell/sierpinski-carpet-1.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
sierpinski_carpet() {
|
||||
local -i n="${1:-3}"
|
||||
local carpet="${2:-#}"
|
||||
while (( n-- )); do
|
||||
local center="${carpet//#/ }"
|
||||
carpet="$(paste -d ' ' <(echo "$carpet"$'\n'"$carpet"$'\n'"$carpet") <(echo "$carpet"$'\n'"$center"$'\n'"$carpet") <(echo "$carpet"$'\n'"$carpet"$'\n'"$carpet"))"
|
||||
done
|
||||
echo "$carpet"
|
||||
}
|
||||
22
Task/Sierpinski-carpet/UNIX-Shell/sierpinski-carpet-2.sh
Normal file
22
Task/Sierpinski-carpet/UNIX-Shell/sierpinski-carpet-2.sh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
sierpinski_carpet() {
|
||||
typeset -i n=${1:-3}
|
||||
if (( n < 1 )); then
|
||||
return 1
|
||||
fi
|
||||
typeset -i size x y
|
||||
typeset x1 y1
|
||||
(( size = 3 ** n ))
|
||||
for (( y=0; y<size; ++y )); do
|
||||
y1=$(dc <<<"$y 3op")
|
||||
for (( x=0; x<size; ++x )); do
|
||||
x1=$(dc <<<"$x 3op")
|
||||
if (( 2#${x1//2/0} & 2#${y1//2/0} )); then
|
||||
printf ' '
|
||||
else
|
||||
printf '#'
|
||||
fi
|
||||
done
|
||||
printf '\n'
|
||||
done
|
||||
}
|
||||
sierpinski_carpet 3
|
||||
Loading…
Add table
Add a link
Reference in a new issue