<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title></title>
    <description>I build web applications at Tempus Labs Inc. I love playing cricket and discovering new music. I am a passionate AI beginner.</description>
    <link>https://jitendra8911.github.io/</link>
    <atom:link href="https://jitendra8911.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Thu, 02 Mar 2023 13:33:05 +0000</pubDate>
    <lastBuildDate>Thu, 02 Mar 2023 13:33:05 +0000</lastBuildDate>
    <generator>Jekyll v3.9.3</generator>
    
      <item>
        <title></title>
        <description>&lt;p&gt;useful git commands&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;setting-up-ssh-authentication&quot;&gt;setting up ssh authentication&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent&quot;&gt;Guide to set up ssh authentication&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;pushing-to-github-without-ssh-key&quot;&gt;pushing to github without ssh key&lt;/h2&gt;

&lt;p&gt;For every push we don’t want to authenticate using username and password. This is annoying. This is where ssh comes handy.
Once ssh authentication is setup, run the following command:&lt;/p&gt;

&lt;p&gt;git remote set-url origin git@github.com:&lt;Username&gt;/&lt;Project&gt;.git&lt;/Project&gt;&lt;/Username&gt;&lt;/p&gt;

&lt;p&gt;Next time, when you push, git will not ask for username and password&lt;/p&gt;
</description>
        <pubDate>Thu, 02 Mar 2023 13:33:05 +0000</pubDate>
        <link>https://jitendra8911.github.io/2023-03-02-git-commands.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/2023-03-02-git-commands.html</guid>
        
        
      </item>
    
      <item>
        <title>Why does ice float?</title>
        <description>&lt;p&gt;It all comes down to density. Water is densest at 4° celsius. Ice is less dense than when water is in liquid form. This is because
water molecules inside ice have a lot of empty spaces between them. Therefore, in order for something to sink all the way to the bottom of water, it should
have more density than water. This explains why ice doesn’t sink.&lt;/p&gt;

&lt;!--more--&gt;
&lt;p&gt;Ice is 9% less dense than water. The heavier water displaces the lighter ice, so the ice floats to the top&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.thoughtco.com/why-does-ice-float-604304#:~:text=Ice%20floats%20because%20it%20is,ice%20floats%20to%20the%20top&quot;&gt;Ice and the Density of Water&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://youtu.be/cF7p5nAPnDU&quot;&gt;Neil deGrasse Tyson Explains Why Ice Floats&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Sat, 24 Jul 2021 10:30:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/science-docs/why-does-ice-float.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/science-docs/why-does-ice-float.html</guid>
        
        <category>documentation</category>
        
        
        <category>science-docs</category>
        
      </item>
    
      <item>
        <title>Why do astronauts float in ISS?</title>
        <description>&lt;p&gt;The first reason that we might think is because of zero gravity in the ISS orbit. This is not true. Gravity still exists at the height from above Earth where ISS is orbiting.
However, astronauts float in ISS because of something called free-falling.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;Think of it like you are on roller coaster and when you just hit the peak of the path going from downhill to uphill, you will feel weightlessness momentarily. ISS in the orbit
is in free-fall state all the time throughout its path. But you might wonder if ISS is free-falling, how come it doesn’t hit earth?
That’s a good question. So the ISS travels around the orbit roughly at 5 miles per sec. Because of its acceleration force and Earth’s gravity acting simultaneously
on ISS, it will remain in its orbit and thus avoiding collision with the Earth&lt;/p&gt;

&lt;p&gt;If you remove Earth’s gravity from this equation, the ISS will come out of its orbit and keep travelling farther away from Earth. Instead,
if you remove acceleration force of the ISS from the equation, the ISS will free-fall on the Earth’s surface just like an apple falling from the tree.&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://youtu.be/5wwEFfOzc4c&quot;&gt;Neil deGrasse Tyson Explains “What Goes Up, Must Come Down”&lt;/a&gt;&lt;/p&gt;

