##bash, sed and coreutils, (削除) 95 (削除ここまで) 89 bytes
bash, sed and coreutils, (削除) 95 (削除ここまで) 89 bytes
You can define a function like this
f(){ n=$[1ドル-2];yes \ |sed $[2ドル*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
##bash, sed and coreutils, (削除) 95 (削除ここまで) 89 bytes
You can define a function like this
f(){ n=$[1ドル-2];yes \ |sed $[2ドル*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
bash, sed and coreutils, (削除) 95 (削除ここまで) 89 bytes
You can define a function like this
f(){ n=$[1ドル-2];yes \ |sed $[2ドル*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
##bash, sed and coreutils, 95(削除) 95 (削除ここまで) 89 bytes
You can define a function like this
f(){ n=$((1ドルn=$[1ドル-2));yes2];yes \ |head|sed -n$((2ドル*n))|tr$[2ドル*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
##bash and coreutils, 95 bytes
You can define a function like this
f(){ n=$((1ドル-2));yes \ |head -n$((2ドル*n))|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
##bash, sed and coreutils, (削除) 95 (削除ここまで) 89 bytes
You can define a function like this
f(){ n=$[1ドル-2];yes \ |sed $[2ドル*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
##bash and coreutils, 95 bytes
You can define a function like this
f(){ n=$((1ドル-2));yes \ |head -n$((2ドル*n))|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
##bash and coreutils, 95 bytes
You can define a function like this
f(){ n=$((1ドル-2));yes \ |head -n$((2ドル*n))|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.
##bash and coreutils, 95 bytes
You can define a function like this
f(){ n=$((1ドル-2));yes \ |head -n$((2ドル*n))|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
Or in a more readable format:
f() {
n=$((1ドル-2))
# The next couple of lines create a rectangle of spaces
# matching the desired size
yes ' ' |
head -n$((2ドル*n)) |
tr -d '\n' |
fold -w$n |
# Add the pipes and dashes
sed '
s/^\|$/|/g # Replace first and last character by a pipe
1! {$!b } # Do nothing if not on first or last line
s/ /-/g # Add the dashes
'
echo
}
You can now say f 4 3:
|--|
| |
|--|
If you care about trailing new-line, add an echo at the end of function.