18
\$\begingroup\$

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

\$\endgroup\$
11
  • 7
    \$\begingroup\$ 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. \$\endgroup\$
    – Giuseppe
    Apr 20, 2018 at 17:44
  • 1
    \$\begingroup\$ How ridiculously annoying is the fact that '0' comes before 'A' in ASCII code >:( lol \$\endgroup\$
    – NL628
    Apr 20, 2018 at 18:00
  • \$\begingroup\$ "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? \$\endgroup\$
    – user41805
    Apr 20, 2018 at 18:55
  • 1
    \$\begingroup\$ But according to the first statement, you say that $ will not appear in inputs \$\endgroup\$
    – user41805
    Apr 20, 2018 at 19:05
  • 1
    \$\begingroup\$ Now that you removed digits and innalid chars from the specs, you may want to also remove them from the examples. \$\endgroup\$
    – Titus
    Apr 20, 2018 at 23:17

32 Answers 32

4
\$\begingroup\$

Husk, 23 bytes

mż§?'#|=⁰mR32¤+…"AZ""09

Try it online or try it with the fancy █ character (but an invalid bytecount)!

Unfortunately I wasn't able to merge the two maps into one (except with using parentheses, costing 24 bytes)..

Explanation

mż§?'#|=⁰mR32¤+…"AZ""09"  -- expects string as argument, eg. "FOO"
             ¤            -- with the two strings "AZ" "09" ..
               …          -- | fill ranges: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                          -- |              "0123456789"
              +           -- .. and concatenate: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
          m               -- map the following (eg. with 'X')
                          -- | replicate 32 times: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                          -- : ["A…A","B…B",…,"Z…Z","0…0",…"9…9"]
m                         -- map the following (eg. with "F…")
 ż      ⁰                 -- | zipWith (keeping elements of longer list) argument ("FOO")
  §?   =                  -- | | if elements are equal
    '#                    -- | | | then use '#'
      |                   -- | | | else use the first character
                          -- | : ["#FF…F"]
                          -- : ["A…A",…,"#FF…F",…,"O##O…O",…,"9…9"]
\$\endgroup\$
4
\$\begingroup\$

Ruby, 62 bytes

->s{[*?A..?Z,*?0..?9].map{|c|(0..31).map{|i|c==s[i]??@:c}*''}}

Try it online!

Returns array of strings. Could be golfed further by discarding string joins and returning a 2D array of characters as is usually the norm, but I'm not sure if it is allowed here.

\$\endgroup\$
3
\$\begingroup\$

C (gcc), 132 126 bytes

char*s="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",*_,*a;f(char*x){for(_=s;*_;++_,puts(""))for(a=s;*a;)putchar(x[a++-s]-*_?*_:64);}

Try it online!

Thanks to Jonathan Frech for saving 6 bytes.

\$\endgroup\$
9
  • \$\begingroup\$ puts("") is equivalent to putchar(10). \$\endgroup\$ Apr 20, 2018 at 20:18
  • \$\begingroup\$ ++a)putchar((x[a-s]-*_)?*_:64); -> )putchar(x[a++-s]-*_?*_:64);. \$\endgroup\$ Apr 20, 2018 at 20:20
  • \$\begingroup\$ If you are willing to bend the rules a little, you could also golf 64 to 1. \$\endgroup\$ Apr 20, 2018 at 20:21
  • \$\begingroup\$ If you do, the putchar call could be golfed to putchar(*_*(*_!=a[x-s]));. \$\endgroup\$ Apr 20, 2018 at 20:24
  • \$\begingroup\$ Normally I'd be okay with bending the rules for that... but 1 is a very different beast from a filled rectangle or an @ sign. The other changes are useful though - will update. \$\endgroup\$
    – LambdaBeta
    Apr 20, 2018 at 20:25
3
\$\begingroup\$

Red, 177 bytes

