<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pedro Pancine</title>
    <description>The latest articles on DEV Community by Pedro Pancine (@pancine).</description>
    <link>https://dev.to/pancine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F970133%2Fb106799a-1692-4948-aec8-6886a92ebe16.jpeg</url>
      <title>DEV Community: Pedro Pancine</title>
      <link>https://dev.to/pancine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pancine"/>
    <language>en</language>
    <item>
      <title>Explaining Matches Numbers Problem - beecrowd 3008</title>
      <dc:creator>Pedro Pancine</dc:creator>
      <pubDate>Wed, 14 Dec 2022 20:00:00 +0000</pubDate>
      <link>https://dev.to/pancine/explaining-matches-numbers-problem-beecrowd-3008-5aj7</link>
      <guid>https://dev.to/pancine/explaining-matches-numbers-problem-beecrowd-3008-5aj7</guid>
      <description>&lt;p&gt;This problem is a special one to me because it was created by a professor who taught me in college.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem link&lt;/strong&gt;: &lt;a href="https://www.beecrowd.com.br/judge/en/problems/view/3008" rel="noopener noreferrer"&gt;https://www.beecrowd.com.br/judge/en/problems/view/3008&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Short Description
&lt;/h2&gt;

&lt;p&gt;Given N number of sticks, how many different numbers can you create using all of them and following the image format?&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf4a3r0893bl7j4e22eu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf4a3r0893bl7j4e22eu.png" alt="Image showing how the numbers are created" width="423" height="129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Solution Link: &lt;a href="https://github.com/pancine/coding-challenges/blob/master/URI/3008.py" rel="noopener noreferrer"&gt;https://github.com/pancine/coding-challenges/blob/master/URI/3008.py&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Solution Explained
&lt;/h2&gt;

&lt;p&gt;First, I created two arrays:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;R&lt;/strong&gt; contains all the numbers, including the ones with the leading 0's&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T&lt;/strong&gt; contains all the numbers, excluding the ones with leading 0's
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;R&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10001&lt;/span&gt;
&lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10001&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The number 8 uses 7 sticks and is the one which uses more sticks, so I initialized R with 7 base cases:&lt;br&gt;
0 sticks -&amp;gt; 0 numbers&lt;br&gt;
1 sticks -&amp;gt; 0 numbers&lt;br&gt;
2 sticks -&amp;gt; 1 number (&lt;strong&gt;1&lt;/strong&gt;)&lt;br&gt;
3 sticks -&amp;gt; 1 number (&lt;strong&gt;7&lt;/strong&gt;)&lt;br&gt;
4 sticks -&amp;gt; 2 numbers (&lt;strong&gt;4&lt;/strong&gt;, 11)&lt;br&gt;
5 sticks -&amp;gt; 5 numbers (&lt;strong&gt;2&lt;/strong&gt;, &lt;strong&gt;3&lt;/strong&gt;, &lt;strong&gt;5&lt;/strong&gt;, 17, 71)&lt;br&gt;
6 sticks -&amp;gt; 7 numbers (&lt;strong&gt;0&lt;/strong&gt;, &lt;strong&gt;6&lt;/strong&gt;, &lt;strong&gt;9&lt;/strong&gt;, 14, 41, 77, 111)&lt;br&gt;
7 sticks -&amp;gt; 12 numbers (&lt;strong&gt;8&lt;/strong&gt;, 12, 13, 15, 21, 31, 47, 51, 74, 117, 171, 711)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, now that we have all the possible 1-digit numbers, we can use them to build every possible combination.&lt;br&gt;
For example, if the input is 8:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 stick numbers with 7 sticks numbers

&lt;ul&gt;
&lt;li&gt;(no numbers)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;2 sticks numbers with 6 sticks numbers (&lt;strong&gt;R[2] x R[6]&lt;/strong&gt;)

&lt;ul&gt;
&lt;li&gt;(10, 01, 16, 61, 19, 91, 114, &lt;del&gt;114&lt;/del&gt;, 141, &lt;del&gt;141&lt;/del&gt;, 411, &lt;del&gt;411&lt;/del&gt;, 177, 717, 771, 1111) = 13&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;3 sticks numbers with 5 sticks numbers (&lt;strong&gt;R[3] x R[5]&lt;/strong&gt;)

&lt;ul&gt;
&lt;li&gt;(72, 27, 73, 37, 75, 57, &lt;del&gt;717&lt;/del&gt;, &lt;del&gt;177&lt;/del&gt;, &lt;del&gt;177&lt;/del&gt;, &lt;del&gt;771&lt;/del&gt;, &lt;del&gt;771&lt;/del&gt;, &lt;del&gt;717&lt;/del&gt;) = 6&lt;/li&gt;
&lt;li&gt;As you can see, here we have some numbers already on the previous one. This happens because in the &lt;strong&gt;R[5]&lt;/strong&gt; we have the combination &lt;strong&gt;R[2] x R[3]&lt;/strong&gt; &lt;code&gt;(17 and 71)&lt;/code&gt; and &lt;strong&gt;R[2]&lt;/strong&gt; was used on the &lt;strong&gt;R[2] x R[6]&lt;/strong&gt; step.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;4 sticks numbers with itself

&lt;ul&gt;
&lt;li&gt;(44, &lt;del&gt;411&lt;/del&gt;, &lt;del&gt;141&lt;/del&gt;, &lt;del&gt;114&lt;/del&gt;) =  1&lt;/li&gt;
&lt;li&gt;We have repeated numbers for the same reason since &lt;strong&gt;R[4]&lt;/strong&gt; has the combination &lt;strong&gt;R[2] x R[2]&lt;/strong&gt; and &lt;strong&gt;R[2]&lt;/strong&gt; was used on the &lt;strong&gt;R[2] x R[6]&lt;/strong&gt; step.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;R[8]&lt;/strong&gt; is the sum of all cases, which is 20. However, we have the number '01', which is not a possible solution since it has a leading 0, so we have to remove it.&lt;/p&gt;

&lt;p&gt;Also, it's possible to apply this logic to any number after 7, leading to a formula:&lt;br&gt;
&lt;code&gt;R[n] = R[n-1] + R[n-2] + R[n-3] + R[n-4] + (3 * R[n-5]) + (3 * R[n-6]) + R[n-7]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note that: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;R[n-1]&lt;/strong&gt; is always 0&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;R[n-5]&lt;/strong&gt; and &lt;strong&gt;R[n-6]&lt;/strong&gt; were multiplied by 3 because both &lt;strong&gt;R[5]&lt;/strong&gt; and &lt;strong&gt;R[6]&lt;/strong&gt; have 3 numbers with 1 digit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, for the final part, we need to remove the numbers that have leading zeros. &lt;br&gt;
Looking at the base cases, you will see that the leading 0's are created in the 6 sticks case, so we need to remove this possibility, and to do it, we need to remove all the combinations.&lt;/p&gt;

&lt;p&gt;Then, we will have &lt;code&gt;T[n] = T[n] - T[n-6]&lt;/code&gt; and note that now we don't multiply by 3 because we don't want to remove 6 and 9.&lt;/p&gt;

</description>
      <category>gsap</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
