コード例 #1
0
        //CREATE TRUTHTABLE ROWS WITH ROW VALUES
        private void createTruthtableRows()
        {
            if (argumentsChar != null)
            {
                if (argumentsChar.Count > 0)
                {
                    //calculting row true/false swap time (when to print true and when to print false)
                    List <int> rowLenght = new List <int>();
                    for (int i = argumentsChar.Count - 1; i >= 0; i--)
                    {
                        rowLenght.Add((int)Math.Pow(2, i));
                    }

                    //creating all rows
                    TruthtableRow           tempRow;
                    TruthtableRowArgument   tempArg;
                    TruthtableRowArgument[] args = new TruthtableRowArgument[argumentsChar.Count];
                    for (int i = rowLenght[0] * 2 - 1; i >= 0; i--)   //going to next row
                    {
                        for (int j = 0; j < argumentsChar.Count; j++) //creating one row
                        {
                            int cal = i / rowLenght[j];
                            if (cal % 2 == 0)
                            {
                                tempArg = new TruthtableRowArgument(argumentsChar[j], '1');
                            }
                            else
                            {
                                tempArg = new TruthtableRowArgument(argumentsChar[j], '0');
                            }
                            args[j] = tempArg;
                        }
                        tempRow = new TruthtableRow(args.ToList());
                        rows.Add(tempRow);
                    }
                }
                else //Only 1 and/or 0 arguments
                {
                    rows.Add(new TruthtableRow(new List <TruthtableRowArgument>()));
                }
            }
            else
            {
                throw new NullReferenceException();
            }
        }
コード例 #2
0
        private static List <TruthtableRow> getSubrowsOfMainRowRec(TruthtableRow main, int argIndex)
        {
            if (argIndex == main.Arguments.Count)
            {
                return(new List <TruthtableRow>()
                {
                    main
                });
            }
            List <TruthtableRow> subsets = new List <TruthtableRow>();

            if (main.Arguments[argIndex].Value == '*')
            {
                //copy Main and adjust it
                List <TruthtableRowArgument> newMainArguments = new List <TruthtableRowArgument>();
                for (int i = 0; i < main.Arguments.Count; i++) //copy arguments, but change current argument (on index)
                {
                    if (i == argIndex)
                    {
                        newMainArguments.Add(new TruthtableRowArgument(main.Arguments[i].Argument, '1'));
                    }
                    else
                    {
                        newMainArguments.Add(main.Arguments[i]);
                    }
                }
                TruthtableRow newMain = new TruthtableRow(newMainArguments);
                newMain.RowValue = main.RowValue;
                //get subRows if current arg == '1'
                foreach (TruthtableRow r in getSubrowsOfMainRowRec(newMain, argIndex + 1))
                {
                    subsets.Add(r);
                }
                TruthtableRowArgument[] newMainArguments2 = new TruthtableRowArgument[newMainArguments.Count];
                newMainArguments.CopyTo(newMainArguments2);
                newMainArguments2[argIndex] = new TruthtableRowArgument(main.Arguments[argIndex].Argument, '0');
                TruthtableRow newMain2 = new TruthtableRow(newMainArguments2.ToList());
                newMain2.RowValue = main.RowValue;
                //get subRows if current arg == '0'
                foreach (TruthtableRow r in getSubrowsOfMainRowRec(newMain2, argIndex + 1))
                {
                    subsets.Add(r);
                }
            }
            else if (main.Arguments[argIndex].Value == '1')
            {
                foreach (TruthtableRow r in getSubrowsOfMainRowRec(main, argIndex + 1))
                {
                    subsets.Add(r);
                }
            }
            else if (main.Arguments[argIndex].Value == '0')
            {
                foreach (TruthtableRow r in getSubrowsOfMainRowRec(main, argIndex + 1))
                {
                    subsets.Add(r);
                }
            }
            else
            {
                throw new Exception("Unknown char");
            }
            return(subsets);
        }