</description>
        <pubDate>Sat, 24 Jul 2021 10:30:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/science-docs/why-do-astronauts-float-in-ISS.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/science-docs/why-do-astronauts-float-in-ISS.html</guid>
        
        <category>documentation</category>
        
        
        <category>science-docs</category>
        
      </item>
    
      <item>
        <title>Why are plants green?</title>
        <description>&lt;p&gt;Sunlight visible by human eye is made up of rainbow colors namely
VIBGYOR (Violet, Indigo, Blue, Green, Yellow, Orange, Red).&lt;/p&gt;

&lt;p&gt;A color that an object, or a living thing (such as plants) appears to have is the wavelength that it reflects after absorbing the remaining wavelengths
In this case, plants reflects green wavelength and absorbs the remaining wavelengths of light. Therefore, plants appear to be green.&lt;/p&gt;

</description>
        <pubDate>Sun, 11 Jul 2021 19:08:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/science-docs/why-are-plants-green.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/science-docs/why-are-plants-green.html</guid>
        
        <category>documentation</category>
        
        
        <category>science-docs</category>
        
      </item>
    
      <item>
        <title>What causes tidal waves?</title>
        <description>&lt;p&gt;Sun’s and moon’s gravity on the earth will cause earth to bulge. When the water body flows through the bulgy region, the water appears to be
flowing from high tide region to the low tide region.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;When the sun, earth and moon align and forms line (a configuration known as syzygy), the tide’s range is at maximum. This is because, the opposite gravitational pull
exerted by moon and sun don’t cancel each other at this configuration and tries to pull earth on both the opposite sides of earth. This will result in
the bulgiest structure of earth causing the tides to be at its maximum during this time. Full moon&lt;/p&gt;

</description>
        <pubDate>Sun, 11 Jul 2021 19:08:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/science-docs/what-causes-tidal-waves.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/science-docs/what-causes-tidal-waves.html</guid>
        
        <category>documentation</category>
        
        
        <category>science-docs</category>
        
      </item>
    
      <item>
        <title>What are leap seconds?</title>
        <description>&lt;p&gt;Do you know that occasionally at around 23:59:59 UTC, the minute is going to have an extra second, i.e, a total of 61 seconds? Yes you heard it right. 
There are overall 27 such seconds inserted in the past. When the correction is made, it usually happens at the end of June or December or sometimes both.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;A day on earth is typically not exactly 24 hours long. Earth usually takes about 23:59:54 seconds to complete one rotation about its own axis.
Because of the Moon’s gravitational pull, Earth’s rotation slows down slightly, which in turn results in a slightly longer day. If you take the average over 365 days,
the length of the day is computed to be 24 hours. Therefore, we consider length of the day to be 24 hours. However, occasionally this average value need slight correction to 
accommodate slowing down of Earth’s rotation. Therefore, International Earth Rotation and Reference Systems Service (IERS), adds an extra second on some occasions
to rectify the error in length of the day. This extra second is known as leap second.&lt;/p&gt;
</description>
        <pubDate>Sun, 11 Jul 2021 19:08:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/science-docs/what-are-leap-seconds.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/science-docs/what-are-leap-seconds.html</guid>
        
        <category>documentation</category>
        
        
        <category>science-docs</category>
        
      </item>
    
      <item>
        <title>Googolplex</title>
        <description>&lt;p&gt;Do you know that Google derived its name from a number called googol? The number googol is equivalent to 10^100 which is equal to number 1
followed by 100 zeros.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;Googolplex is equivalent to 10^googol. This is considered to be the largest number in the universe. Carl Sagan, once said that even if you were to use all the
particles in the universe to represent the number googolplex, we will still run out of the particles to represent it. In in other words, there is
no room or space available in the universe to represent the number Googolplex!!&lt;/p&gt;
</description>
        <pubDate>Sun, 11 Jul 2021 19:08:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/science-docs/googolplex.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/science-docs/googolplex.html</guid>
        
        <category>documentation</category>
        
        
        <category>science-docs</category>
        
      </item>
    
      <item>
        <title>ReactJS cheatsheet</title>
        <description>&lt;p&gt;If you already know react, but wanted to brush up your knowledge on React or looking for quick reactjs references and best practices, 
