Tuesday, March 26, 2013

CodeGolf Answer Explained: Printing The Alphabet

I participate in challenges at CodeGolf.SE (part of the StackExchange network), so from time to time, I will set aside some effort to elaborate on certain solutions I provide.

Today's solution (which can be found by following this link) is in response to a question titled: "Print the alphabet without using each vowel"


First, to explain the challenge further, one is tasked with printing the alphabet in their language of choice, but do so using no vowels (or as few as possible) in their solution. If vowels are used, then an alternate solution must be provided that also prints the alphabet, but does not include the vowels from the first solution, etc.

There are actually 3 parts to my challenge response, given how my VBA implementation (also usable as VBScript and probably VB.NET, but I did not try the latter) works, each explained below.

1 (uses 'o', 'u', and 'i') initializes a variable, b, to the value 65, which corresponds to an 'A' in an ASCII character set. The character value of b is printed (?, when used in the immediate window, is equivalent to Debug.Print in normal VBA operation), then incremented until the character value equals 'Z' and the script terminates.
b=65:Do:?Chr(b):b=b+1:Loop Until b=91
2 (uses 'o' and 'e') initializes a variable, b, as the counter of a loop to the value 65. As the loop progresses, until the numeric value of b equals that of the corresponding 'Z', the character value is printed.
For b=65 To 90:?Chr(b):Next
and 3 (uses 'i' and 'e') initializes a variable, b, to the value 65. b is printed and incremented until the b equals 91.
b=65:While b<91:Chr(b):b="b+1:Wend
I also provided an alternative, semi-cheating method using no vowels, which prints the entire alphabet, replacing the String representations of the individual vowels with a conversion of the numeric equivalent into a String.

 ?Chr(65)&"BCD"&Chr(69)&"FGH"&Chr(73)&"JKLMN"&Chr(79)&"PQRST"&Chr(85)&"VWXYZ"
comments powered by Disqus