# Fill out my Bubble Sheet

Today was AP exam registration day at my school, and while I was meticulously bubbling in the pages and pages of information required, the idea for this challenge hit me. So, given a string of letters and numbers, output an appropriately filled out bubble chart.

# Rules:

• For each character in the input string, replace that character in the corresponding column with a # or @ or any other reasonable symbol (if your language can handle it, the Unicode character 'full_block': █ looks really good)
• A space is represented by a blank column (see examples)
• Valid input will be a string which is made up of only uppercase letters, numerical digits, and spaces.
• Input will be of a length with a minimum of 1, and a maximum of 32 characters.
• Output must be UPPERCASE
• If the input length is less than the maximum length of 32, your program must still output the remaining blank columns
• Your program doesn’t have to handle lowercase input the same as if they were uppercase, but bonus points if it can.

## Board Format:

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
00000000000000000000000000000000
11111111111111111111111111111111
22222222222222222222222222222222
33333333333333333333333333333333
44444444444444444444444444444444
55555555555555555555555555555555
66666666666666666666666666666666
77777777777777777777777777777777
88888888888888888888888888888888
99999999999999999999999999999999

## Examples:

CODE GOLF ->

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
█CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DD█DDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEE█EEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFF█FFFFFFFFFFFFFFFFFFFFFFF
GGGGG█GGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
LLLLLLL█LLLLLLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
O█OOOO█OOOOOOOOOOOOOOOOOOOOOOOOO
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
00000000000000000000000000000000
11111111111111111111111111111111
22222222222222222222222222222222
33333333333333333333333333333333
44444444444444444444444444444444
55555555555555555555555555555555
66666666666666666666666666666666
77777777777777777777777777777777
88888888888888888888888888888888
99999999999999999999999999999999

ABCDEFGHIJKLMNOPQRSTUVWXYZ012345 ->

@AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
B@BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CC@CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEE@EEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFF@FFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGG@GGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHH@HHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIII@IIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJ@JJJJJJJJJJJJJJJJJJJJJJ
KKKKKKKKKK@KKKKKKKKKKKKKKKKKKKKK
LLLLLLLLLLL@LLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMM@MMMMMMMMMMMMMMMMMMM
NNNNNNNNNNNNN@NNNNNNNNNNNNNNNNNN
OOOOOOOOOOOOOO@OOOOOOOOOOOOOOOOO
PPPPPPPPPPPPPPP@PPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQ@QQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRR@RRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSS@SSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTT@TTTTTTTTTTTT
UUUUUUUUUUUUUUUUUUUU@UUUUUUUUUUU
VVVVVVVVVVVVVVVVVVVVV@VVVVVVVVVV
WWWWWWWWWWWWWWWWWWWWWW@WWWWWWWWW
XXXXXXXXXXXXXXXXXXXXXXX@XXXXXXXX
YYYYYYYYYYYYYYYYYYYYYYYY@YYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZ@ZZZZZZ
00000000000000000000000000@00000
111111111111111111111111111@1111
2222222222222222222222222222@222
33333333333333333333333333333@33
444444444444444444444444444444@4
5555555555555555555555555555555@
66666666666666666666666666666666
77777777777777777777777777777777
88888888888888888888888888888888
99999999999999999999999999999999

ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ->^^^

And of course, this is , so shortest answer wins