this is the right place. This post can be used as a cheatsheet and is intended to keep up with latest and best practices.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h1 id=&quot;hooks&quot;&gt;Hooks&lt;/h1&gt;

&lt;h2 id=&quot;useeffect&quot;&gt;useEffect&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Run an effect and clean it up only once&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;hobbits&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getHobbits&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;get me list of Hobbits&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;setHobbits&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hobbits&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;subscription&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;lordOfTheRings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;subscription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;unsubscribe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;2. Run effect every time some property changes&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;hobbit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getHobbitByName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;props.hobbitName&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;setHobbit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hobbit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hobbitName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;3. Run effect after every completed render&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;misty mountain song!!!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Sat, 10 Jul 2021 16:19:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/docs/reactjs-cheatsheet.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/docs/reactjs-cheatsheet.html</guid>
        
        <category>documentation</category>
        
        
        <category>docs</category>
        
      </item>
    
      <item>
        <title>Advent of code 2020 day 20</title>
        <description>&lt;p&gt;&lt;a href=&quot;https://adventofcode.com/2020/day/20&quot;&gt;Advent of code 2020&lt;/a&gt; day 20th problem arguably the most hardest problem I have ever solved
both in terms of complexity and also time taken to get the final output. If you want to know
more about why this was the hardest problem, various barriers I faced while solving the problem and how I have overcome barriers,
please continue reading this article. It is going to be a fun ride and a worth reading.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;advent-of-code&quot;&gt;Advent of Code&lt;/h2&gt;

&lt;p&gt;In the month of December 2020, I have participated in a programming contest called &lt;a href=&quot;https://adventofcode.com/&quot;&gt;Advent of Code&lt;/a&gt; which is created by &lt;a href=&quot;https://twitter.com/ericwastl&quot;&gt;Eric Wastl&lt;/a&gt;, 
with the recommendation from my colleague. Every year Eric creates problems set that covers topics such as regular expressions,
matrix operations, bitwise operations, recursive functions, depth first and breadth first search, mathematical problems such as Chinese Remainder Theorem,
binary search tree, stacks, queues, string combinations and permutations, importance of double-precision floating-point,
linked list representation as an array, so on and so forth. The contest opens from December 1st through 25th. I strongly
recommend this challenge to anyone who is looking to solve hard problems.&lt;/p&gt;

&lt;p&gt;It was a fantastic experience for me getting to solve some of the toughest algorithmic problems I have ever come across.
One of the the problem which is the topic of the article is my favorite and the most challenging algorithmic problem I ever tackled.
It taught me so many things apart from technical perspective such as how to be patient solving tough problems, how to
strategically arrive to a solution, how helpful is divide and conquer approach among others.&lt;/p&gt;

&lt;p&gt;In the coming sections I am going to introduce the problem, challenges I faced at every tiny step I made and how
I have overcome those challenges to reach the end of tunnel!&lt;/p&gt;

&lt;h2 id=&quot;day-20th-problem&quot;&gt;Day 20th problem&lt;/h2&gt;

&lt;p&gt;Given a set of two dimensional square matrix tiles each with a tileId, arrange the tiles to form a 2D square matrix image
such that the neighboring tiles should have the same values at the border. The tiles can be rotated or flipped or both so as to align with the neighbors.
Following is an example of how a tile looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-$xslt&quot;&gt;Tile 1217:
.#....#..#
#.#....###
##.#....#.
##...###..
###..#..#.
.#...##...
#.#..##...
#...#.##..
#..##....#
.##.#..#..
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are two subproblems:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Find the product of the tileIds of the borders in the final image. This should become trivial to solve as soon as the tiles are arranged.&lt;/li&gt;
  &lt;li&gt;Part 2 is the most toughest subproblem. After aligning the tiles, shave the edges and rotate or flip or perform both on the resultant image until
you find the following sea monsters pattern.&lt;/li&gt;
&lt;/ol&gt;

&lt;pre&gt;&lt;code class=&quot;language-$xslt&quot;&gt;                  # 
#    ##    ##    ###
 #  #  #  #  #  #   
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One you find sea monsters, count the remaining &lt;strong&gt;#&lt;/strong&gt; that does’t constitute sea monsters.&lt;/p&gt;

