<?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: DouglasParanhos</title>
    <description>The latest articles on DEV Community by DouglasParanhos (@douglasparanhos).</description>
    <link>https://dev.to/douglasparanhos</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%2F728004%2F7155e5f0-623a-4087-821c-a3cd9605caa8.png</url>
      <title>DEV Community: DouglasParanhos</title>
      <link>https://dev.to/douglasparanhos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/douglasparanhos"/>
    <language>en</language>
    <item>
      <title>Reports of a problem #1</title>
      <dc:creator>DouglasParanhos</dc:creator>
      <pubDate>Sun, 24 Oct 2021 21:34:08 +0000</pubDate>
      <link>https://dev.to/douglasparanhos/reports-of-a-problem-1-1ejm</link>
      <guid>https://dev.to/douglasparanhos/reports-of-a-problem-1-1ejm</guid>
      <description>&lt;p&gt;This is my first post ever in dev.to and I always wanted to report the struggling about solving challenging problems, that kind of problems that just test your logic to do stuff, and I also wanted to kick off the moss from my Python abilities.&lt;/p&gt;

&lt;p&gt;To achieve that I'm starting this new thread "Reports of a problem", which I'll report all steps until i get the final solution of a specific problem.&lt;/p&gt;

&lt;p&gt;So, if anyone has different solutions of the problems, tips of how can I make it better, please let me know and we discuss about it.&lt;/p&gt;

&lt;p&gt;I'll be solving problems from &lt;a href="https://www.beecrowd.com.br/judge/en"&gt;Beecrowd&lt;/a&gt;. It has lots of problems divided by categories and difficulties. Excellent site for practicing, BTW.&lt;/p&gt;

&lt;p&gt;So, the first problem, as I'm returning to python now is a not very difficult, random chosen one: &lt;a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1026"&gt;To Carry or not to Carry&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, there's a story telling that a student created a 32-bit adder, but the carry-on bit was broken, so the sum 4 + 6 = 2.&lt;/p&gt;

&lt;p&gt;And, for that, he converted both numbers to 32-bit and, as the carry-on bit was broken, the final 32-bit result was 2.&lt;/p&gt;

&lt;p&gt;The idea is to implement this broken adder.&lt;/p&gt;

&lt;p&gt;So, my idea was to reproduce exactly what he did, convert both numbers to 32-bit and do the sum but, to do that, there's a lot of casting and looping, etc, as you can see &lt;a href="https://github.com/DouglasParanhos/Problems/commit/41fe3fe8c418ae27a15111a5b4ded60a200e4792#diff-8e349e7b73cb742144cf508b09f558f0fc8719e0b1a8bf39fa65b18ba687d414"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This solution worked, but the problem set the time limit as 3s, and this solution took more than that to run, due these loops and converting.&lt;/p&gt;

&lt;p&gt;Then, I decided to think the whole problem again and realised the obvious, all that story told was to hide that all the student "created" was a &lt;a href="https://en.wikipedia.org/wiki/XOR_gate"&gt;Xor&lt;/a&gt;. Finally, a &lt;a href="https://github.com/DouglasParanhos/Problems/blob/master/URIOnlineJudge/Python/1026.py"&gt;much more simple&lt;/a&gt; solution was created, and worked successfully.&lt;/p&gt;

&lt;p&gt;It's always, always important to think straight about the problem even before considering start coding, it will spare you a lot of pain.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
