Skip to main content
added 719 characters in body
Source Link
Ivan
  • 209
  • 1
  • 5

BASH , 580 349 308 303 291 286 283 277 275 272 275271 bytes

Found this very entertaining, thanks! First variant was 580 bytes, then 349, ..., now 275271:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;((i+=$2b=$3;$[i+=$2,c++));S[ic++];S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;((n\>;$[n-=a));f=a];f . $N \|;f \' -2 - \<;((n\<;$[n--));f];f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n"$T\\n "${S[@]}"

Try it online!Try it online!

Squeezed to 275271(with 2>/dev/null):

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]
 
f(){ 
    b=$1
    for((j=1;j<n;j++)); {
        ((c<N))&&T+=%s
        [[ $4 ]]&&h=$4 S[i+$2/2]=-
        t=${s:c:1} S[i]=${t:-$b} b=$3
        ((i+=$2$[i+=$2,c++))c++]
        S[i-($2/N)]=\ 
    }
}
 
while((n>0));do
    f .  2    - \>; ((n$[n-=a))=a]
    f .  $N  \|
    f \' -2   - \<; ((n$[n--))]
    f \' -$N \|   ;   a=1
done;S[i]=$h;printf "$T\n" "${S[@]}"

And if we run script with 2>/dev/null we can squeezed it up to 272:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;$[i+=$2,c++];S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;$[n-=a];f . $N \|;f \' -2 - \<;$[n--];f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n"$T\\n "${S[@]}"

Try it online!

BASH , 580 349 308 303 291 286 283 277 275 bytes

Found this very entertaining, thanks! First variant was 580 bytes, then 349, ..., now 275:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;((i+=$2,c++));S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;((n-=a));f . $N \|;f \' -2 - \<;((n--));f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n" "${S[@]}"

Try it online!

Squeezed to 275:

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]
 
f(){ 
    b=$1
    for((j=1;j<n;j++)); {
        ((c<N))&&T+=%s
        [[ $4 ]]&&h=$4 S[i+$2/2]=-
        t=${s:c:1} S[i]=${t:-$b} b=$3
        ((i+=$2,c++))
        S[i-($2/N)]=\ 
    }
}
 
while((n>0));do
    f .  2    - \>; ((n-=a))
    f .  $N  \|
    f \' -2   - \<; ((n--))
    f \' -$N \|   ;   a=1
done;S[i]=$h;printf "$T\n" "${S[@]}"

And if we run script with 2>/dev/null we can squeezed it up to 272:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;$[i+=$2,c++];S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;$[n-=a];f . $N \|;f \' -2 - \<;$[n--];f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n" "${S[@]}"

Try it online!

BASH , 580 349 308 303 291 286 283 277 275 272 271 bytes

Found this very entertaining, thanks! First variant was 580 bytes, then 349, ..., now 271:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;$[i+=$2,c++];S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;$[n-=a];f . $N \|;f \' -2 - \<;$[n--];f \' -$N \|;a=1;done;S[i]=$h;printf $T\\n "${S[@]}"

Try it online!

Squeezed to 271(with 2>/dev/null):

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]
f(){ 
    b=$1
    for((j=1;j<n;j++)); {
        ((c<N))&&T+=%s
        [[ $4 ]]&&h=$4 S[i+$2/2]=-
        t=${s:c:1} S[i]=${t:-$b} b=$3
        $[i+=$2,c++]
        S[i-($2/N)]=\ 
    }
}
while((n>0));do
    f .  2    - \>; $[n-=a]
    f .  $N  \|
    f \' -2   - \<; $[n--]
    f \' -$N \|   ;   a=1
done;S[i]=$h;printf $T\\n "${S[@]}"
added 719 characters in body
Source Link
Ivan
  • 209
  • 1
  • 5

And if we run script with 2>/dev/null we can squeezed it up to 272:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;$[i+=$2,c++];S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;$[n-=a];f . $N \|;f \' -2 - \<;$[n--];f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n" "${S[@]}"

