Skip to main content
2 of 4
added 800 characters in body
darrylyeo
  • 7.9k
  • 21
  • 44

JavaScript (ES6), 382 bytes

f=(a,N)=>{X=0
Y=0
if(!a[1])X=1
else{Y=a[1].trim()[0]=='B'
X=z=a[0][1]==a[1][0]?1:!Y
l="ABCDEFGHIJKLMNOPQRSTUVWXYZ".slice(0,N)
if(z){if(a[0][1]=='A'){for(a=[],i=0,L=l;i<N;i++)a[N-i]=a[N+i]=L.slice(0,-1)+l[N-i-1].repeat(i*2)+[...L].reverse().join``,L=L.slice(0,-1);return a}if(a[1][1]=='C')for(i=0;a[i++]=l,i<N;)l=l.slice(1)+l[0]}}a=X?a.map(l=>l.slice(0,N)):a
return Y?a.slice(0,N):a}

Pass an array of strings to the function f(), like this:

f(
`AAAAAAA
ABBBBBA
ABCCCBA
ABCDCBA
ABCCCBA
ABBBBBA
AAAAAAA`.split('\n'), 3)

Slightly less golfed version with comments:

f=(a,N)=>{
    // Whether to truncate array horizontally to width N.
    X=0
    // Whether to truncate array vertically to height N.
    Y=0
    // If a second row exists
    if(I=a[1]){
        // If the first non-whitespace character in the second row == 'B', truncate vertically.
        if(I.trim()[0]=='B')Y=1
        // Truncate horizontally if 2nd character in row 1 == 1st character in row 2; otherwise, if not truncating vertically.
        X=z=a[0][1]==I[0]?1:!Y
        // If 2nd character in row 1 == 1st character in row 2
        if(z){
            // Make an alphabet.
            l="ABCDEFGHIJKLMNOPQRSTUVWXYZ".slice(0,N)
            // If 2nd character in row 1 == 'A', forget everything we just did. Make a new array, generate a Square pattern, then return it.
            if(a[0][1]=='A'){for(a=[],i=0,L=l;i<N;i++)a[N-i]=a[N+i]=L.slice(0,-1)+l[N-i-1].repeat(i*2)+[...L].reverse().join``,L=L.slice(0,-1);return a}
            // If 2nd character in row 2 == 'C', fill array with a Tabula Recta.
            if(I[1]=='C')for(i=0;a[i++]=l,i<N;)l=l.slice(1)+l[0]
        }
    }else{
        // If a second row doesn't exist, it's a horizontal line; truncate horizontally.
        X=1
    }
    
    // Truncate array horizontally.
    a=X?a.map(l=>l.slice(0,N)):a
    // Truncate array vertically.
    return Y?a.slice(0,N):a
}
darrylyeo
  • 7.9k
  • 21
  • 44