@@ -96,7 +96,8 @@ namespace SolveAvdoshin
9696 Console.Write("{0} — {1}", i.ToString("D2"), AvdoshinNames[i].PadRight(18));
9797
9898 try {
99− var ex = BooleanExpression.FindMininalExpressionInBasis(n, AvdoshinBases[i], AvdoshinVars[i]);
99+ var ex = BooleanExpression.FindMininalExpressionInBasis(n, AvdoshinBases[i], AvdoshinVars[i],
100+ mode: BooleanExpression.ExpressionSearchMode.CountBlocks);
100101
101102 Console.WriteLine(ex.ToString());
102103 }
@@ -668,7 +669,7 @@ namespace SolveAvdoshin
668669 abstract public byte Eval();
669670 abstract override public string ToString();
670671 abstract public BooleanExpression Clone();
671− abstract public int getSize();
672+ abstract public int CountOps();
672673
673674 public override int GetHashCode()
674675 {
@@ -680,6 +681,15 @@ namespace SolveAvdoshin
680681 return ToString() == obj.ToString();
681682 }
682683
684+ public abstract HashSet<string> GetSetOfAllBlockStrings();
685+
686+ public int CountBlocks()
687+ {
688+ var allBlocks = GetSetOfAllBlockStrings();
689+
690+ return allBlocks != null ? allBlocks.Count : 0;
691+ }
692+
683693 public IEnumerable<BooleanExpression> CombineWith(BooleanExpression anotherExpression,
684694 BooleanOperation[] ops)
685695 {
@@ -737,7 +747,8 @@ namespace SolveAvdoshin
737747 }
738748 }
739749
740− public static BooleanExpression FindMininalExpressionInBasis(int n, BooleanOperation[] ops, BooleanVariable[] vars)
750+ public enum ExpressionSearchMode { CountOps, CountBlocks, };
751+ public static BooleanExpression FindMininalExpressionInBasis(int n, BooleanOperation[] ops, BooleanVariable[] vars, ExpressionSearchMode mode = ExpressionSearchMode.CountOps)
741752 {
742753 var queue = new ImprovisedPriorityQueue<BooleanExpression>(20);
743754 var knownTruthTables = new HashSet<byte>();
@@ -765,7 +776,8 @@ namespace SolveAvdoshin
765776
766777 foreach(var anotherExpression in knownExpressions) {
767778 foreach(var neighbourExpression in curExperession.CombineWith(anotherExpression, ops)) {
768− queue.TryEnqueue(neighbourExpression, neighbourExpression.getSize());
779+ queue.TryEnqueue(neighbourExpression, mode == ExpressionSearchMode.CountBlocks
780+ ? neighbourExpression.CountBlocks() : neighbourExpression.CountOps());
769781 }
770782 }
771783 }
@@ -798,9 +810,25 @@ namespace SolveAvdoshin
798810 return new OpExpression(Op, Left.Clone(), Right.Clone());
799811 }
800812
801− public override int getSize()
813+ public override int CountOps()
814+ {
815+ return Left.CountOps() + Right.CountOps() + 1;
816+ }
817+
818+ public override HashSet<string> GetSetOfAllBlockStrings()
802819 {
803− return Left.getSize() + Right.getSize() + 1;
820+ var allBlocks = new HashSet<string>();
821+ allBlocks.Add(ToString());
822+
823+ var leftBlocks = Left.GetSetOfAllBlockStrings();
824+ if(leftBlocks != null)
825+ allBlocks.UnionWith(leftBlocks);
826+
827+ var rightBlocks = Right.GetSetOfAllBlockStrings();
828+ if(rightBlocks != null)
829+ allBlocks.UnionWith(rightBlocks);
830+
831+ return allBlocks;
804832 }
805833
806834 public override byte Eval()
@@ -902,11 +930,16 @@ namespace SolveAvdoshin
902930 return new VarExpression(Var);
903931 }
904932
905− public override int getSize()
933+ public override int CountOps()
906934 {
907935 return 0;
908936 }
909937
938+ public override HashSet<string> GetSetOfAllBlockStrings()
939+ {
940+ return null;
941+ }
942+
910943 public override byte Eval()
911944 {
912945 switch(Var) {