Sliding Capitals

11

The Background

Imagine the English alphabet written out in a row in capital letters -- ABCDEFGHIJKLMNOPQRSTUVWXYZ. Suppose we have a special variable-width lens such that, when placed over the row, it shows a certain "window" of the alphabet, with letters outside the lens hidden from view. Additionally, this lens has a warping characteristic, so that the first letter inside the lens, and every second letter thereafter, is lower-cased, but the remaining letters still show capitalized.

For example, we could have a lens of length 5 placed somewhere in the middle of the alphabet and we would only see . jKlMn (leading period here to ensure whitespace shows) -- note the K and M are still capitalized, while the j, l, and n are all lower-cased. As we slide this lens from left-to-right along the alphabet, different letters would be shown and different letters capitalized. The task here is to output the resultant letters as the lens slides along the alphabet.

The Challenge

Write a program or function that takes an input integer 0 < n < 27 and outputs or returns the string(s) that are visible as the lens described above slides across the alphabet.

For values of n larger than 1, the lens begins by "hanging" off the left side of the alphabet, so only the A is shown in the right-most slot of the lens. The first line of any output will thus be a single A, either capital or lowercase depending upon the length of the lens.

Similarly, the lens finishes sliding when the Z is in the left-most slot of the lens (meaning that the very last line in any output will always be 25 spaces followed by a lowercase z).

The Examples

Input: 1

Output:

a
 b
  c
   d
    e
     f
      g
       h
        i
         j
          k
           l
            m
             n
              o
               p
                q
                 r
                  s
                   t
                    u
                     v
                      w
                       x
                        y
                         z

Input: 4

Output:

A
aB
AbC
aBcD
 bCdE
  cDeF
   dEfG
    eFgH
     fGhI
      gHiJ
       hIjK
        iJkL
         jKlM
          kLmN
           lMnO
            mNoP
             nOpQ
              oPqR
               pQrS
                qRsT
                 rStU
                  sTuV
                   tUvW
                    uVwX
                     vWxY
                      wXyZ
                       xYz
                        yZ
                         z

Input: 26

Output:

A
aB
AbC
aBcD
AbCdE
aBcDeF
AbCdEfG
aBcDeFgH
AbCdEfGhI
aBcDeFgHiJ
AbCdEfGhIjK
aBcDeFgHiJkL
AbCdEfGhIjKlM
aBcDeFgHiJkLmN
AbCdEfGhIjKlMnO
aBcDeFgHiJkLmNoP
AbCdEfGhIjKlMnOpQ
aBcDeFgHiJkLmNoPqR
AbCdEfGhIjKlMnOpQrS
aBcDeFgHiJkLmNoPqRsT
AbCdEfGhIjKlMnOpQrStU
aBcDeFgHiJkLmNoPqRsTuV
AbCdEfGhIjKlMnOpQrStUvW
aBcDeFgHiJkLmNoPqRsTuVwX
AbCdEfGhIjKlMnOpQrStUvWxY
aBcDeFgHiJkLmNoPqRsTuVwXyZ
 bCdEfGhIjKlMnOpQrStUvWxYz
  cDeFgHiJkLmNoPqRsTuVwXyZ
   dEfGhIjKlMnOpQrStUvWxYz
    eFgHiJkLmNoPqRsTuVwXyZ
     fGhIjKlMnOpQrStUvWxYz
      gHiJkLmNoPqRsTuVwXyZ
       hIjKlMnOpQrStUvWxYz
        iJkLmNoPqRsTuVwXyZ
         jKlMnOpQrStUvWxYz
          kLmNoPqRsTuVwXyZ
           lMnOpQrStUvWxYz
            mNoPqRsTuVwXyZ
             nOpQrStUvWxYz
              oPqRsTuVwXyZ
               pQrStUvWxYz
                qRsTuVwXyZ
                 rStUvWxYz
                  sTuVwXyZ
                   tUvWxYz
                    uVwXyZ
                     vWxYz
                      wXyZ
                       xYz
                        yZ
                         z

The Rules

  • Standard input/output rules apply
  • Standard loopholes disallowed
  • Standard code-golf rules apply
  • The leading whitespace as shown is required, so that we know where we're at in the alphabet.
  • Each line cannot have trailing whitespace (as shown - the output is not a rectangle).
  • A single trailing newline is optional.

AdmBorkBork

Posted 2016-02-17T18:51:16.637

Reputation: 41 581

1Related – Alex A. – 2016-02-17T20:13:31.780

Answers

2

Pyth, 31 bytes

Vr_tQ26s.erb%+Nk2+*Nd:GeS,0N+NQ

Try it online. Test suite.

Quick and dirty.

PurkkaKoodari

Posted 2016-02-17T18:51:16.637

Reputation: 16 699

2

JavaScript (ES6), 130 bytes

n=>[...Array(n+25)].map(_=>[...Array(26)].map(_=>String.fromCharCode(j++<i|i+n<j?32:j+(j-i)%2*32),++i,j=64).join``,i=64-n).join`\n`

Where \n represents the literal newline character. Works by looping over the output rectangle and outputting spaces outside the diagonal while adding 32 to the character code to lower case it in alternate squares. Using replace appears to be 1 byte longer:

n=>[...Array(n+25)].map(_=>' '.repeat(26).replace(/./g,s=>j++<i|i+n<j?s:String.fromCharCode(j+(j-i)%2*32),++i,j=64),i=64-n).join`\n`

Neil

Posted 2016-02-17T18:51:16.637

Reputation: 95 035

1

AWK, 160 bytes

{d=-$1
m=25
for(;i<m+$1;i++){f="%"(++d<0?0:d<m?d:m)"s"
c=u=65
l=97
printf f,""
for(j=++E-$1;j<E&&j<26;j++){c=c==u?l:u
if(j<0)continue
printf("%c",j+c)}print""}}

That's about as tight as I can come up with in AWK. Having 3 different prints and a continue really add to the byte-count.

Robert Benson

Posted 2016-02-17T18:51:16.637

Reputation: 1 339