&lt;h2 id=&quot;my-github-code-for-day-20&quot;&gt;My Github Code for day 20&lt;/h2&gt;

&lt;p&gt;If you wanted to look at the code, here is the link for &lt;a href=&quot;https://github.com/jitendra8911/advent-of-code/tree/master/src/day/20&quot;&gt;day 20 code&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;why-was-the-problem-hard-to-solve&quot;&gt;Why was the problem hard to solve&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Complexity in arranging the tiles adjacent to each other is proportional to time taken to find a robust algorithm
that satisfies neighbor tiles matching criteria. It took me about 2 weeks to come up with an algorithm that works.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Once the final image is obtained, finding the sea monsters using a regular expression was another mammoth task.
To give a brief idea, knowing the importance and difference between javascript regex methods matchAll and exec could unlock answer to the puzzle. 
But I learned difference between those methods while solving part 2 in a hard way.
More about it in coming sections.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;arranging-the-tiles-complexity-1&quot;&gt;Arranging the tiles (Complexity 1)&lt;/h2&gt;

&lt;p&gt;Finding corners was simple. Just find tiles that have only 2 borders which are common with other tiles.
After solving part 1, I took the following approach to solve part2&lt;/p&gt;

&lt;h4 id=&quot;first-approach-non-working-solution&quot;&gt;First approach (non working solution)&lt;/h4&gt;

&lt;p&gt;I tried to build the final image by traversing the grid in undirected way. The algorithm is as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Read the tiles. For each and every tile (call it source tile) do the following:
    &lt;ol&gt;
      &lt;li&gt;If there is a destination tile that has a border in common with the source tile.&lt;/li&gt;
      &lt;li&gt;If there is no such destination tile, try to rotate/flip source tile or the tile that is being compared to source
depending on which can be rotated/flipped until one of the border of the two tiles align.&lt;/li&gt;
      &lt;li&gt;Maintain a link between the source and destination tiles. 
Make sure both the source and destination tiles won’t be rotated/flipped in future iterations.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach has following disadvantages:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;We are not traversing the matrix in a fixed direction. Instead we are traversing in zigzag manner.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;There is no easy way to compare the source and destination border after one of them is rotated/flipped.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;There are chances of using the common borders of source and destination tiles while finding matched neighbors for other tiles.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Hard to maintain links between source and destination tile, i.e, whether destination tile is a left/right/top/bottom neighbor.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Hard to build image after the links are established.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;second-approach-working-solution&quot;&gt;Second approach (working solution)&lt;/h4&gt;

&lt;p&gt;The solution to build an image matrix is as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;It is guaranteed that all the corners have either a left neighbor or right neighbor.&lt;/li&gt;
  &lt;li&gt;Take any corner. Call it C1. Push it to stack&lt;/li&gt;
  &lt;li&gt;Check if C1 has right neighbor
    &lt;ol&gt;
      &lt;li&gt;If it has, then find the right neighbor. Call it N1. Rotate/flip N1 until the left of N1 matches with right of N1. Push it to stack.&lt;/li&gt;
      &lt;li&gt;If C1 doesn’t have right neighbor, then find left neighbor. Call it N2. Rotate/flip N2 until the right of N2 matches with left of C1. Push N2 to stack.&lt;/li&gt;
      &lt;li&gt;Repeat one of the above two steps for the current last tile in the stack until we don’t find any neighbor.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;At this point, we found all the tiles that are present in the top/bottom border of the image. If we traversed right to left of image matrix, then Col = 0. If we traversed left to right
then Col = n-1.&lt;/li&gt;
  &lt;li&gt;For each tile in the stack
    &lt;ol&gt;
      &lt;li&gt;Pop the tile. Call it T1.
        &lt;ol&gt;
          &lt;li&gt;Find the bottom/top neighbor of T1. Call it TN1. If bottom neighbor, row = 0. If top neighbor, row = n-1. Push T1 to image matrix to (row, col)&lt;/li&gt;
          &lt;li&gt;Rotate flip TN1 so that top/bottom of TN1 matches with bottom/top of T1. If bottom neighbor, increment row or else decrement row. Push TN1 to (row,col).&lt;/li&gt;
          &lt;li&gt;Find top/bottom neighbor of TN1 and repeat the above step until there are no neighbors.&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we take this approach we can successfully build the image matrix. Half the task is done. The remaining puzzle piece is to just find out sea monsters
