{"id":308231,"date":"2020-08-10T09:00:36","date_gmt":"2020-08-10T09:00:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308231"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308231","title":{"rendered":"\u041d\u0430\u0439\u0442\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0447\u0438\u0441\u0435\u043b, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0441\u0430\u043c\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514476\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ui\/cr\/93\/uicr93td9nqpjxhu2vy3suulivi.png\"><\/div>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 (20&#215;20) \u0441 \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u043e\u0442 0 \u0434\u043e 99 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043b\u0435\u0442\u043e\u043a.<\/p>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430 \u2014 \u043d\u0430\u0439\u0442\u0438 4 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0447\u0438\u0441\u043b\u0430 \u0431\u0435\u0437 \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u043e\u0434\u043d\u043e \u0437\u0430 \u0434\u0440\u0443\u0433\u0438\u043c, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0441\u0430\u043c\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u0426\u0432\u0435\u0442\u043e\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b 4 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0447\u0438\u0441\u0435\u043b (\u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c\u0438 \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043d\u0430 1 \u043a\u043b\u0435\u0442\u043a\u0443 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430).<\/p>\n<p>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C#.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 20\u044520 \u0438 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"cs\">static void CreateArrayFile() {     Random random = new Random();     string file = &quot;&quot;;     for (int i = 0; i &lt; 20; i++)     {         string line = &quot;&quot;;         for (int j = 0; j &lt; 20; j++)         {             line += random.Next(0, 99) + &quot;,&quot;;         }         line = line + Environment.NewLine;         file += line;     }     using (FileStream fstream = new FileStream($&quot;array.txt&quot;, FileMode.OpenOrCreate))     {         byte[] array = System.Text.Encoding.Default.GetBytes(file);         fstream.Write(array, 0, array.Length);         Console.WriteLine(&quot;\u041c\u0430\u0441\u0441\u0438\u0432 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0432 \u0444\u0430\u0439\u043b&quot;);     } } <\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/th\/2y\/up\/th2yup5ssawso17vhgqex-sjadu.png\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c, \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0432 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432.<\/p>\n<pre><code class=\"cs\">string[] lines = arrayFile.Split(Environment.NewLine); for (int i = 0; i &lt; 20; i++) {     string[] items = lines[i].Split(',');     for (int j = 0; j &lt; 20; j++)     {         table[i, j] = Convert.ToInt32(items[j]);     } } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 Element:<\/p>\n<pre><code class=\"cs\">public class Element {     public int Line { get; set; }     public int Column { get; set; }     public int Value { get; set; } } <\/code><\/pre>\n<p>  \u041f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0439. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 Multiplication \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0438\u0441\u0435\u043b \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0432 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"cs\">public class Multiplication {     public Multiplication()     {         Elements = new Element[4];     }     public Element[] Elements { get; set; }     public int Value     {         get         {             Multiply();             return value;         }     }     int value;     void Multiply()     {         if(Elements[0] != null &amp;&amp; Elements[1] != null &amp;&amp; Elements[2] != null &amp;&amp; Elements[3] != null)         {             value = Elements[0].Value * Elements[1].Value * Elements[2].Value * Elements[3].Value;         }     } } <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0439\u0442\u0438 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0447\u0438\u0441\u043b\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u0430 40 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u0441\u0435\u0434\u0438:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yp\/1-\/l2\/yp1-l2kw8cp28knztjyriqivezo.png\"><\/div>\n<p>  \u0410 \u0443 \u0447\u0438\u0441\u043b\u0430 48 \u0432 \u043f\u0440\u0430\u0432\u043e\u043c \u043d\u0438\u0436\u043d\u0435\u043c \u0443\u0433\u043b\u0443 \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e 3 \u0441\u043e\u0441\u0435\u0434\u0430. \u041d\u0435 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0441\u043e\u0441\u0435\u0434\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u044d\u0442\u043e:<\/p>\n<pre><code class=\"cs\">table[i-1][j-1] table[i-1][j] table[i-1][j+1]  table[i][j-1] table[i][j+1]  table[i+1][j-1] table[i+1][j] table[i+1][j+1] <\/code><\/pre>\n<p>  \u0423\u0431\u0435\u0434\u0438\u0432\u0448\u0438\u0441\u044c, \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0435 \u0433\u0440\u0430\u043d\u0438\u0446, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 FindNeighbors \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0432\u0441\u0435\u0445 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>  \u041f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0438\u0437 4 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0447\u0438\u0441\u0435\u043b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u0438\u0437 4 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<pre><code class=\"cs\">static List&lt;Multiplication&gt; GetFactorCombinations(int line, int column) {     List&lt;Multiplication&gt; combinations = new List&lt;Multiplication&gt;();     if (table[line, column] != 0)     {         List&lt;Element&gt; firstLevelNeighbors = FindNeighbors(line, column);         foreach (var firstLevelNeighbor in firstLevelNeighbors)         {             Element[] elements = new Element[4];             elements[0] = new Element             {                 Line = line,                 Column = column,                 Value = table[line, column]             };             elements[1] = firstLevelNeighbor;             List&lt;Element&gt; secondLevelNeighbors = FindNeighbors(firstLevelNeighbor.Line, firstLevelNeighbor.Column);             foreach (var secondLevelNeighbor in secondLevelNeighbors)             {                 if (!elements[0].Equals(secondLevelNeighbor) &amp;&amp; !elements[1].Equals(secondLevelNeighbor))                 {                     elements[2] = secondLevelNeighbor;                 }                 if (elements[2] != null)                 {                     List&lt;Element&gt; thirdLevelNeighbors = FindNeighbors(secondLevelNeighbor.Line, secondLevelNeighbor.Column);                     foreach (var thirdLevelNeighbor in thirdLevelNeighbors)                     {                         if (!elements[0].Equals(thirdLevelNeighbor) &amp;&amp; !elements[1].Equals(thirdLevelNeighbor) &amp;&amp; !elements[2].Equals(thirdLevelNeighbor))                         {                             elements[3] = thirdLevelNeighbor;                             Multiplication multiplication = new Multiplication                              {                                  Elements = elements                             };                             if (combinations.Where(p=&gt;p.Elements[0].Value==elements[0].Value&amp;&amp; p.Elements[1].Value == elements[1].Value &amp;&amp; p.Elements[2].Value == elements[2].Value &amp;&amp; p.Elements[3].Value == elements[3].Value).FirstOrDefault()==null)                             {                                 var nnnn =new Multiplication                                 {                                     Elements = new Element[] { elements[0], elements[1], elements[2], elements[3]}                                 };                                 combinations.Add(nnnn);                             }                         }                     }                 }             }         }     }     return combinations; } <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0447\u0438\u0441\u043b\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 0 (\u041f\u0440\u0438 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 0 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f 0). \u041f\u043e\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434 \u0438\u0449\u0435\u0442 \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430. \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u043d\u0435 0 \u0438\u0449\u0435\u043c \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f\u2026<\/p>\n<p>  \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 Equals \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b:<\/p>\n<pre><code class=\"cs\">public override bool Equals(Object obj) {     if (this==null || (obj == null) || !this.GetType().Equals(obj.GetType()))     {         return false;     }     else if(Line == ((Element)obj).Line &amp;&amp; Column == ((Element)obj).Column)     {         return true;     }     else     {         return false;     } } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0434\u043e \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0435\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u0430 \u043d\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"cs\">if (!elements[0].Equals(thirdLevelNeighbor) &amp;&amp; !elements[1].Equals(thirdLevelNeighbor) &amp;&amp; !elements[2].Equals(thirdLevelNeighbor)) {     elements[3] = thirdLevelNeighbor;     Multiplication multiplication = new Multiplication      {          Elements = elements     };     if (combinations.Where(p=&gt;p.Elements[0].Value==elements[0].Value&amp;&amp; p.Elements[1].Value == elements[1].Value &amp;&amp; p.Elements[2].Value == elements[2].Value &amp;&amp; p.Elements[3].Value == elements[3].Value).FirstOrDefault()==null)     {         var combination=new Multiplication         {             Elements = new Element[] { elements[0], elements[1], elements[2], elements[3]}         };         combinations.Add(combination);     } } <\/code><\/pre>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 GetFactorCombinations \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/lz\/gv\/5d\/lzgv5dz2ol335io4lifdr-3evfc.gif\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0432 \u043d\u0430\u0448 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0449\u0435\u043c \u0441\u0430\u043c\u0443\u044e \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0447\u0438\u0441\u0435\u043b.<\/p>\n<pre><code class=\"cs\">for (int i = 0; i &lt; 20; i++) {     for (int j = 0; j &lt; 20; j++)     {         List&lt;Multiplication&gt; combinations = GetFactorCombinations(i, j);         foreach (var combination in combinations)         {             if (combination.Value &gt; maxMultiplication.Value)             {                 Console.WriteLine(&quot;\u041d\u0430\u0439\u0434\u0435\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f &quot; + combination.Elements[0].Value + &quot; * &quot; + combination.Elements[1].Value + &quot; * &quot; + combination.Elements[2].Value + &quot; * &quot; + combination.Elements[3].Value + &quot; = &quot; + combination.Value);                 maxMultiplication = combination;             }         }     } } Console.WriteLine(&quot;\u0421\u0430\u043c\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0447\u0438\u0441\u0435\u043b = &quot; + maxMultiplication.Elements[0].Value + &quot; * &quot; + maxMultiplication.Elements[1].Value + &quot; * &quot; + maxMultiplication.Elements[2].Value + &quot; * &quot; + maxMultiplication.Elements[3].Value + &quot; = &quot; + maxMultiplication.Value); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c maxMultiplication, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bj\/rz\/vm\/bjrzvm6rgdudijm4ltfr1ivwlqq.png\"><\/div>\n<p>  \u0414\u0430, \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u044d\u0442\u043e. \u041c\u044b \u043d\u0430\u0448\u043b\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0438\u0437 4 \u0447\u0438\u0441\u0435\u043b \u0441 \u0441\u0430\u043c\u044b\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c. <\/p>\n<p>  \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443, \u043d\u043e \u043a\u043e\u0434 \u0437\u0430\u0445\u0430\u0440\u0434\u043a\u043e\u0436\u0435\u043d \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0447\u0438\u0441\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434. \u0410 \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043d\u0435 20 \u043d\u0430 20, \u0430 \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 30 \u043d\u0430 30 \u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u043d\u0435 \u0438\u0437 4, \u0430 5 \u0447\u0438\u0441\u0435\u043b? \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b (\u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u0432\u0441\u0435\u0445 \u0441\u043e \u0432\u0441\u0435\u043c\u0438) \u2026<\/p>\n<p>  \u0417\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u0443\u0435\u043c 2 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">const int TABLE_SIZE = 20; public const int COMBINATION_SIZE = 4; <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 GetFactorCombinations \u043d\u0430 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"cs\">static List&lt;Multiplication&gt; GetMultiplicationForStep(int line, int column, List&lt;Element&gt; otherElements = null) {     List&lt;Multiplication&gt; resultMultiplications = new List&lt;Multiplication&gt;();     List&lt;Element&gt; resultElements = new List&lt;Element&gt;();      Element element = new Element     {         Column = column,         Line = line,         Value = table[line, column]     };     if (otherElements == null)     {         otherElements = new List&lt;Element&gt;();     }     if(otherElements!=null)     {         resultElements.AddRange(otherElements);     }     if (table[line, column] != 0)     {                         if (otherElements.Where(p =&gt; p.Equals(element)).FirstOrDefault() == null)         {             resultElements.Add(element);         }     }     if (resultElements.Count() == COMBINATION_SIZE)     {         Multiplication multiplication = new Multiplication         {             Elements = resultElements.ToArray()         };         resultMultiplications.Add(multiplication);     }     else     {         List&lt;Element&gt; elementNeighbors = FindNeighbors(line, column);         elementNeighbors = elementNeighbors.Where(p =&gt; !p.Equals(element)&amp;&amp; otherElements.Where(p=&gt;p.Equals(element)).FirstOrDefault()==null).ToList();         List&lt;Multiplication&gt; newMultiplications = new List&lt;Multiplication&gt;();         foreach(Element neighbor in elementNeighbors)         {             \/\/ \u0415\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u043c\u0435\u043d\u044c\u0448\u0435 COMBINATION_SIZE \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0438\u0441\u043a\u0430\u0442\u044c \u0441\u043e\u0441\u0435\u0434\u0435\u0439...             newMultiplications.AddRange(GetMultiplicationForStep(neighbor.Line, neighbor.Column, resultElements).Where(p=&gt;p!=null));         }         foreach(Multiplication multiplication in newMultiplications)         {             if(resultMultiplications.Where(p=&gt;p.Value==multiplication.Value).FirstOrDefault()==null)             {                 resultMultiplications.Add(multiplication);             }         }     }     return resultMultiplications; } <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432, \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u043f\u043e\u043a\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 resultElements.Count() != COMBINATION_SIZE <\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0435\u0433\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n<pre><code class=\"cs\">for (int i = 0; i &lt; TABLE_SIZE; i++) {     for (int j = 0; j &lt; TABLE_SIZE; j++)     {         if (maxMultiplication.Elements.Where(p =&gt; p.Line == i &amp;&amp; p.Column == j).FirstOrDefault() != null)         {             Console.BackgroundColor = ConsoleColor.White;             Console.ForegroundColor = ConsoleColor.Black; \/\/ \u0422\u0443\u0442 \u044f \u0432\u044b\u0432\u043e\u0436\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0437\u0430\u043d\u043e\u0432\u043e, \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e \u0441\u0430\u043c\u0443\u044e \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e             Console.Write(table[i, j] + &quot; &quot;);             Console.ResetColor();         }         else         {             Console.Write(table[i, j] + &quot; &quot;);         }     }     Console.WriteLine(); } <\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/hx\/ef\/je\/hxefjemzubz4k_hdncs9bmr9hni.png\"><\/div>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-a\/_p\/r6\/-a_pr6oa5ww5fqcvsf4ad8wxany.png\"><\/div>\n<p>  <\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 NxN. <\/p>\n<p>  \u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435:<\/p>\n<ul>\n<li> \u041c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u0432 \u0432\u0441\u0435\u0445 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u0441\u043e \u0432\u0441\u0435\u043c\u0438, \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434. <\/li>\n<li> \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0430 3-\u043c\u0435\u0440\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435. \u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u0437\u2026<\/li>\n<\/ul>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ym\/5m\/px\/ym5mpxaud8j6pktfumqoyq19wfc.png\"><\/div>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/514476\/\"> https:\/\/habr.com\/ru\/post\/514476\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514476\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ui\/cr\/93\/uicr93td9nqpjxhu2vy3suulivi.png\"><\/div>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 (20&#215;20) \u0441 \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u043e\u0442 0 \u0434\u043e 99 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043b\u0435\u0442\u043e\u043a.<\/p>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430 \u2014 \u043d\u0430\u0439\u0442\u0438 4 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0447\u0438\u0441\u043b\u0430 \u0431\u0435\u0437 \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u043e\u0434\u043d\u043e \u0437\u0430 \u0434\u0440\u0443\u0433\u0438\u043c, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0441\u0430\u043c\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u0426\u0432\u0435\u0442\u043e\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b 4 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u0447\u0438\u0441\u0435\u043b (\u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c\u0438 \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043d\u0430 1 \u043a\u043b\u0435\u0442\u043a\u0443 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430).<\/p>\n<p>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C#.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308231","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308231"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308231\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}