Skip to main content
added 1 character in body
Source Link
darrylyeo
  • 7.9k
  • 21
  • 44

JavaScript (ES6), 382 380380 370 bytes

f=(a,N)=>{X=Y=0
if(a[1]){Y=a[1].trim()[0]=='B'
X=z=a[0][1]==a[1][0]?1:!Y
l="ABCDEFGHIJKLMNOPQRSTUVWXYZ".slicel="ABCDEFGHIJKLMNOPQRSTUVWXYZ"[s='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.slicei]=a[N+i]=L[s](0,-1)+l[N-i-1].repeat(i*2)+[...L].reverse().join``
L=L.sliceL=L[s](0,-1)
return a}if(a[1][1]=='C')for(i=0;a[i++]=l,i<N;)l=l.slicel=l[s](1)+l[0]}}else X=1
a=X?a.map(l=>l.slicel=>l[s](0,N)):a
return Y?a.slicea[s](0,N):a}

JavaScript (ES6), 382 380 bytes

f=(a,N)=>{X=Y=0
if(a[1]){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]}}else X=1
a=X?a.map(l=>l.slice(0,N)):a
return Y?a.slice(0,N):a}

JavaScript (ES6), 382 380 370 bytes

f=(a,N)=>{X=Y=0
if(a[1]){Y=a[1].trim()[0]=='B'
X=z=a[0][1]==a[1][0]?1:!Y
l="ABCDEFGHIJKLMNOPQRSTUVWXYZ"[s='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[s](0,-1)+l[N-i-1].repeat(i*2)+[...L].reverse().join``
L=L[s](0,-1)
return a}if(a[1][1]=='C')for(i=0;a[i++]=l,i<N;)l=l[s](1)+l[0]}}else X=1
a=X?a.map(l=>l[s](0,N)):a
return Y?a[s](0,N):a}
added 160 characters in body
Source Link
darrylyeo
  • 7.9k
  • 21
  • 44

JavaScript (ES6), 382382 380 bytes

f=(a,N)=>{X=0
Y=0X=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
return a}if(a[1][1]=='C')for(i=0;a[i++]=l,i<N;)l=l.slice(1)+l[0]}}else X=1
a=X?a.map(l=>l.slice(0,N)):a
return Y?a.slice(0,N):a}

Slightly lessLess 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
                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 if necessary.
    a=X?a.map(l=>l.slice(0,N)):a
    
    // Truncate array vertically if necessary.
    return Y?a.slice(0,N):a
}

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}

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
}

JavaScript (ES6), 382 380 bytes

f=(a,N)=>{X=Y=0
if(a[1]){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]}}else X=1
a=X?a.map(l=>l.slice(0,N)):a
return Y?a.slice(0,N):a}

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 if necessary.
    a=X?a.map(l=>l.slice(0,N)):a
    
    // Truncate array vertically if necessary.
    return Y?a.slice(0,N):a
}
added 800 characters in body
Source Link
darrylyeo
  • 7.9k
  • 21
  • 44

Slightly less golfed version for my own sanitywith 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(!a[1]I=a[1]){
X=1
}else{        // If the first non-whitespace character in the second row == 'B', truncate vertically.
        if(a[1]I.trim()[0]=='B')Y=1
X=z=a[0][1]==a[1][0]        // 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)
            // GenerateIf 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}
            // GenerateIf 2nd character in row 2 == 'C', fill array with a Tabula Recta.
            if(a[1][1]=='C'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
}

Slightly less golfed version for my own sanity:

f=(a,N)=>{
X=0
Y=0
if(!a[1]){
X=1
}else{
if(a[1].trim()[0]=='B')Y=1
X=z=a[0][1]==a[1][0]?1:!Y
if(z){
l="ABCDEFGHIJKLMNOPQRSTUVWXYZ".slice(0,N)
// Generate Square
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}
// Generate Tabula Recta
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
}

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
}
Source Link
darrylyeo
  • 7.9k
  • 21
  • 44
Loading