from the image matrix and count number of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; that is not part of sea monster. Initially what was thought to be straight forward turned out to be a nightmare.
Therefore it deserve an explanation in the following section on why it was complicated to find out sea monsters.&lt;/p&gt;

&lt;h2 id=&quot;finding-sea-monsters-complexity-2&quot;&gt;Finding sea monsters (Complexity 2)&lt;/h2&gt;

&lt;p&gt;Now that the image is formed, we need to strip the borders of the tiles as per the problem’s requirement. After the borders are stripped off,
we need to rotate/flip the final image until we find sea monsters.&lt;/p&gt;

&lt;h4 id=&quot;first-approach-non-working-solution-1&quot;&gt;First approach (non working solution)&lt;/h4&gt;

&lt;p&gt;After rotating/flipping the image:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;I built a string of the resultant image.&lt;/li&gt;
  &lt;li&gt;I was finding sea monsters using string.match(). Even though I found sea monsters this way, I couldn’t find the
exact number because of overlapping sea monsters, in which case string.match() will skip and not return the correct results.
This took me over a week to realize. Thanks to reddit user by name &lt;a href=&quot;https://www.reddit.com/r/adventofcode/comments/kgo01p/2020_day_20_solutions/ghm9sej/&quot;&gt;davidlozzi&lt;/a&gt;
whose solution helped me identify my mistake.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;second-approach-working-solution-1&quot;&gt;Second approach (working solution)&lt;/h4&gt;

&lt;p&gt;After rotating/flipping the image:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;I built a string of the resultant image.&lt;/li&gt;
  &lt;li&gt;The regular expression to find sea monsters is 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;const regex = new RegExp('#.[^]{77}#....##....##....###.[^]{77}#..#..#..#..#..#...', 'g');&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Then execute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let match = regex.exec(image_matrix_string)&lt;/code&gt;.
    &lt;ol&gt;
      &lt;li&gt;If a match is found, increment the total number of sea monsters found and set the next index to start the search to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index + 1&lt;/code&gt;.
This way overlapping sea monsters can be found.&lt;/li&gt;
      &lt;li&gt;Repeat the above step until no further sea monsters are found.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;Finally count the number of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; in the image matrix that is not part of sea monster. This is answer for part 2!!&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Sat, 30 Jan 2021 08:06:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/docs/advent-of-code-2020-day20.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/docs/advent-of-code-2020-day20.html</guid>
        
        <category>documentation</category>
        
        
        <category>docs</category>
        
      </item>
    
      <item>
        <title>Troubleshooting Jekyll Errors</title>
        <description>&lt;p&gt;Are you facing issues while installing gem dependencies? Are you running into issues while serving jekyll?
Do you want to have different version of ruby installed for different projects? Then good news! You are in the right place. 
In this article I will explain how to fix all such issues.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;If are just looking for how to spin up a new jekyll blog, install ruby/gem/bundle in your project directory you can skip the following section and head 
to &lt;a href=&quot;#useful-jekyll-commands&quot;&gt;Useful Jekyll commands&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s almost been two years since I wrote my last post. Whoooah!! Last week I was going to write an article on one of the hardest
coding problem I ever solved in my life &lt;a href=&quot;https://adventofcode.com/2020/day/20&quot; target=&quot;_blank&quot;&gt;Advent Of Code 2020&lt;/a&gt;. I am going to talk about my experience in solving this problem in another article.
But the point is, when I started running the website on my local, I ran into some local environment issues. I was scratching my head and trying to get my head around the errors
I was getting but with little luck. Finally after thoroughly deep diving into what jekyll/gem/bundle/rbenv is and how they work, 
I was finally able to figure out how to overcome such type of issues. In this article I am going to talk about what issues I faced and how I have overcome such type of issues.&lt;/p&gt;

