YourThirdLife
BAN USERusing System;
using System.Text;
namespace SRMs
{
public class StringGames
{
public void AllStrings(string template)
{
int counter = 0;
for (int i = 0; i < template.Length; i++)
{
if (template[i] == '?')
{
counter++;
}
}
long numberOfCombinations = 1 << counter;
for (long i = 0; i < numberOfCombinations; i++)
{
var result = new StringBuilder();
int move = 0;
for (int j = 0; j < template.Length; j++)
{
if (template[j] == '?')
{
result.Append((i & (1 << move++)) == 0
? "0"
: "1");
}
else
{
result.Append(template[j]);
}
}
Console.WriteLine(result);
}
}
}
}
Works in cases where number of '?' is less then 63.
- YourThirdLife December 22, 2014
I didn't use LINQ to keep answer clean. With LINQ it can be even more beautiful...
- YourThirdLife January 07, 2015