EDIT: I edited the answer so that now it conforms with the format of the imported .xls file.
You Import the data with
data = Import["data.xls"]
{{{"A", ""}, {"B", 1.}, {"C", 1.}, {"D", 1.}, {"E", ""}, {"F",
2.}, {"G", 2.}, {"H", ""}}}
That's a list with one element: a list of the tuples, so let's do
list = First@data
{{"A", ""}, {"B", 1.}, {"C", 1.}, {"D", 1.}, {"E", ""}, {"F",
2.}, {"G", 2.}, {"H", ""}}
I will employ the function removeFrom from this answer:
removeFrom[b_List, a_List] := Module[{f}, f[_] = 0;
(f[#] = -#2) & @@@ Tally[a];
Pick[b, UnitStep[f[#]++ & /@ b], 1]]
Find positions of non-alternatives:
complPos = Partition[Position[list, ""][[All, 1]], 1]
{{1}, {5}, {8}}
Positions of alternatives:
pos = removeFrom[Partition[Range[Length@list], 1], complPos]
{{2}, {3}, {4}, {6}, {7}}
Non-alternative elements:
ones = Flatten@Table[list[[i, 1]], {i, complPos}]
{"A", "E", "H"}
Alternatives with their indices:
twos = Flatten[Table[list[[i]], {i, pos}], 1]
{{"B", 1.}, {"C", 1.}, {"D", 1.}, {"F", 2.}, {"G", 2.}}
Strip them of the indices and group the corresponding alternatives:
grouped = GatherBy[twos, Last]
elems = Table[grouped[[i, All, 1]], {i, 1, Length@grouped}]
{{{"B", 1.}, {"C", 1.}, {"D", 1.}}, {{"F", 2.}, {"G", 2.}}}
{{"B", "C", "D"}, {"F", "G"}}
Make all possible combinations of the alternatives:
tuples = Tuples[elems]
{{"B", "F"}, {"B", "G"}, {"C", "F"}, {"C", "G"}, {"D", "F"}, {"D",
"G"}}
Make all combinations including the non-alternatives:
result = Map[Sort, Table[Join[tuples[[i]], ones], {i, 1, Length@tuples}]]
{{"A", "B", "E", "F", "H"}, {"A", "B", "E", "G", "H"}, {"A", "C", "E",
"F", "H"}, {"A", "C", "E", "G", "H"}, {"A", "D", "E", "F",
"H"}, {"A", "D", "E", "G", "H"}}
Display it as a table where the rows are the possibilites:
TableForm@result
or if you want the columns to be the answers:
TableForm@Transpose@result
If you want the result to be really in the form you posted, i.e. with empty places in the table, then do
allElems = Sort@Flatten@Join[ones, elems]
{"A", "B", "C", "D", "E", "F", "G", "H"}
del = Table[Flatten@Table[
Position[allElems, removeFrom[allElems, result[[j]]][[i]]], {i, 1,
Length@removeFrom[allElems, result[[j]]]}], {j, 1, Length@result}]
{{3, 4, 7}, {3, 4, 6}, {2, 4, 7}, {2, 4, 6}, {2, 3, 7}, {2, 3, 6}}
final = Table[ReplacePart[allElems,
Table[del[[j, k]] -> {}, {k, 1, Length@del[[j]]}]], {j, 1, Length@result}]
{{"A", "B", {}, {}, "E", "F", {}, "H"}, {"A", "B", {}, {}, "E", {},
"G", "H"}, {"A", {}, "C", {}, "E", "F", {}, "H"}, {"A", {}, "C", {},
"E", {}, "G", "H"}, {"A", {}, {}, "D", "E", "F", {},
"H"}, {"A", {}, {}, "D", "E", {}, "G", "H"}}
And finally (for possibilities in rows)
TableForm@final
or (for answers in columns)
TableForm@Transpose@final
NOTE: Keep in mind that C and D are protected symbols; if you use strings "C" and "D" like above then there is no problem, but the code may crash if you decide on some point to change strings into expressions. That's why I used in the first version of my answer lower-case letters a,b,c,.... Additionally, I have a concern regarding the indices in data/list: in MMA there's a substantial difference between 1 and 1.. If the programme that was used to produce the .xls file made an error and instead of 1. placed in some place, e.g., 1.00000000000000001, the code will not give the correct answer.
Yes the order of the alternative items could be different
– Mazuego Sep 01 '16 at 14:50