Preparing a multiple choice test
Python 3, 71
Saved 22 bytes thanks to Ogaday.
Saved 3 bytes thanks to DSM.
Saved a bunch of bytes thanks to an array of bools being valid.
*k,=map(ord,input())
x=65
while x<=max(k):print([v==x for v in k]);x+=1
Takes uppercase command line input.
PowerShell, 95 94 73 bytes
param([char[]]$a)0..(($a|sort)[-1]-65)|%{$d=$_;-join($a|%{+!($_-$d-65)})}
Takes input as an uppercase string, but immediately casts it [char[]]
. We then loop from 0..
to the maximal value of $a
taken alphabetically (hence the -65
to convert from ASCII). For example, with ADCEB
, this can be thought of as looping from A
to E
.
Each iteration, we set a helper variable $d
equal to the current alphabetical (not ASCII) value. We then loop through all of $a
, each time putting either 0
or 1
on the pipeline, based on whether $_-$d-65
is truthy or falsey (i.e., whether we're in the right "slot"). This works because any non-zero value in PowerShell is truthy, meaning if our current letter $_
doesn't "equal" what slot we're in $d
, then the !
of that is $false
, or 0
.
Each of those arrays of 0
s and 1
s is then -join
ed together and re-put on the pipeline. When the outer loop ends, we have an array of strings, which will print one string per line.
Examples
PS C:\Tools\Scripts\golfing> .\preparing-a-multiple-choice-test.ps1 ABCDEFGH
10000000
01000000
00100000
00010000
00001000
00000100
00000010
00000001
PS C:\Tools\Scripts\golfing> .\preparing-a-multiple-choice-test.ps1 AFGHEEHFD
100000000
000000000
000000000
000000001
000011000
010000010
001000000
000100100
Edit 1 -- saved a byte by using Boolean-not instead of -eq
Edit 2 -- saved another 21 bytes by eliminating the extra array $b
LabVIEW, 30 22 20 LabVIEW Primitives
Goes through from a-z until the sum of all bools is equal to the input lenght. then Transforms the bools to numbers.
Now directly takes the max instead of checking the bool sum.
Since 2D bools are viable now im saving 2 Primitives by outputting the green wire in front of ?1:0
could redo it but im too lazy...