Find an algorithm
-
I've probably been staring at this far too long but I can't find an algorithm that will return the correct results for the code below. Anyone have some fresh ideas?
private void Test()
{
Logic(false, false, false, false, false, false, false);
Logic(false, false, false, false, true, true, true);
Logic(false, false, false, false, true, false, false);
Logic(false, false, true, false, true, true, false);
Logic(false, false, true, true, true, true, true);
}private void Logic(bool f, bool fl, bool d, bool dl, bool r, bool rl, bool expected)
{
bool result = [What algorithm goes here];System.Diagnostics.Debug.Assert(result == expected, "Does not match expected results");
}
I know the language. I've read a book. - _Madmatt
If it were me I'd ask a lot more questions of whoever gave you this. The first two inputs to Logic appear to have no effect on the result and (if that's true) should be removed. This leaves a four bit table mapping: false, false, false, false, false false, false, true, true, true false, false, true, false, false true, false, true, true, false true, true, true, true, true Which can also be looked at as a bit table d dl r rl Exp Dec 0 0 0 0 0 00 * 0 0 0 1 ? 01 0 0 1 0 0 02 * 0 0 1 1 1 03 * 0 1 0 0 ? 04 0 1 0 1 ? 05 0 1 1 0 ? 06 0 1 1 1 ? 07 1 0 0 0 ? 08 1 0 0 1 ? 09 1 0 1 0 ? 10 1 0 1 1 0 11 * 1 1 0 0 ? 12 1 1 0 1 ? 13 1 1 1 0 ? 14 1 1 1 1 1 15 * There doesn't appear to be an obvious pattern, but there are lots of unknowns. I'd be tempted to change Logic to remove the first two parameters and return a bool? (nullable). I'd then convert d, dl, r and rl into a single byte value and use a switch statement to return the known results, returning null for undefined results. If a pattern later emerges you can do something 'pretty' then.
-
If it were me I'd ask a lot more questions of whoever gave you this. The first two inputs to Logic appear to have no effect on the result and (if that's true) should be removed. This leaves a four bit table mapping: false, false, false, false, false false, false, true, true, true false, false, true, false, false true, false, true, true, false true, true, true, true, true Which can also be looked at as a bit table d dl r rl Exp Dec 0 0 0 0 0 00 * 0 0 0 1 ? 01 0 0 1 0 0 02 * 0 0 1 1 1 03 * 0 1 0 0 ? 04 0 1 0 1 ? 05 0 1 1 0 ? 06 0 1 1 1 ? 07 1 0 0 0 ? 08 1 0 0 1 ? 09 1 0 1 0 ? 10 1 0 1 1 0 11 * 1 1 0 0 ? 12 1 1 0 1 ? 13 1 1 1 0 ? 14 1 1 1 1 1 15 * There doesn't appear to be an obvious pattern, but there are lots of unknowns. I'd be tempted to change Logic to remove the first two parameters and return a bool? (nullable). I'd then convert d, dl, r and rl into a single byte value and use a switch statement to return the known results, returning null for undefined results. If a pattern later emerges you can do something 'pretty' then.
why do conversions, why introduce decision statements, if all it takes is some simple boolean expression? would you also replace multiplications by loops containing an addition? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
IMO Karnaugh maps aren't very useful. They can't cope with medium or large problems (how many times have you drawn Karnaugh maps with 6 input variables?) and they aren't very useful at solving small problems, as you just don't need them. The one thing they do well is visualize how minterms can be formed, but once you saw the principle, you don't need a graphics tool any more. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
Karnaugh maps aren't very useful
That's why you have Quine–McCluskey algorithm. You can easily implement it in any language and it always works regardless of number of inputs.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
-
why do conversions, why introduce decision statements, if all it takes is some simple boolean expression? would you also replace multiplications by loops containing an addition? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Simple because with all the unknowns, 30 secs after the method is finished some "new" result will be expected. Boolean expression are fine when what you are trying to communicate is clear. In this case things don't appear to be 'clear'. Converting isn't necessary, it's just helpful. Cheers
-
Luc Pattyn wrote:
Karnaugh maps aren't very useful
That's why you have Quine–McCluskey algorithm. You can easily implement it in any language and it always works regardless of number of inputs.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
parth.p wrote:
That's why you have Quine–McCluskey algorithm
and more. Pichat's work was more interesting (seems absent on the web??). I did a lot of research on the subject, and came up with my own optimization and design language, even before Verilog and VHDL became popular. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I've probably been staring at this far too long but I can't find an algorithm that will return the correct results for the code below. Anyone have some fresh ideas?
private void Test()
{
Logic(false, false, false, false, false, false, false);
Logic(false, false, false, false, true, true, true);
Logic(false, false, false, false, true, false, false);
Logic(false, false, true, false, true, true, false);
Logic(false, false, true, true, true, true, true);
}private void Logic(bool f, bool fl, bool d, bool dl, bool r, bool rl, bool expected)
{
bool result = [What algorithm goes here];System.Diagnostics.Debug.Assert(result == expected, "Does not match expected results");
}
I know the language. I've read a book. - _Madmatt
-
Simple because with all the unknowns, 30 secs after the method is finished some "new" result will be expected. Boolean expression are fine when what you are trying to communicate is clear. In this case things don't appear to be 'clear'. Converting isn't necessary, it's just helpful. Cheers
It seemed to be clear to everyone else
I know the language. I've read a book. - _Madmatt
-
You mean like Member 4190501 suggested over 10 hours ago. If you also read the responses you would see the problem was solved long ago.
I know the language. I've read a book. - _Madmatt
-
It seemed to be clear to everyone else
I know the language. I've read a book. - _Madmatt
-
I've probably been staring at this far too long but I can't find an algorithm that will return the correct results for the code below. Anyone have some fresh ideas?
private void Test()
{
Logic(false, false, false, false, false, false, false);
Logic(false, false, false, false, true, true, true);
Logic(false, false, false, false, true, false, false);
Logic(false, false, true, false, true, true, false);
Logic(false, false, true, true, true, true, true);
}private void Logic(bool f, bool fl, bool d, bool dl, bool r, bool rl, bool expected)
{
bool result = [What algorithm goes here];System.Diagnostics.Debug.Assert(result == expected, "Does not match expected results");
}
I know the language. I've read a book. - _Madmatt
result = ((f&&f1) || (d&&d1) || (r&&r1)) && (f||f1) && (d||d1) && (r||r1)
-
result = ((f&&f1) || (d&&d1) || (r&&r1)) && (f||f1) && (d||d1) && (r||r1)
incorrect, none of the test cases have (f||f1) true. :|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
incorrect, none of the test cases have (f||f1) true. :|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
result = ((f&&f1) || (d&&d1) || (r&r1)) && (f==f1) && (d==d1) && (r==r1);
-
I've probably been staring at this far too long but I can't find an algorithm that will return the correct results for the code below. Anyone have some fresh ideas?
private void Test()
{
Logic(false, false, false, false, false, false, false);
Logic(false, false, false, false, true, true, true);
Logic(false, false, false, false, true, false, false);
Logic(false, false, true, false, true, true, false);
Logic(false, false, true, true, true, true, true);
}private void Logic(bool f, bool fl, bool d, bool dl, bool r, bool rl, bool expected)
{
bool result = [What algorithm goes here];System.Diagnostics.Debug.Assert(result == expected, "Does not match expected results");
}
I know the language. I've read a book. - _Madmatt
Is it simply the number of TRUE arguments passed? No TRUE args ==> FALSE even no of TRUE args ==> TRUE Otherwise ==> FALSE :confused: Tadeusz Westawic Sum quid sum.
-
I've probably been staring at this far too long but I can't find an algorithm that will return the correct results for the code below. Anyone have some fresh ideas?
private void Test()
{
Logic(false, false, false, false, false, false, false);
Logic(false, false, false, false, true, true, true);
Logic(false, false, false, false, true, false, false);
Logic(false, false, true, false, true, true, false);
Logic(false, false, true, true, true, true, true);
}private void Logic(bool f, bool fl, bool d, bool dl, bool r, bool rl, bool expected)
{
bool result = [What algorithm goes here];System.Diagnostics.Debug.Assert(result == expected, "Does not match expected results");
}
I know the language. I've read a book. - _Madmatt
( ( d && dl ) && ( r && rl ) ) || ( (d && dl) && ( !r && !rl) ) || ( (!d && !dl) && ( r && rl ) )
I wasn't, now I am, then I won't be anymore.
-
Is it simply the number of TRUE arguments passed? No TRUE args ==> FALSE even no of TRUE args ==> TRUE Otherwise ==> FALSE :confused: Tadeusz Westawic Sum quid sum.
What are you confused about? Perhaps you are confused that the problem had been solved 18 days ago by people how were not confused.:confused:
I know the language. I've read a book. - _Madmatt
-
( ( d && dl ) && ( r && rl ) ) || ( (d && dl) && ( !r && !rl) ) || ( (!d && !dl) && ( r && rl ) )
I wasn't, now I am, then I won't be anymore.
Only 18 days after everyone else. Glad it wasn't urgentz
I know the language. I've read a book. - _Madmatt
-
What are you confused about? Perhaps you are confused that the problem had been solved 18 days ago by people how were not confused.:confused:
I know the language. I've read a book. - _Madmatt
There are unanswered posts of my own that are months old and I would still appreciate any other point of view as long as it is mathematically valid and programmable. Are you saying my post is illegal? Take off that heavy badge once in a while. Tadeusz Westawic Sum quid sum.
-
Only 18 days after everyone else. Glad it wasn't urgentz
I know the language. I've read a book. - _Madmatt
:laugh: I didn't even notice that. Man, do I suck... :-D
I wasn't, now I am, then I won't be anymore.
-
There are unanswered posts of my own that are months old and I would still appreciate any other point of view as long as it is mathematically valid and programmable. Are you saying my post is illegal? Take off that heavy badge once in a while. Tadeusz Westawic Sum quid sum.
Tadeusz Westawic wrote:
There are unanswered posts of my own
There is the difference. This post was answered by several people quite a long time ago.
Tadeusz Westawic wrote:
Are you saying my post is illegal?
losen up and perhaps vist more often
I know the language. I've read a book. - _Madmatt
-
I've probably been staring at this far too long but I can't find an algorithm that will return the correct results for the code below. Anyone have some fresh ideas?
private void Test()
{
Logic(false, false, false, false, false, false, false);
Logic(false, false, false, false, true, true, true);
Logic(false, false, false, false, true, false, false);
Logic(false, false, true, false, true, true, false);
Logic(false, false, true, true, true, true, true);
}private void Logic(bool f, bool fl, bool d, bool dl, bool r, bool rl, bool expected)
{
bool result = [What algorithm goes here];System.Diagnostics.Debug.Assert(result == expected, "Does not match expected results");
}
I know the language. I've read a book. - _Madmatt
private void Logic( bool f1, bol f2, bool f3, bool f4, bool f5, bool f6, bool expected)
{
bool result = ((!f1) && (!f2) && f5 && f6 && ( ((!f3) && (!f4)) || ( f3 && f4 )));
System.Diagnostics.Debug.Assert( result == expected, "Does not match expected results" );
}