func[s][m: copy[]foreach c a:"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[insert/dup r: copy"^/"c 32 append m r]j: 0
foreach c s[j: j + 1 if c <>#" "[m/(index? find a c)/(j): #"@"]]m]

Try it online!

More readable:

f: func[s][
    m: copy[]
    a:"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    foreach c a[
        insert/dup r: copy "^/" c 32
        append m r
    ]
    j: 0
    foreach c s[
        j: j + 1
        if c <>#" "[m/(index? find a c)/(j): #"@"]
    ]
    m
]
\$\endgroup\$
3
\$\begingroup\$

Charcoal, 21 bytes

E⁺α⭆…αχκ⭆…◨θφ³²⎇⁼ιλ#ι

Try it online! Link is to verbose version of code. Explanation:

  α  α                  Uppercase alphabet predefined variable
      χ                 Predefined variable 10
    …                   Chop to length
   ⭆                    Map over characters and join
       κ                Current index
 ⁺                      Concatenate
E                       Map over characters into array
           θ            Input string
            φ           Predefined variable 1000
          ◨             Right pad to length
             ³²         Literal 32
         …              Chop to length
        ⭆               Map over characters and join
                 ι  ι   Current outer character
                  λ     Current inner character
                ⁼       Equals
                   #    Literal `#`
               ⎇        Ternary
                        Implicitly print each result on its own line

Previous version with input validation, 34 32 bytes. Edit: saved 2 bytes thanks to @ASCII-only.

≔⁺α⭆…αχκαEα⭆…◨Φθ∨⁼ι №αιφ³²⎇⁼ιλ#ι

Try it online! Link is to verbose version of code.

\$\endgroup\$
7
  • \$\begingroup\$ :/ you appear to be missing a close paren at the end \$\endgroup\$
    – ASCII-only
    Apr 21, 2018 at 1:19
  • \$\begingroup\$ This looks like it works. (Wolfram StringReplace) On a side note, a replace builtin would be really handy right \$\endgroup\$
    – ASCII-only
    Apr 21, 2018 at 1:25
  • \$\begingroup\$ Never mind, I don't know what I was doing. 27 bytes - you don't need the Cast \$\endgroup\$
    – ASCII-only
    Apr 21, 2018 at 1:36
  • \$\begingroup\$ Also, re: the pad with arbitrary character you were asking about before: do you think that would be useful enough to add as a builtin? or maybe as a two-character builtin? \$\endgroup\$
    – ASCII-only
    Apr 21, 2018 at 1:43
  • \$\begingroup\$ 23 \$\endgroup\$
    – ASCII-only
    Apr 21, 2018 at 1:48
3
\$\begingroup\$

R, 104 bytes

function(S,o=""){for(i in 1:32)o=paste0(o,`[<-`(x<-c(LETTERS,1:9),x==substr(S,i,i),"@"))
cat(o,sep="
")}

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Jelly,  18  17 bytes

ØA;ØDWẋ32ɓ,€⁶y"ZY

Uses a space character. To use a # replace with ”# for a cost of one byte.

Try it online!

How?

ØA;ØDWẋ32ɓ,€⁶y"ZY - Main Link: list of characters, S   e.g.  ['S','P','A','M']
ØA                - upper-case alphabet characters           ['A','B',...,'Z']
   ØD             - digit characters                         ['0','1',...,'9']
  ;               - concatenate                              ['A','B',...,'Z','0','1',...,'9']
     W            - wrap in a list                           [['A','B',...,'Z','0','1',...,'9']]
      ẋ32         - repeat 32 times                          [['A','B',...,'Z','0','1',...,'9'],...,['A','B',...,'Z','0','1',...,'9']]
         ɓ        - start a new dyadic chain with that on the right
            ⁶     - space character                          ' '
          ,€      - pair €ach of S with a space              [['S',' '],['P',' '],['A',' '],['M',' ']]
              "   - zip with:
             y    -   translate (replace 'S' with ' ' in 1st, 'P' with ' ' in 2nd, ...) -- Note: zip is a zip-longest, so trailing lists remain
                Z  - transpose
                 Y - join with line-feeds
                   - implicit print
\$\endgroup\$
5
  • \$\begingroup\$ I can save one byte. \$\endgroup\$ Apr 21, 2018 at 9:45
  • \$\begingroup\$ Welp, I also got ³Ḣ,⁶yØA;ØD¤µ32СZY at 18 which I feel may also be improvable! Going out though... \$\endgroup\$ Apr 21, 2018 at 10:29
  • \$\begingroup\$ So, obviously, that's not the byte I'm referring to. :) Try harder... \$\endgroup\$ Apr 21, 2018 at 10:32
  • \$\begingroup\$ Amazing I managed to golf on mobile 17 bytes \$\endgroup\$ Apr 21, 2018 at 10:55
  • \$\begingroup\$ Mine was actually this, but congrats! \$\endgroup\$ Apr 21, 2018 at 10:56
2
\$\begingroup\$

C++14, 319 bytes 237

This is my first time doing this, in the worst possible CodeGolf Language :P

char c;string k="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",s;int main(){map<char,vc>g;g[' ']=vc(32,' ');for(char c:k)g[c]=vc(32,c);getline(cin,s);for(int i=0;i<s.length();i++)g[s[i]][i]='@';for(char d:k){for(char x:g[d])cout<<x;cout<<'\n';}}

Try it Online!

\$\endgroup\$
9
  • \$\begingroup\$ Question: Do I need to include the header? \$\endgroup\$
    – NL628
    Apr 20, 2018 at 18:05
  • \$\begingroup\$ If it's needed to run the code, it needs to be in your answer. That said, you can remove pretty much all the whitespace and have this answer still work. \$\endgroup\$
    – user48543
    Apr 20, 2018 at 18:07
  • \$\begingroup\$ Could I rewrite this as a function with parameters, instead of a main()? \$\endgroup\$
    – NL628
    Apr 20, 2018 at 18:08
  • \$\begingroup\$ @NL628 yes you can. See tips for golfing in C++ for more help. EDIT: switched link to C++ \$\endgroup\$
    – Giuseppe
    Apr 20, 2018 at 18:10
  • 1
    \$\begingroup\$ COBOL anyone? I've never written a line of code in it, but using COBOL for code golf might be an interesting challenge. \$\endgroup\$ Apr 21, 2018 at 5:31
2
\$\begingroup\$

Node.js, 85 bytes

Port to Node.js suggested by @DanielIndie

f=(s,x=544,c=Buffer([48+x/32%43]))=>x<1696?(s[x&31]==c?'@':c)+[`
`[++x&31]]+f(s,x):''

Try it online!


JavaScript (ES6), 103 98 bytes

f=(s,x=544,n=x>>5,c=String.fromCharCode(48+n%43))=>n<53?(s[x&31]==c?'@':c)+[`
`[++x&31]]+f(s,x):''

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ 90 bytes how about this? \$\endgroup\$ Apr 20, 2018 at 19:57
  • \$\begingroup\$ @DanielIndie Thanks! Added. (We don't really need this +"", do we?) \$\endgroup\$
    – Arnauld
    Apr 20, 2018 at 20:02
  • \$\begingroup\$ I never know if we need to convert or not so i dont think about it :P but yes, you dont actually need it :) \$\endgroup\$ Apr 20, 2018 at 20:03
  • \$\begingroup\$ @DanielIndie Ah, now we can just use x/32 to save 2 more bytes, since Buffer is coercing to integers. \$\endgroup\$
    – Arnauld
    Apr 20, 2018 at 20:09
  • \$\begingroup\$ f=(s,x=561,c=Buffer([48+x/33%43]))=>x<1749?(s[x++%33]==c?'@':x%33?c:`\n`)+f(s,x):'' \$\endgroup\$
    – l4m2
    May 1, 2018 at 4:40
2
\$\begingroup\$

APL+WIN, 56 bytes

Prompts for input string and uses # character as identifier:

m←⍉32 36⍴⎕av[(65+⍳26),48+⍳10]⋄((,m[;1]∘.=32↑⎕)/,m)←'#'⋄m

Explanation:

m←⍉32 36⍴⎕av[(65+⍳26),48+⍳10] create the table

32↑⎕ pad the input string to 32 characters with spaces

(,m[;1]∘.=32↑⎕) use outer product with = to identify characters in table

((,m[;1]∘.=32↑⎕)/,m)←'#' replace characters with #

m display table

⋄ statement separator
\$\endgroup\$
2
\$\begingroup\$

Perl 5 -F, 47 bytes

//,say map{$F[$_]eq$'?'*':$'}0..31for A..Z,0..9

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Haskell, 86 bytes

For a much nicer approach (and less bytes), see Laikoni's solution!

f x=(x#).(<$[1..32])<$>['A'..'Z']++['0'..'9']
(a:b)#(u:v)=last(u:['#'|a==u]):b#v
_#w=w

Try it online!

Alternatively for the same byte count we could use:

(a:b)#(u:v)|a==u='#':b#v|0<3=u:b#v

Try it online!

Explanation / Ungolfed

The operator (#) is very similar to zipWith however the function is hardcoded, st. it uses # if two characters are equal and otherwise it keeps the second one, ungolfed:

(a:b) # (u:v)
   | a == u    = '#' : b # v
   | otherwise =  u  : b # v

If the first list is exhausted it just appends the remaining elements of the second one:

_ # w = w

With that helper we only need to generate the string "A..Z0..9", replicate each element 32 times and zip the input with each string, ungolfed:

f x = map ((x#) . replicate 32) (['A'..'Z'] ++ ['0'..'9'])
\$\endgroup\$
3
  • 1
    \$\begingroup\$ 85 bytes: Try it online! \$\endgroup\$
    – Laikoni
    Apr 21, 2018 at 21:15
  • \$\begingroup\$ @Laikoni: Shame that it's just 1 byte less, this is a really clever usage of max. I think you should post that as your own solution since it's very different from my solution. \$\endgroup\$ Apr 21, 2018 at 21:20
  • \$\begingroup\$ I posted a 74 byte version. \$\endgroup\$
    – Laikoni
    Apr 21, 2018 at 21:56
2
\$\begingroup\$

Haskell, 74 bytes

f x=[do a<-take 32$x++cycle" ";max[c]['~'|a==c]|c<-['A'..'Z']++['0'..'9']]

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.

\$\endgroup\$
2
\$\begingroup\$

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))
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
1
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

Python 2, 103 96 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!

\$\endgroup\$
0
1
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ a[b] doesn't work like you want it here, does it :P? \$\endgroup\$ Apr 25, 2018 at 23:39
  • \$\begingroup\$ @MagicOctopusUrn: Unfortunately not. That was my first thought as well, but modular indexing is not our friend in this case :P \$\endgroup\$
    – Emigna
    Apr 26, 2018 at 6:51
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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")
\$\endgroup\$
1
\$\begingroup\$

Java 10, 120 118 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
\$\endgroup\$
1
\$\begingroup\$

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
             {expr {$i==$j?"#":$i}}
        ]
        ""
    ]
}
\$\endgroup\$
3
  • \$\begingroup\$ 152 \$\endgroup\$
    – sergiol
    Apr 27, 2018 at 18:27
  • \$\begingroup\$ @sergiol :| yes it is. 146? \$\endgroup\$
    – ASCII-only
    May 9, 2018 at 10:23
  • 1
    \$\begingroup\$ 145 \$\endgroup\$
    – ASCII-only
    May 9, 2018 at 10:28
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 155 150 bytes

	I =INPUT
	U =&UCASE '0123456789'
N	U LEN(1) . K REM . U	:F(END)
	O =DUPL(K,32)
	X =
S	I LEN(X) @X K	:F(O)
	O POS(X) K =' '	:S(S)
O	OUTPUT =O	:(N)
END

Try it online!

Explanation:

	I =INPUT			;* read input
	U =&UCASE '0123456789'		;* U = uppercase concat digits
N	U LEN(1) . K REM . U	:F(END)	;* while U not empty, pop first letter as K
	O =DUPL(K,32)			;* dup K 32 times
	X =				;* set position to 0
S	I LEN(X) @X K	:F(O)		;* find the next occurrence of K and save (index - 1) as X
	O POS(X) K =' '	:S(S)		;* replace the X'th occurrence of K with space. If that's before character 32, goto S, else proceed to next line
O	OUTPUT =O	:(N)		;* output the string and goto N
END
\$\endgroup\$
1
\$\begingroup\$

Prolog (SWI), 235 229 228 222 214 198 173 167 165 bytes

-6 bytes thanks to @Cows quack, -6 bytes thanks to @ 0 '

X*[H|T]:-(H=X->write(#);writef("%n",[X])),X*T;nl.
_+[].
X+[H|T]:-H*X,X+T.
?-read(X),swritef(Y,"%32l",[X]),string_codes(Y,Z),Z+`ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`.

Try it online!

Explanation

% if head = bubble char, write "#", else write bubble char, then while tail is non-empty, recurse.
% if tail is empty then print newline
X*[H|T]:-(H=X->write(#);writef("%n",[X])),X*T;nl.
% if list is empty, then do nothing. this prevents t from being called with invalid X
_+[].
% call t, then recurse for each char in list
X+[H|T]:-H*X,X+T.
% read, pad input to 32 chars, and convert input to list
?-read(X),swritef(Y,"%32l",[X]),string_codes(Y,Z),Z+`ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`.
\$\endgroup\$
0
\$\begingroup\$

SOGL V0.12, 19 bytes

,M↕+'»m{Z²²+;╗ŗ}⁰№I

Try it Here!

\$\endgroup\$
0
\$\begingroup\$

Octave, 61 bytes

@(s)[((a=[30:55 13:22]'*~~(o=1:32)).*(a+35~=[s o](o)))+35 '']

Try it online!

The function works as follows:

@(s)[                                                     ''] %Anonymous function, taking string, outputting character array   
         [30:55 13:22]'                                       %Creates the board alphabet ('A':'Z' '0':'9']) but minus 35 (value of '#')
                       *~~(o=1:32)                            %Matrix multiplication by an array of 32 1's to form the 2D board. Saves 1:32 for later.
      (a=                         )                           %Saves the board mimus 32 to a for use later.
                                            [s o](o)          %Ensures the input is 32 characters long. Missing chars replaced by 1:32 (not in board)
                                     (a+35~=        )         %Compares against board (a+35 as a=board-35). Makes 2D array where matches = 0, others = 1. 
     (                             .*                )+35     %Element=wise multiplication, forcing matches to 0. Then add 35 resulting in board with #'s  
\$\endgroup\$
0
\$\begingroup\$

Perl 6, 57 bytes

{map {<<$^c█>>[.comb[^32]Xeq$c].join},|('A'..'Z'),|^10}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.