• Input validation is generally discouraged, so you could just have the input match [A-Z0-9]{1,32} and allow any behavior for inputs not matching that. – Giuseppe Apr 20 '18 at 17:44
• How ridiculously annoying is the fact that '0' comes before 'A' in ASCII code >:( lol – NL628 Apr 20 '18 at 18:00
• "Valid input will be a string which is made up of the characters that appear on the bubble sheet as well as spaces" but you also state "Any character other than the capital letters, spaces, and numerical digits, or over the 32 character limit should be ignored", so which one is it? – user41805 Apr 20 '18 at 18:55

Try it online! An input string x is padded with spaces to a length of 32 with take 32$x++cycle" ". For each character c from A to Z and 0 to 9, we look at the characters a from the padded input string and replace them by ~ when a and c are equal and by c otherwise. This is achieved by max[c]['~'|a==c], which is e.g. max "A" "~" = "~" when a = c = 'A', and max "A" "" = "A" when c = 'A' and a = 'B'. Because this yields a singleton string instead of a char, the do-notation is used which concatenates the singleton strings into one string. Based on BMO's Haskell solution. # Python 2, 138 bytes Supports both upper and lower case chars and leaves an unfilled column for spaces. def f(s): s=s.upper() for j in"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789":print"".join(j if(len(s)<=i)or(s[i]!=j)else'@'for i in range(32)) If the bonus isn't worth it, then I'll go for 125 bytes and only support upper case inputs: def f(s): for j in"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789":print"".join(j if(len(s)<=i)or(s[i]!=j)else'@'for i in range(32)) # Stax, 15 bytes ╛dδÑ-═E↑\≈Fà±AG Run and debug it It uses '#' to indicate a filled bubble. Unpacked, ungolfed, and commented, it looks like this. 32( right-pad or truncate to 32 { begin block for mapping VAVd+ "A..Z0..9" s'#+ move input character to top of stack and append "#". e.g. "C#" |t translate; replace the first character with the second in string m perform map using block Mm transpose array of arrays and output each line Run this one # Pyth, 23 20 bytes j.Tm:s+r1GUTdN.[Qd32 Try it here ### Explanation j.Tm:s+r1GUTdN.[Qd32 .[Qd32 Pad the input to 32 characters. m For each character... s+r1GUT ... get the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"... : dN ... with the character replaced by a '"'. j.T Transpose the lines and print them all. # C (gcc), 124 bytes f(s,b,x,y)char*s,b[33];{sprintf(b,"%-32.32s",s);for(x=0;++x<36;puts(""))for(y=x+21+43*(x<27),s=b;*s;putchar(*s++==y?35:y));} Try it online! Instead of a hard-coded array, I replaced it with a lookup function instead. Fortunately the ASCII character set has contiguous alphabetic and numeric ranges (I'm looking at you, EBCDIC!) As well, I made sure to keep the output to exactly 32 characters using sprintf(): if this wasn't a requirement of the task, the function would be 97 bytes: f(s,i,x,y)char*s,*i;{for(x=0;++x<36;puts(""))for(y=x+21+43*(x<27),i=s;*i;putchar(*i++==y?35:y));} Try it online! # CJam, 31 bytes q32Se]{'[,65>A,s+S+_@#St);}%zN* Try it online! Uses spaces as the "hole" character. If trailing whitespace is allowed, then this works for 29 bytes: q32Se]{'[,65>A,s+S+_@#St}%zN* Try it online! Here's a 34-byte variation that uses the Unicode full block () instead: q32Se]{'[,65>A,s+S+_@#'█t);}%zN* Try it online! ## Explanation q Input. e] Pad to a length of 32 32 with S spaces. { }% For each character: Get the uppercase alphabet by > dropping the first 65 65 elements of , the range of characters below '[ '['. + Append s the string version , of the range of numbers below A 10. + Append S a space. # Find the index of @ the character. t Set this index to S a space _ in the original array. ); Drop the space at the end. Yield this modified array. End for. The result is an array of arrays of characters. z Transpose this array, turning rows into columns. N* Join the result on newlines. # Python 2, 10396 94 bytes -7 bytes thanks to Mnemonic -2 bytes thanks to Jonathan Frech Uses ' as the symbol i,l=input(),17;exec"k=chr(l%43+48);print''.join(k[i[x:][:1]!=k]for x in range(32));l+=1;"*36 Try it online! # 05AB1E, 19 bytes RтúR32£vžKuÙyð:})ø» Try it online! Explanation R # reverse тú # prepend 100 zeroes R # reverse 32£ } # take the first 32 characters v # for each character žK # push a string of [a-zA-Z0-9] uÙ # upper case and remove duplicates yð: # replace current character with space )ø # transpose » # join by newline • a[b] doesn't work like you want it here, does it :P? – Magic Octopus Urn Apr 25 '18 at 23:39 • @MagicOctopusUrn: Unfortunately not. That was my first thought as well, but modular indexing is not our friend in this case :P – Emigna Apr 26 '18 at 6:51 # MATL, 21 bytes 1Y24Y2vjO33(32:)y=~*c Uses a space as marker character. Try it online! ### Explanation 1Y2 % Push 'AB...YZ' 4Y2 % Push '01...89' v % Concatenate into a 36×1 column vector of chars j % Push unevaluated input: string of length n, or equivalently 1×n % row vector of chars O33( % Write 0 at position 33. This automatically writes a 0 at postions % n+1, n+2, ..., 32 too 32:) % Keep only the first 32 entries: gives a 1×32 row vector y % Duplicate from below: pushes a copy of the 36 ×1 column vector =~ % Test for non-equal entries, with broadcast. Gives a 33×32 matrix % containing 0 for matching entries, and 1 otherwise * % Multiply this matrix by the 1×32 row vector, with broadcast. This % changes each 1 into the corresponding character in the input c % Convert to char. Implicitly display. Char 0 is displayed as space # Common Lisp, 150 bytes (setq s(format nil"~32a"(read-line)))(map nil(lambda(i)(map nil(lambda(j)(princ(if(eq i j)#\# i)))s)(princ" "))"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") Try it online! ### Explanation ;; pad input to 32 spaces on the right (setq s(format nil"~32a"(read-line))) ;; for each character in bubble sheet, for each character in input: ;; if characters are equal print "#" ;; else print bubble sheet character (map nil(lambda(i)(map nil(lambda(j)(princ(if(eq i j)#\# i)))s)(princ" "))"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") # Java 10, 120118 117 bytes s->{var r="";for(char c=65,i;c<91&c!=58;r+="\n",c+=c<90?1:-42)for(i=0;i<32;i++)r+=i<s.length&&s[i]==c?35:c;return r;} Try it online (for TIO I've used '█' (9608 instead of 35) for better visibility). Explanation: s->{ // Method with character-array parameter and String return-type var r=""; // Result-String, starting empty for(char c=65,i; // Start character c at 'A' c<91&c!=58 // Loop as long as c is 'Z' or smaller, and is not '9' ; // After every iteration: r+="\n", // Append a new-line to the result-String c+=c<90? // If c is not 'Z' yet 1 // Go to the next character ASCII-value-wise : // Else: -42) // Change the 'Z' to '0' for(i=0;i<32;i++) // Inner loop i in the range [0,32) r+=i<s.length // If we're not at the end of the input array yet, &&s[i]==c? // and the characters in the column and array are the same 35 // Append the filler-character '#' : // Else: c; // Append the current character instead return r;} // Return the result-String # Retina, 64 bytes$
36*
L.{36}
.
36*@$&¶ Y@Ld (.)(.*)\1 @$2
N$\S$.%
L.{32}

Try it online!

$36* L.{36} Pads the inputs string on the right with spaces to 36 characters . 36*@$&¶
Y@Ld

Then, put each character on its own line and add ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 before it.

(.)(.*)\1
@$2 Match a pair of the same character on the same line, which there is one if and only if the character for that line matches one of ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. Replace the first with @ and remove the second. N$\S
$.% The only unmatched lines are ones with spaces, so the non-space characters is a 36×36 square block. Transpose it. L.{32} Only keep the first 32 characters in each line # Tcl, 153 145 bytes Thanks @sergiol for -8 bytes lmap i [split ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ""] {puts [join [lmap j [split [format %-32s [join$argv ""]] ""] {expr {$i==$j?"#":$i}}] ""]} Try it online! ### Explanation # for i in list of choices lmap i [split ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ""] { # print string of puts [join # list of [lmap j # for each character in first argument padded to 32 characters [split [format %-32s [join$argv ""]] ""]
# return "#" if current choice and current character are equal, else current choice

Try it online!