Try it online!

First variant was:

First variant was:

And if we run script with 2>/dev/null we can squeezed it up to 272:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;$[i+=$2,c++];S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;$[n-=a];f . $N \|;f \' -2 - \<;$[n--];f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n" "${S[@]}"

Try it online!

First variant was:

deleted 1357 characters in body
Source Link
Ivan
  • 209
  • 1
  • 5

BASH , 580 349 308 303 291 286 283 277 283275 bytes

Found this very entertaining, thanks! First variant was 580 bytes, then 349, ..., now 283275:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N)) && T+=%s;[[&&T+=%s;[[ $4 ]]&&h=$4 S[$[i+$2S[i+$2/2]]=2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;((i+=$2,c++));S[$[i;S[i-($2/N)]]=\]=\ ;};};while((n>0));do f . 2 - \>;((n-=a));f . $N \|;f \' -2 - \<;((n--));f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n" "${S[@]}"

Try it online!Try it online!

Squeezed to 283275:

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]

f(){ 
    b=$1
    for ((j=1; j<n; j++j=1;j<n;j++)); {
        ((c<N)) && T+="%s"&&T+=%s
        [[ $4 ]] && h=$4]]&&h=$4 S[$[i+$2S[i+$2/2]]=2]=-
        t=${s:c:1} S[i]=${t:-$b} b=$3
        ((i+=$2,c++))
        S[$[iS[i-($2/N)]]=' '
    }
}

while ((n>0)); do
    f .  2    - \>; ((n-=a))
    f .  $N  \|
    f \' -2   - \<; ((n--))
    f \' -$N \|   ;   a=1
done; S[i]=$h; printf "$T\n" "${S[@]}"

Reduced to 349 bytes:

s=$1 n=$2 N=$[n+n-1]; for ((p=0; p<n*N; p++)); { S[p]=" "; }; printf -v T "%${N}s"; T=${T// /%s}; f(){ b=$1; for ((j=1; j<n; j++)); { [[ $4 ]] && h=$4 S[$[i+$2/2]]=-; t=${s:c:1} S[i]=${t:-$b} b=$3; ((i+=$2,c++)); }; }; while ((n>0)); do f . 2 - \>; ((n-=a)); f . $N \|; f \' -2 - \<; ((n--)); f \' -$N \|; a=1; done; S[i]=$h; printf "$T\n" "${S[@]}"

Try it online!

And ungolfed for better readability:

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]
for ((p=0; p<n*N; p++)); { S[p]=" "; }
printf -v T "%${N}s"; T=${T// /%s}

f(){
    b=$1
    for ((j=1; j<n; j++)); {
        [[ $4 ]] && h=$4 S[$[i+$2/2]]=-
        t=${s:c:1} S[i]=${t:-$b}]=\ b=$3
        ((i+=$2,c++))
    }
}

while ((n>0)); do;do
    f .  2    - \>; ((n-=a))
    f .  $N  \|
    f \' -2   - \<; ((n--))
    f \' -$N \|   ;   a=1
done; S[i]=$h; printfdone;S[i]=$h;printf "$T\n" "${S[@]}"

BASH , 580 349 308 303 291 286 283 bytes

Found this very entertaining, thanks! First variant was 580 bytes, then 349, ..., now 283:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N)) && T+=%s;[[ $4 ]]&&h=$4 S[$[i+$2/2]]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;((i+=$2,c++));S[$[i-($2/N)]]=\ ;};};while((n>0));do f . 2 - \>;((n-=a));f . $N \|;f \' -2 - \<;((n--));f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n" "${S[@]}"

Try it online!

Squeezed to 283:

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]

f(){
    b=$1
    for ((j=1; j<n; j++)); {
        ((c<N)) && T+="%s"
        [[ $4 ]] && h=$4 S[$[i+$2/2]]=-
        t=${s:c:1} S[i]=${t:-$b} b=$3
        ((i+=$2,c++))
        S[$[i-($2/N)]]=' '
    }
}

