Skip to main content
2 bytes saved by Stewie Griffin by changing a - 91 < 0 to a < 91
Source Link
jfh
  • 61
  • 5

Java SE 8, 7171 69 bytes

Golfed:

(a,s)->{char b=97;if(a-91<0a<91)b-=32;a=b;b+=26;while(a<b)s+=a++;return s;}

Ungolfed:

(a,s)->{          // String as a parameter. If declaration is necessary it adds 8 bytes
char b = 97;      // Uppercase A char, this is important
if (a -< 91) < 0)     // If it is not past 'z', where a is a char param
    b -= 32;      // Then go back to the lowercase alphabet
a = b;            // Done to prevent a cast
b += 26;          // End of alphabet
while (a < b)     // Go to end of alphabet
    s += a++;     // Append character
return s;}        // Then return

I had originally implemented the following

String s="";char b=96;if(a-91<0)b-=32;for(char c=b;++c<b+27;)s+=c;return s;

It's more elegant but sadly it's one byte larger. This is assuming that behavior for non alpha characters is undefined and string s is initialized to "" prior to execution. Be gentle it's my first post.

edit: 2 bytes saved by Stewie Griffin by changing

a - 91 < 0 to a < 91

Java SE 8, 71 bytes

Golfed:

(a,s)->{char b=97;if(a-91<0)b-=32;a=b;b+=26;while(a<b)s+=a++;return s;}

Ungolfed:

(a,s)->{          // String as a parameter. If declaration is necessary it adds 8 bytes
char b = 97;      // Uppercase A char, this is important
if (a - 91 < 0)   // If it is not past 'z', where a is a char param
    b -= 32;      // Then go back to the lowercase alphabet
a = b;            // Done to prevent a cast
b += 26;          // End of alphabet
while (a < b)     // Go to end of alphabet
    s += a++;     // Append character
return s;}        // Then return

I had originally implemented the following

String s="";char b=96;if(a-91<0)b-=32;for(char c=b;++c<b+27;)s+=c;return s;

It's more elegant but sadly it's one byte larger. This is assuming that behavior for non alpha characters is undefined and string s is initialized to "" prior to execution. Be gentle it's my first post.

Java SE 8, 71 69 bytes

Golfed:

(a,s)->{char b=97;if(a<91)b-=32;a=b;b+=26;while(a<b)s+=a++;return s;}

Ungolfed:

(a,s)->{          // String as a parameter. If declaration is necessary it adds 8 bytes
char b = 97;      // Uppercase A char, this is important
if (a < 91)       // If it is not past 'z', where a is a char param
    b -= 32;      // Then go back to the lowercase alphabet
a = b;            // Done to prevent a cast
b += 26;          // End of alphabet
while (a < b)     // Go to end of alphabet
    s += a++;     // Append character
return s;}        // Then return

I had originally implemented the following

String s="";char b=96;if(a-91<0)b-=32;for(char c=b;++c<b+27;)s+=c;return s;

It's more elegant but sadly it's one byte larger. This is assuming that behavior for non alpha characters is undefined and string s is initialized to "" prior to execution. Be gentle it's my first post.

edit: 2 bytes saved by Stewie Griffin by changing

a - 91 < 0 to a < 91
Source Link
jfh
  • 61
  • 5

Java SE 8, 71 bytes

Golfed:

(a,s)->{char b=97;if(a-91<0)b-=32;a=b;b+=26;while(a<b)s+=a++;return s;}

Ungolfed:

(a,s)->{          // String as a parameter. If declaration is necessary it adds 8 bytes
char b = 97;      // Uppercase A char, this is important
if (a - 91 < 0)   // If it is not past 'z', where a is a char param
    b -= 32;      // Then go back to the lowercase alphabet
a = b;            // Done to prevent a cast
b += 26;          // End of alphabet
while (a < b)     // Go to end of alphabet
    s += a++;     // Append character
return s;}        // Then return

I had originally implemented the following

String s="";char b=96;if(a-91<0)b-=32;for(char c=b;++c<b+27;)s+=c;return s;

It's more elegant but sadly it's one byte larger. This is assuming that behavior for non alpha characters is undefined and string s is initialized to "" prior to execution. Be gentle it's my first post.