Click here to Skip to main content
15,887,895 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
David198717-Aug-11 21:52
David198717-Aug-11 21:52 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
BillWoodruff17-Aug-11 22:10
professionalBillWoodruff17-Aug-11 22:10 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
David198717-Aug-11 22:19
David198717-Aug-11 22:19 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? [modified] Pin
BillWoodruff24-Aug-11 20:55
professionalBillWoodruff24-Aug-11 20:55 
AnswerRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
Luc Pattyn17-Aug-11 15:59
sitebuilderLuc Pattyn17-Aug-11 15:59 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
BillWoodruff17-Aug-11 19:20
professionalBillWoodruff17-Aug-11 19:20 
Answerlink to usable c# sample of output of logic-matrix auto-generator for your review and comments Pin
BillWoodruff18-Aug-11 15:27
professionalBillWoodruff18-Aug-11 15:27 
AnswerRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? [modified] Pin
RobCroll19-Aug-11 5:02
RobCroll19-Aug-11 5:02 
Hi Bill,

I had a play with this tonight and thought I'd post it for what it's worth. If the code generator needs to support a various number of boolean values, it may be of some use.

C#
void Start()
{
	bool[] bools = new bool[] { true, false, true};
	string testCase = "Test case " + FindTestCase(bools);
}

int FindTestCase(bool[] bools)
{
	string arrayCode = BoolArrayToBinaryString(bools);
	foreach (string code in BoolArrayToBinaryStringPermuations(bools.Length))
		if (code == arrayCode)
			return Convert.ToInt32(code, 2);

	return -1; //ignore
}

string BoolArrayToBinaryString(bool[] bools)
{
	StringBuilder sb = new StringBuilder();
	foreach (bool b in bools)
		sb.Append(Convert.ToInt32(b));

	return sb.ToString();
}

IEnumerable BoolArrayToBinaryStringPermuations(int count)
{
	double max = Math.Pow(2, count);
	for (int i = 0; i < max; i++)
		yield return Convert.ToString(i, 2).PadLeft(count, '0');
}


[modified] took into account David's comments but decided against << due to readablity. Changed code and assigned a max variable so I was only killing the kitten once instead of at every iteration
"You get that on the big jobs."
modified on Friday, August 19, 2011 1:37 PM

GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
David198719-Aug-11 5:32
David198719-Aug-11 5:32 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
RobCroll19-Aug-11 5:46
RobCroll19-Aug-11 5:46 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
David198719-Aug-11 6:04
David198719-Aug-11 6:04 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? [modified] Pin
BillWoodruff19-Aug-11 6:51
professionalBillWoodruff19-Aug-11 6:51 
AnswerRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
GParkings3-Sep-11 5:57
GParkings3-Sep-11 5:57 
Questionconnection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff2-Aug-11 23:47
professionalBillWoodruff2-Aug-11 23:47 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
David19875-Aug-11 1:21
David19875-Aug-11 1:21 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff5-Aug-11 2:10
professionalBillWoodruff5-Aug-11 2:10 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
David19875-Aug-11 2:40
David19875-Aug-11 2:40 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff5-Aug-11 7:29
professionalBillWoodruff5-Aug-11 7:29 
AnswerRe: connection routing algorithm for connecting rectangles with lines ? Pin
cjb1106-Aug-11 9:35
cjb1106-Aug-11 9:35 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff7-Aug-11 13:02
professionalBillWoodruff7-Aug-11 13:02 
AnswerRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 10:48
Member 41945937-Aug-11 10:48 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? [modified] Pin
BillWoodruff7-Aug-11 14:30
professionalBillWoodruff7-Aug-11 14:30 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 15:34
Member 41945937-Aug-11 15:34 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 15:59
Member 41945937-Aug-11 15:59 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff7-Aug-11 17:40
professionalBillWoodruff7-Aug-11 17:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.