(0..63).map{|i|(((1+i/26)<<5)-i/52*81+i%26+i/62*(3*(i&1)-15)+33).chr}.joinThe compactiest formula, with just 47 characters designed to calculate 64 characters. The entire one-liner has 74 characters.
"".join([chr(((1+i//26)<<5)-(i//52*81)+i%26+(i//62*(3*(i&1)-15))+33) for i in range(0,64)])The formula is comprised in 54 characters, while the one-liner has 91 characters.
String.fromCharCode(...Array.from(Array(64), (_,i) =>
((1+i/26)<<5)-(81*(i/52|0))+i%26+((i/62|0)*(3*(i&1)-15))+33
))The most verbose one-liner (although I really like JS). The formula has 59 characters, while the one-liner has 120 characters (112 without the spaces and newline breaks).
All these snippets output the same string: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/, which is the base-64 encoding alphabet.
Yeah, this section would need cleaning. It's really long and it may tire the reader's eyes. However, it's the deconstruction of my thought processes.
I broke the original "problem", which was to generate the base-64 encoding alphabet instead of simply hardcoding the string, as summed up factors. The first solution was the JS version, then Python, and finally Ruby.
This factor is the initial offset for each subsequence (better thinking of it as "groups") comprised by 26 characters: the upper-case A-Z, the lowercase a-z, then a remaining (and smaller) third group for digits, plus sign and slash symbol. The difference between ASCII A (64) and ASCII a (97) is exactly 32, which is a power of two, achievable by left-shifting the "group index" (the 1+i/26 part) by 5 bits. The advantage of left-shifting is that it effectively truncates the division, which is a float number in both JS and Python.
Individually, this part results in 32 (from the index 0 to the index 25), 64 (from the index 26 to the index 51), then 96 (from the index 52 onwards).
This factor accounts for the difference between the aforementioned 96 (from the index 52 onwards) and 48 - 33, which is 81. "Why the 33", may you ask? It's the last factor I explain below, while 48 is the ASCII code representing the digit 0.
Individually, this part results in a bunch of zeros from the index 0 to the index 51, then a bunch of -81 (negative 81) from the index 52 onwards. This factor effectively "overlaps" the entire sequence with a larger grouping of 52 elements (0 to the first group, 1 to the second group, thanks to the truncation achievable by |0, which is shorter than Math.floor or Math.trunc) , subtracting the difference of 81 from both the number set and the two symbol set (the latter set, in turn, is accounted for by the fourth factor below).
This factor is the clearest of them all: the sub-sequence within each group of 26 elements. Nothing special here.
Individually, it's a cyclical counting from 0 to 25, repeating and going back to 0.
This factor introduces the adjustments needed for the last two characters, the plus-sign and the slash. The (i / 62 | 0) creates a third grouping which effectively splits the sequence between the first 62 elements from the last two elements. This sub-factor will result in 0 for the indices between 0 and 61, and 1 for the indices 62 and 63, also taking advantage of bitwise truncation (again, it's shorter than Math.floor or Math.trunc so it's the best fit for one-liners).
It's then multiplied by an adjustment sub-factor: the difference between + (43) and / (47) is 4. One (1) is guaranteed by the previous factor (i % 26), so it becomes a difference of 3 between them (hence the multiplication by 3 instead of 4). The index 62 is even, while the index 63 is odd, so the parity is exploited, multiplying it (0 and 1, respectively) by 3 (which will result in either 0 or 3). It's then subtracted by 15 (resulting in either -15 or -12).
Individually, it's all zeroes (0) until the index 62, followed by -15 and -12 which will add up with the other factors in order to account for 43 (plus sign) and 47 (slash).
This factor offsets everything to match the expected ASCII code offset. For example: at the index 0, the previous factors will add up to 32, so adding 33 will correctly result in 65, the ASCII code for A. At the index 52, the previous factors will add up to 96 + -81 + 0 + 0 = 15, so adding (back) 33 (as 33 was previously taken out from -81) will result in 48, the ASCII code for the digit 0.
Individually, it's just 33 repeating 64 times.
Just for fun. I believe that literally everything in the Cosmos can be expressed by mathematical formulas, even though humans haven't discovered them yet, and even if they're larger than the patterns they are intended to represent, whether these patterns are discrete sets/sequences or continuous series.
Another approach (for JS):