&lt;h2 id=&quot;jekyll-errors&quot;&gt;Jekyll errors&lt;/h2&gt;

&lt;p&gt;You might be encountering various errors including but not limited to following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;could not find i18n-0.9.5 in any of the sources&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bundler could not find compatible versions for gem &quot;ruby&quot;&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Could not find concurrent-ruby-1.0.5 in any of the sources&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundler failed to load command jekyll&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require: cannot load such file -- rexml/parsers/baseparser&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cannot load such file webrick&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After encountering the above errors and doing some research I found that installing rbenv and using it to install all other tools such as
ruby/gems/bundler required for a project is going to fix the above errors. The following section explains briefly about importance of rbenv and bundler&lt;/p&gt;

&lt;h2 id=&quot;importance-of-rbenv&quot;&gt;Importance of rbenv&lt;/h2&gt;

&lt;p&gt;The main use of the tool rbenv is to maintain different versions of ruby for different projects. Some projects might
require ruby 2.7 whereas other projects might need ruby 3.0. In order to install different versions of ruby in your machine and switch between them, rbenv as far
as I know is the only tool available to do so. The errors mentioned in &lt;a href=&quot;#jekyll-errors&quot;&gt;Jekyll errors&lt;/a&gt; could have been a result of having
incompatible versions of jekyll/ruby/bundler or any other gems installed in your machine globally. If instead you use rbenv to switch to a specific ruby version
pertinent to your project, you can get rid of those errors. For more information on rbenv please visit
&lt;a href=&quot;https://github.com/rbenv/rbenv&quot; target=&quot;blank&quot;&gt;rbenv github page&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;importance-of-bundle&quot;&gt;Importance of bundle&lt;/h2&gt;

&lt;p&gt;Whereas rbenv is used to determine which ruby version to use and which bundle is installed implicitly within the ruby, bundle is used to
install specific gems for the jekyll project such as jekyll itself or other gems such as html-proofer or webrick etc. For more information
on bundle visit &lt;a href=&quot;https://jekyllrb.com/tutorials/using-jekyll-with-bundler/&quot; target=&quot;blank&quot;&gt;bundle tutorial&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;useful-jekyll-commands&quot;&gt;Useful Jekyll Commands&lt;/h2&gt;

&lt;p&gt;If you are starting a jekyll project from scratch, start from step 1. If you already have a project but are running into the above mentioned &lt;a href=&quot;#jekyll-errors&quot;&gt;Jekyll errors&lt;/a&gt;
then start from step 10.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Install rbenv: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;brew install rbenv&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Run this command and follow instructions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rbenv init&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Install specific ruby version by doing: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rbenv install 3.0.0&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Go to the directory where you want to create jekyll project and issue: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkdir project-name&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;initialize bundler: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle init&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Setup ruby version you want your project to use by issuing: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rbenv local 3.0.0&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;configure bundler installation path: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle config set --local path 'vendor/path'&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Add jekyll as dependency to our project by running: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle add jekyll&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;If you want to create default theme and pages to your website run: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll new --force --skip-bundle&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;If you already have any gems installed under the vendor/path, delete them as we want to install the gems freshly.&lt;/li&gt;
  &lt;li&gt;Install gems under local path vendor/path by running: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle install&lt;/code&gt;. If you are running into any issues here, make sure
you are using the correct ruby version for the project by issuing: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rbenv local 3.0.0&lt;/code&gt; and go to step 10.&lt;/li&gt;
  &lt;li&gt;Serve the site by running: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll serve --livereload&lt;/code&gt;. If you run into any errors such as missing gem such as webrack, 
add it to Gemfile and try running again. The issue should be resolved.&lt;/li&gt;
&lt;/ol&gt;

</description>
        <pubDate>Sat, 23 Jan 2021 06:35:00 +0000</pubDate>
        <link>https://jitendra8911.github.io/docs/Troubleshooting-jekyll-errors.html</link>
        <guid isPermaLink="true">https://jitendra8911.github.io/docs/Troubleshooting-jekyll-errors.html</guid>
        
        <category>documentation</category>
        
        
        <category>docs</category>
        
      </item>
    
  </channel>
</rss>