while ((n>0)); do
    f .  2    - \>; ((n-=a))
    f .  $N  \|
    f \' -2   - \<; ((n--))
    f \' -$N \|   ;   a=1
done; S[i]=$h; printf "$T\n" "${S[@]}"

Reduced to 349 bytes:

s=$1 n=$2 N=$[n+n-1]; for ((p=0; p<n*N; p++)); { S[p]=" "; }; printf -v T "%${N}s"; T=${T// /%s}; f(){ b=$1; for ((j=1; j<n; j++)); { [[ $4 ]] && h=$4 S[$[i+$2/2]]=-; t=${s:c:1} S[i]=${t:-$b} b=$3; ((i+=$2,c++)); }; }; while ((n>0)); do f . 2 - \>; ((n-=a)); f . $N \|; f \' -2 - \<; ((n--)); f \' -$N \|; a=1; done; S[i]=$h; printf "$T\n" "${S[@]}"

Try it online!

And ungolfed for better readability:

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]
for ((p=0; p<n*N; p++)); { S[p]=" "; }
printf -v T "%${N}s"; T=${T// /%s}

f(){
    b=$1
    for ((j=1; j<n; j++)); {
        [[ $4 ]] && h=$4 S[$[i+$2/2]]=-
        t=${s:c:1} S[i]=${t:-$b} b=$3
        ((i+=$2,c++))
    }
}

while ((n>0)); do
    f .  2    - \>; ((n-=a))
    f .  $N  \|
    f \' -2   - \<; ((n--))
    f \' -$N \|   ;   a=1
done; S[i]=$h; printf "$T\n" "${S[@]}"

BASH , 580 349 308 303 291 286 283 277 275 bytes

Found this very entertaining, thanks! First variant was 580 bytes, then 349, ..., now 275:

s=$1 n=$2 N=$[n+n-1];f(){ b=$1;for((j=1;j<n;j++));{((c<N))&&T+=%s;[[ $4 ]]&&h=$4 S[i+$2/2]=-;t=${s:c:1} S[i]=${t:-$b} b=$3;((i+=$2,c++));S[i-($2/N)]=\ ;};};while((n>0));do f . 2 - \>;((n-=a));f . $N \|;f \' -2 - \<;((n--));f \' -$N \|;a=1;done;S[i]=$h;printf "$T\n" "${S[@]}"

Try it online!

Squeezed to 275:

#!/bin/bash
s=$1 n=$2 N=$[n+n-1]

f(){ 
    b=$1
    for((j=1;j<n;j++)); {
        ((c<N))&&T+=%s
        [[ $4 ]]&&h=$4 S[i+$2/2]=-
        t=${s:c:1} S[i]=${t:-$b} b=$3
        ((i+=$2,c++))
        S[i-($2/N)]=\ 
    }
}

while((n>0));do
    f .  2    - \>; ((n-=a))
    f .  $N  \|
    f \' -2   - \<; ((n--))
    f \' -$N \|   ;   a=1
done;S[i]=$h;printf "$T\n" "${S[@]}"
removed unnecassary " and '
Source Link
Ivan
  • 209
  • 1
  • 5
Loading
removed unnecassary whitespaces
Source Link
Ivan
  • 209
  • 1
  • 5
Loading
deleted 26 characters in body
Source Link
Ivan
  • 209
  • 1
  • 5
Loading
added 1 character in body
Source Link
Ivan
  • 209
  • 1
  • 5
Loading
added 286 characters in body
Source Link
Ivan
  • 209
  • 1
  • 5
Loading
added 1316 characters in body
Source Link
Ivan
  • 209
  • 1
  • 5
Loading
Add syntax highlighting; Add TIO link to golfed version
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76
Loading
added "short" version
Source Link
Ivan
  • 209
  • 1
  • 5
Loading
Source Link
Ivan
  • 209
  • 1
  • 5
Loading