<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sopan Thakre on Medium]]></title>
        <description><![CDATA[Stories by Sopan Thakre on Medium]]></description>
        <link>https://medium.com/@thakresopan72?source=rss-b4f7a997ab0e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*30_69Tvj3C0Zdl7y2sYn0Q.jpeg</url>
            <title>Stories by Sopan Thakre on Medium</title>
            <link>https://medium.com/@thakresopan72?source=rss-b4f7a997ab0e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:16:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thakresopan72/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding GeoJSON]]></title>
            <link>https://medium.com/@thakresopan72/understanding-geojson-b339dfe72392?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b339dfe72392</guid>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[geojson]]></category>
            <category><![CDATA[openstreetmap]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Sat, 11 Jul 2026 04:46:06 GMT</pubDate>
            <atom:updated>2026-07-11T04:51:59.342Z</atom:updated>
            <content:encoded><![CDATA[<p>How does any map-based app extract out information from open source spatial data? How do we convert it into data that we understand?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ldy4SQEbINA-ZjxyOagwA.png" /><figcaption>Fig. Extracting data from GeoJSON file</figcaption></figure><h3>1. Introduction</h3><p>GeoJSON is one of the file formats for storing vector data. In this article we will focus on understanding the file format and building a parser to get useful information.</p><h3>2. File Structure</h3><p>The file is divided into two parts- metadata and a collection of features. Each feature is further divided into <em>type</em>, <em>properties</em>, <em>geometry</em> and <em>id</em>.</p><pre>{<br>  &quot;type&quot;: &quot;FeatureCollection&quot;,<br>  &quot;generator&quot;: &quot;overpass-turbo&quot;,<br>  &quot;timestamp&quot;: &quot;2026-07-10T17:29:00Z&quot;,<br>  &quot;features&quot;: [<br>    {<br>      &quot;type&quot;: &quot;Feature&quot;,<br>      &quot;properties&quot;: {<br>        &lt;list of properties&gt;<br>      },<br>      &quot;geometry&quot;: {<br>        &quot;type&quot;: &lt;type of feature&gt;,<br>        &quot;coordinates&quot;: [<br>          &lt;list of x, y coordinates&gt;<br>        ]<br>      },<br>      &quot;id&quot;: &lt;unique element id&gt;<br>    },<br>    ...<br>  ]<br>}</pre><ol><li><em>type</em>: Tells the type of the object under consideration; a feature here.</li><li><em>properties</em>: Specifies metadata about the feature like names (in English and regional languages), is it a highway, one way (if a road), opening time, closing time (if an amenity).</li><li><em>geometry</em>: Contains the type of the feature (<em>Point</em>,<em> LineString</em>,<em> Polygon</em>) and a list of x and y coordinates.</li><li><em>id</em>: This represents the unique global identifier of the specific feature in the OpenStreetMap database in the format: &lt;<em>element type</em>&gt;/&lt;<em>numeric id</em>&gt;.</li></ol><p>Here’s an example of a GeoJSON file containing a point, a line and a polygon. Note that the first and the last cooordinates of the polygon are the same.</p><pre><br>{<br>  &quot;type&quot;: &quot;FeatureCollection&quot;,<br>  &quot;generator&quot;: &quot;overpass-turbo&quot;,<br>  &quot;timestamp&quot;: &quot;2026-07-10T17:29:00Z&quot;,<br>  &quot;features&quot;: [<br>    {<br>      &quot;type&quot;: &quot;Feature&quot;,<br>      &quot;properties&quot;: {<br>        &quot;@id&quot;: &quot;way/217112832&quot;,<br>        &quot;leisure&quot;: &quot;park&quot;<br>      },<br>      &quot;geometry&quot;: {<br>        &quot;type&quot;: &quot;Polygon&quot;,<br>        &quot;coordinates&quot;: [<br>          [<br>            [<br>              73.8135024,<br>              18.5653285<br>            ],<br>            [<br>              73.8140203,<br>              18.5653491<br>            ],<br>            [<br>              73.8139986,<br>              18.5658374<br>            ],<br>            [<br>              73.8134807,<br>              18.5658168<br>            ],<br>            [<br>              73.8135024,<br>              18.5653285<br>            ]<br>          ]<br>        ]<br>      },<br>      &quot;id&quot;: &quot;way/217112832&quot;<br>    },<br>    {<br>      &quot;type&quot;: &quot;Feature&quot;,<br>      &quot;properties&quot;: {<br>        &quot;@id&quot;: &quot;node/12301663618&quot;,<br>        &quot;leisure&quot;: &quot;park&quot;,<br>        &quot;name&quot;: &quot;Children’s Traffic Park&quot;,<br>        &quot;name:en&quot;: &quot;Children’s Traffic Park&quot;,<br>        &quot;name:mr&quot;: &quot;वाहतूक उद्यान&quot;,<br>        &quot;operator:type&quot;: &quot;government&quot;<br>      },<br>      &quot;geometry&quot;: {<br>        &quot;type&quot;: &quot;Point&quot;,<br>        &quot;coordinates&quot;: [<br>          73.8151486,<br>          18.5598737<br>        ]<br>      },<br>      &quot;id&quot;: &quot;node/12301663618&quot;<br>    },<br>    {<br>      &quot;type&quot;: &quot;Feature&quot;,<br>      &quot;properties&quot;: {<br>        &quot;@id&quot;: &quot;way/60981874&quot;,<br>        &quot;highway&quot;: &quot;secondary&quot;,<br>        &quot;lanes&quot;: &quot;2&quot;,<br>        &quot;name&quot;: &quot;Mahadji Shinde Marg&quot;,<br>        &quot;name:en&quot;: &quot;Mahadji Shinde Marg&quot;,<br>        &quot;name:etymology:wikidata&quot;: &quot;Q3275992&quot;,<br>        &quot;name:hi&quot;: &quot;महादजी शिंदे मार्ग&quot;,<br>        &quot;name:mr&quot;: &quot;महादजी शिंदे मार्ग&quot;,<br>        &quot;oneway&quot;: &quot;yes&quot;,<br>        &quot;surface&quot;: &quot;asphalt&quot;<br>      },<br>      &quot;geometry&quot;: {<br>        &quot;type&quot;: &quot;LineString&quot;,<br>        &quot;coordinates&quot;: [<br>          [<br>            73.8074085,<br>            18.5604669<br>          ],<br>          [<br>            73.8074018,<br>            18.5605258<br>          ],<br>          [<br>            73.8074078,<br>            18.5608726<br>          ],<br>          [<br>            73.807419,<br>            18.5616824<br>          ],<br>          [<br>            73.807431,<br>            18.5624902<br>          ],<br>          [<br>            73.8074354,<br>            18.5627834<br>          ]<br>        ]<br>      },<br>      &quot;id&quot;: &quot;way/60981874&quot;<br>    }<br>  }<br>]</pre><h3>3. Parsing GeoJSON</h3><p>If you want to parse a GeoJSON file, first download some data from <a href="https://overpass-turbo.eu/">Overpass Turbo</a>.</p><h4>3.1 Downloading GeoJSON file from Overpass Turbo</h4><ol><li>Choose your desired area by dragging and zooming in and out on the map.</li><li>Enter your script in the left script panel and hit <em>Run</em>. You can find a sample script <a href="https://github.com/henk1729/GeoToolKit/blob/main/03.%20Learning%3A%20Understanding%20GeoJSON/assets/_query_ParksInMyLocality.txt">here</a>.</li><li>Click <em>Export</em> and download as GeoJSON.</li></ol><h4>3.2 Parsing</h4><ol><li>Include the downloaded file in your project directory.</li><li><a href="https://github.com/henk1729/GeoToolKit/tree/main/03.%20Learning%3A%20Understanding%20GeoJSON/src">Here</a> is the code to parse it in C#. Make sure you have installed the necessary packages.</li></ol><h3>4. Conclusion</h3><p>That’s it from this article. We learnt about GeoJSON and how to parse it. In the next article, we will look at some more file types. Till then, stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b339dfe72392" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to GIS Vector Data Model]]></title>
            <link>https://medium.com/@thakresopan72/introduction-to-gis-vector-data-model-9f72966e6a12?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f72966e6a12</guid>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[vector-data-model]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Thu, 02 Jul 2026 15:14:54 GMT</pubDate>
            <atom:updated>2026-07-02T15:14:54.208Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Introduction</h3><p>How is data represented in maps? How do we see various roads, parks, rivers, offices along with their names, running hours, contact details?</p><p>In this article, we will learn about one of the ways of representing data on maps — GIS Vector data model. But before that let’s understand what a GIS is.</p><h3>2. Geographic Information System (GIS)</h3><p>A Geographic Information System (GIS) is a computer framework used to capture, manage and analyze spatial data. It is basically a mapping of the location and the attributes of data e.g. say you have a general store near your home then GIS helps you connect the precise location of the store with its attributes like opening time, closing time, contact number, etc.</p><h4>2.1 Types of GIS</h4><p>There are two data representation models in GIS — Raster data model and Vector data model. A Raster data model contains data in the form of grid cells containing information about that location. Any pixelated image is an example of raster data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jtxHIGSKEtiBk7t7" /><figcaption>Fig. 2.1.1 Raster data (Photo by <a href="https://unsplash.com/@peek_a_boo_who?utm_source=medium&amp;utm_medium=referral">Tao Yuan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>)</figcaption></figure><p>A Vector data model contains complex forms of data along with the attributes of that data. We’ll look into Vector data model today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*0l9XVRbZsId-dgt9wVCVzQ.png" /><figcaption>Fig. 2.1.2 Vector data (Photo by <a href="https://www.pexels.com/@vladimirsrajber/">Vladimir Srajber</a>)</figcaption></figure><h3>3. Vector Data Model</h3><p>Any feature in this data model is represented using one of the three geometry primitives: a point, a line or a polygon.</p><h4>3.1 Fundamental Spatial Data Types</h4><ol><li>Point: A point is a coordinate pair (x, y) that represents features too small to be captured as lines or polygons like wells, lamp posts, sign boards, public toilets.</li><li>Line: A line (or a polyline) is a series of connected points that do not form a closed loop. These are used to represent roads, rivers, railway tracks.</li><li>Polygon: A polygon is a series of connected points where the first and the last points are the same thus forming a closed loop. These represent enclosed spaces like apartments, fuel stations, shopping malls, lakes.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*edTYOZb8UwqFye7oDTk_nQ.png" /><figcaption>Fig. 3.1.1 Points, lines and polygons in a map</figcaption></figure><h4>3.2 Attribute Table</h4><p>An attribute table contains description about features like road name, max speed for a road, postal code, contact number, email id for a hospital. Each of the attributes in an attribute table has a fixed data type that once set, can’t be modified e.g. road name necessarily has a <em>string</em> data type.</p><h4>3.3 Data Storage File Formats</h4><p>Although there are various file formats for storing vector data, we’ll look at two popular ones — Well-Known-Text (WKT) and GeoJSON.</p><ol><li>WKT: This file stores data in the form: <em>datatype</em> (&lt;list of coordinates&gt;) with no additional data e.g.</li></ol><pre>POINT (5 3)<br>LINESTRING (1 1, 4 4, 8 2)<br>POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))</pre><p>2. GeoJSON: Data in this file format is stored in JSON with coordinates along with attribute data e.g.</p><pre>{<br>  &quot;type&quot;: &quot;Feature&quot;,<br>  &quot;properties&quot;: {<br>    &quot;name&quot;: &quot;Central Park&quot;,<br>    &quot;has_swings&quot;: true<br>  },<br>  &quot;geometry&quot;: {<br>    &quot;type&quot;: &quot;Polygon&quot;,<br>    &quot;coordinates&quot;: [[[0,0], [0,5], [5,5], [5,0], [0,0]]]<br>  }<br>}</pre><h3>4. Conclusion</h3><p>That’s all from this article. In the next one, we’ll learn how to use actual data from OSM to solve real-life problems. Till then, I have a bonus task for you: what if I tell you vector data is actually raster data with infinitesimally small pixels (of length 0.0000001 mm)! Go ahead and find out!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f72966e6a12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Coordinate Reference Systems used in mapping Earth]]></title>
            <link>https://medium.com/@thakresopan72/introduction-to-coordinate-reference-systems-used-in-mapping-earth-0f8a07a816fe?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f8a07a816fe</guid>
            <category><![CDATA[map-projection]]></category>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[geography]]></category>
            <category><![CDATA[cartography]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Sat, 27 Jun 2026 17:50:14 GMT</pubDate>
            <atom:updated>2026-06-27T17:52:40.537Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Introduction</h3><p>Have you ever wondered how the maps we use daily are made? How is Earth, a sphere apparently, plotted onto a plane? Is there some standard reference system that is used in the process?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*TVHJAFsVw_xRhMAQtxJ7dA.png" /><figcaption>Fig. 1.1 Mapping Earth (Photo by <a href="https://www.pexels.com/@vlada-karpovich/">Vlada Karpovich</a>)</figcaption></figure><p>In this story, we will learn about the coordinate systems that are used to map Earth. There are two types of coordinate systems — Geographic Coordinate System and Projected Coordinate System.</p><h3>2. Geographic Coordinate System (GCS)</h3><p><strong>2. 1 The True shape of Earth</strong></p><p>We have a notion that the Earth is a perfect sphere. But that’s not true. With no water on it, it resembles a potato with an uneven surface.</p><figure><img alt="A potato with an uneven surface" src="https://cdn-images-1.medium.com/max/500/1*HmhHHyLFihE53EXal56jtg.png" /><figcaption>Fig. 2.1.1 A potato with an uneven surface similar to Earth (Photo by <a href="https://www.pexels.com/@nikolaos-kofidis-2155853790/">Nikolaos Kofidis</a>)</figcaption></figure><p><strong>2.2 Selecting Model and Datum</strong></p><p>So how do we map Earth? We use an ellipsoid to approximate it. But that solves just half of our problem. After we have selected a model the next task is to position it with respect to the center of the Earth, or in other words, choose its datum. This is because a model optimized for North America (NAD83) will suit that region better than one optimized for Australia (GDA94). So, we should choose the model that best serves our purpose/locality of study.</p><p><strong>2.3 Determining position on Globe</strong></p><p>So, how is a position on Earth determined using a GCS? The globe is divided into latitudes and longitudes which are imaginary lines surrounding it. The latitude wrapping the globe halfway is called the Equator (0° latitude) and the longitude passing through Greenwich, London is known as the Prime Meridian (0° longitude). These lines divide Earth into northern, southern and western, eastern hemispheres respectively. Any position can be addressed as a unique intersection of a latitude and a longitude.</p><figure><img alt="Latitude and longitude lines on a globe" src="https://cdn-images-1.medium.com/max/612/0*RAKi7YRZ_Xvb-Bb7" /><figcaption>Fig. 2.3.1 Latitude and longitude lines</figcaption></figure><p>The most famous GCS is the WGS84 (World Geodetic System 1984). It uses latitude, longitude and height to find a location.</p><h3><strong>3. Projected Coordinate System (PCS)</strong></h3><p><strong>3.1 Projection technique</strong></p><p>If you were to peel an orange and lay the peel flat, you get a projection of the peel onto a flat surface. This is the idea behind PCS. Now instead of an orange imagine you have a globe wireframe with a bulb at the center.</p><figure><img alt="A globe wireframe" src="https://cdn-images-1.medium.com/max/500/1*w6w0Nw2cvqFhM2B_YEJXsw.png" /><figcaption>Fig. 3.1.1 A globe wireframe (Photo by <a href="https://www.pexels.com/@maximilian-f-647630072/">Maximilian F</a>)</figcaption></figure><p>You put it inside a hollow cylinder with the equator touching the cylinder. Now the light bulb projects shadows of landmasses onto the inner surface of the cylinder. Let’s say we get an impression of these shadows on the cylinder. Now, we remove the globe, cut the cylinder, uncurl it open and lay it flat. This is Mercator projection, named after Gerardus Mercator who introduced it in 1569. This is our map as we know it.</p><p><strong>3.2 The Inflation problem</strong></p><p>However, there is a problem with this technique. The regions near the poles get stretched resulting in abnormally large sizes. This is why Greenland appears almost the same size as Africa although the latter is about 14 times larger.</p><figure><img alt="A projected map of Earth with inflated landmasses near the poles" src="https://cdn-images-1.medium.com/max/612/0*LTI7ZwRpnfdUndB8" /><figcaption>Fig. 3.2.1 A projected map of Earth- Greenland and Africa have comparable sizes</figcaption></figure><p>So, how do we resolve this problem? The Mercator projection works best for equatorial regions and for polar regions we use the transverse Mercator i.e. we insert the globe into the cylinder such that the prime meridian touches the cylinder. This way the equatorial regions are stretched but we get an accurate map for the poles.</p><p>So, clearly, we can’t have a single map for all purposes. While selecting the model/technique to use for mapping Earth we need to decide what we can compromise on.</p><p>The widely used PCS, Web Mercator, is used by many modern web maps including the Google Maps. It preserves the local shape and angle of landmasses.</p><h3>4. Conclusion</h3><p>So, both the coordinate systems have their advantages and drawbacks and are used for different purposes. GCS is best for global datasets, navigation, and storing raw GPS data while PCS is best for local mapping, calculating areas, and measuring exact distances. We should realize our objective before using any one of these.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f8a07a816fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pointers in C++: All you need to know]]></title>
            <link>https://medium.com/@thakresopan72/pointers-in-c-all-you-need-to-know-03a90df7341a?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/03a90df7341a</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[pointers]]></category>
            <category><![CDATA[c]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 06:07:05 GMT</pubDate>
            <atom:updated>2024-09-18T06:07:05.513Z</atom:updated>
            <content:encoded><![CDATA[<p>Pointers is one of the trickiest topics in C++ to understand. However, they serve a great purpose by making dynamic memory allocation possible thus making efficient use of memory. Hence, it is important to know about them. In this article, I have explained pointers from basics with neat code and schematics.</p><h3>1. Definition</h3><p>To begin with, what do pointers classify as? Are pointers a data type?</p><p>Let’s have a look at the memory first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*NUWASsrnA44n4IOQCkwOdg.png" /><figcaption>Fig 1. Representation of memory cells with their addresses and identifiers</figcaption></figure><p>As you can see in the above figure, there are two types of cells- one which store a value (of some datatype) and the others which store address (the cell corresponding to address 0x105). And the identifiers associated with these cells (or starting addresses) are known as pointers if they contain an address. So, in the above figure, ptr is a pointer as it contains the address 0x109. Note that, just like int_var has a value 10 and char_var has a value a, ptr has a value 0x109 which is an address and <strong>not</strong> a hexadecimal value. Hexadecimal value for address is mere for representation purpose.</p><p>A pointer is said to point to some identifier if it contains the address of the identifier as its value. In the figure below, ptr points to var.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*hNaFT_80hfoBOst3BXGHIw.png" /><figcaption>Fig 2. Memory representation where ptr points to var</figcaption></figure><p>So, basically, identifiers can be classified into two categories:</p><ol><li>Pointers: they store address</li><li>Non-pointers: they store value (of some datatype)</li></ol><p>By data type, I mean basic types like int, char, float, double, etc.</p><h3>2. Operators</h3><h4>2.1 Address-of operator</h4><p>The address-of operator (&amp;), when prefixed with some identifier, returns its address. For example, in Fig 2., &amp;var is 0x847 and &amp;ptr is 0x108.</p><p>Consider the following code fragment:</p><pre>var = 10;          // let&#39;s assume var has an address 0x847<br>ptr = &amp;var;        // ptr now contains 0x847<br>another_ptr = ptr; // another_ptr also contains 0x847<br>cout&lt;&lt;var;         // 10<br>cout&lt;&lt;&amp;var;        // 0x847<br>cout&lt;&lt;ptr;         // 0x847<br>cout&lt;&lt;another_ptr; // 0x847<br>cout&lt;&lt;&amp;ptr;        // 0x108</pre><p>Note that, we cannot assign the address of any identifier with something, i.e. &amp; operator can appear only on the RHS of an assignment statement. The following code is erroneous:</p><pre>var = 10;<br>another_var = 20;<br>ptr = &amp;var;<br>&amp;var = some_address; // error</pre><h4>2.2 Dereference operator</h4><p>Dereference operator (*) can be used to get the value of identifier pointed to by some pointer, or in other words, to dereference it. This is done by prefixing a pointer with *.</p><p>Let’s assume var and ptr have address 0x847 and 0x108 respectively.</p><pre>var = 10;<br>ptr = &amp;var;         // ptr points to var<br>another_ptr = &amp;ptr; // another_ptr points to ptr<br>cout&lt;&lt;&amp;var;         // 0x847<br>cout&lt;&lt;ptr;          // 0x847<br>cout&lt;&lt;*ptr;         // 10; equivalent to var<br>cout&lt;&lt;&amp;ptr;         // 0x108<br>cout&lt;&lt;another_ptr;  // 0x108<br>cout&lt;&lt;*another_ptr; // 0x847; equivalent to ptr</pre><p>So, &amp; can be used with any identifier, but * can be used with pointers only.</p><h3>3. Data type and Declaration</h3><p>Since pointers are identifiers, they must have a datatype. The data type of a pointer is the same as that of the identifier it points to, except that it has an additional * which signifies that it’s a pointer. Hence the declaration of a pointer looks like:</p><pre>int var = 10;       // var has a type &#39;int&#39;<br>int * ptr = &amp;var;   // ptr has a type &#39;int *&#39;<br>int * another_ptr;  // another_ptr also has a type &#39;int *&#39;<br>another_ptr = &amp;var;</pre><p>The data type of a pointer has something to do with pointer arithmetic and nothing with its size. The size of a pointer depends upon the computer’s OS and CPU architecture. Talking about the pointer arithmetic, when we increment or decrement a pointer by a unit, it increments or decrements by x byte(s) where x is the size of data type of the pointer (or that of identifier pointed to by the pointer).</p><pre>int int_var = 10;            // let the address of int_var be 0x504<br>char char_var = &#39;a&#39;;         // let the address of char_var be 0x388<br>int * int_ptr = &amp;int_var;<br>char * char_ptr = &amp;char_ptr;<br>cout&lt;&lt;int_ptr;               // 0x504<br>cout&lt;&lt;++int_ptr;             // 0x508<br>cout&lt;&lt;char_ptr;              // 0x388<br>cout&lt;&lt;++char_ptr;            // 0x389</pre><p>Note that the * used in the declaration is <strong>not</strong> the dereference operator. It is mere syntax which tells the compiler that the following identifier is a pointer. And because of this reason, it is necessary to always include a * before every pointer declaration.</p><pre>int * ptr1, ptr2;   // pointer ptr1 and non-pointer (int identifier) ptr2<br>int * ptr3, * ptr4; // pointers ptr3 and ptr4</pre><h3>4. Pointers and Arrays</h3><p>In C++, arrays are like pointers to their first element. However, unlike pointers, they cannot be assigned anything.</p><pre>int arr[5];<br>int * ptr = arr; // valid<br>arr = ptr;       // invalid</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*8J_7WC0sNwSXfpIcQxQflQ.png" /><figcaption>Fig 3. Pointer to an array</figcaption></figure><p>To understand how arrays are closely related to pointers, let’s have a look at the following code fragment with assumed addresses (refer Fig 3):</p><pre>int arr[5] = {1, 2, 3, 4, 5};<br>int * ptr = arr; // array decays into pointer<br>cout&lt;&lt;ptr;       // 0x108<br>cout&lt;&lt;&amp;ptr;      // 0x847<br>cout&lt;&lt;&amp;arr;      // 0x108<br>cout&lt;&lt;*ptr;      // 1<br>cout&lt;&lt;*arr;      // 1; since arr behaves as a pointer to its first element<br>cout&lt;&lt;*(ptr+1);  // 2<br>cout&lt;&lt;*(arr+1);  // 2<br>cout&lt;&lt;ptr[2];    // 3</pre><p>As you can see above, ptr can be used instead of arr to refer to the array. The offset-operator ([]) is actually a dereference operator with an additional parameter which tells what address to dereference, e.g. ptr[2] means second element after ptr.</p><h3><strong>5. Null pointers</strong></h3><p>Pointers can point to any address — they are not limited to pointing to only ‘valid’ addresses. So, the following code is not incorrect:</p><pre>int * ptr;                  // uninitialized pointer<br>int arr[5];<br>int * another_ptr = arr+10; // out of bounds</pre><p>But what causes an error is to dereference such pointers — since it is not known what they point to.</p><p>But sometimes, we really need our pointer to point to nowhere. In such cases, we can make it point to nullptr or 0.</p><pre>int * ptr = 0;<br>int * another_ptr = nullptr;</pre><p>Here, both ptr and another_ptr are equal. In fact, all null pointers compare equal.</p><h3>References</h3><p>Cplusplus: <a href="https://cplusplus.com/doc/tutorial/pointers/">https://cplusplus.com/doc/tutorial/pointers/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03a90df7341a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My thoughts made me write a poem at midnight]]></title>
            <link>https://medium.com/@thakresopan72/my-thoughts-made-me-write-a-poem-at-midnight-b9b0add9fd71?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9b0add9fd71</guid>
            <category><![CDATA[thoughts-and-feelings]]></category>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[literature]]></category>
            <category><![CDATA[overthinking]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Sat, 10 Aug 2024 23:21:34 GMT</pubDate>
            <atom:updated>2024-08-11T13:38:09.773Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*14HFuD1xJ3kzAiA8" /><figcaption>Photo by Ruben. on Unsplash</figcaption></figure><p>About a year ago, I was sitting on a swing at midnight. My mind was full of thoughts — I was an overthinker then. And it made me write down my thoughts into a poem. Those were pure thoughts — not something out of a feeling to impress anyone. I never thought of publishing the poem. But here I am, publishing it…</p><p>I am a lot more mature now and don’t overthink anymore. I don’t encourage overthinking or any kind of act towards gaining sympathy or being delusional. But I thought why not share the work of poetry. So, here it is.</p><h3>Poem</h3><p><strong>It’s past midnight</strong></p><blockquote>It’s past midnight<br>My earphones connected to the phone are ensuring there is no noise<br>It’s not silent here at this hour<br>Crickets chirping, some other insect crying, ceiling fan humming and raindrops plinking while they drip from rooftops sadden the silence that is omnipresent<br>The loudest among these sounds is the one in my head<br>As though it were not enough some distant dog barks queue up in the show<br>Just as it’s not silent, it’s neither dark here<br>The glamour of cities, the lights eclipse the darkness within<br>Street lights, LEDs in the houses illuminate the ground<br>The ground that is now occupied by roads and buildings<br>The buildings within which humans reside<br>And the humans who encompass the soul<br>But the soul which is still gloomy<br>The artificial light rays fail to bless the human soul<br>It’s not the daytime where pompous shows are put everyday, mankind races with their shadows for survival<br>But it is slumber, where shadows are static, shows have ended and mankind drowsed<br>There still is a soul on a sleepless swing<br>Trying to calm his mind and sight<br>C’mon it’s past midnight</blockquote><h3><strong>Conclusion</strong></h3><p>I am not publishing this poem to teach a lesson. There is no takeaway from it. It is merely a voice to human thoughts — thoughts we do not keep a control on.</p><p>Regards</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9b0add9fd71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tools to Visualize Complex Curves]]></title>
            <link>https://medium.com/@thakresopan72/tools-to-visualize-complex-curves-39dcc8c6ab8d?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/39dcc8c6ab8d</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[geometry]]></category>
            <category><![CDATA[geogebra]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 16:34:45 GMT</pubDate>
            <atom:updated>2024-07-24T16:34:45.256Z</atom:updated>
            <content:encoded><![CDATA[<p>I always talk about visualization- a way to embrace Math and if it’s geometry, equations aren’t enough. For an abstract context, a curious mind always wonders- how does it look like? This story is about the tools that come handy for plotting complex curves. We will discuss AI- ChatGPT and an online tool- GeoGebra.</p><h3>Problem Statement</h3><p>Let’s begin with a curve:</p><blockquote>Plot the locus of the incentre of a triangle with a fixed base and a fixed altitude.</blockquote><p>Let’s simplify this by making some assumptions: fixed base- BC with B(-1, 0)and C(1, 0)and a fixed altitude of length 1 such that the third point (variable), A, lies on the line y = 1. So, coordinates of A are (x, 1) for x lying in the range [-5, 5].</p><p>Let’s plot this using different tools.</p><h3>Plotting Curve</h3><blockquote><strong><em>1. ChatGPT</em></strong></blockquote><p>In the age of AI, it is not difficult to get your complex tasks done. I asked ChatGPT 4o to plot curve for the above problem statement and it returned me a Python code. We will break it down here.</p><p>Importing necessary libraries:</p><pre>import matplotlib.pyplot as plt<br>import numpy as np</pre><p>Constants:</p><pre>B = np.array([-1, 0])<br>C = np.array([1, 0])<br>altitude = 1<br>x_range = np.linspace(-5, 5, 1000)<br>y = altitude</pre><p>Function to calculate incenter:</p><pre>def incenter(A, B, C):<br>  a = np.linalg.norm(B-C)<br>  b = np.linalg.norm(C-A)<br>  c = np.linalg.norm(A-B)<br>  return (a*A + b*B + c*C)/(a + b + c)</pre><p>Collecting incenter points:</p><pre>incenters = []<br>for x in x_range:<br>  A = np.array([x, y])<br>  I = incenter(A, B, C)<br>  incenters.append(I)<br>incenters = np.array(incenters)</pre><p>Plotting locus:</p><pre>plt.figure(figsize=(8, 4))<br>plt.scatter(incenters[:, 0], incenters[:, 1], c=&quot;blue&quot;, s=1, label=&quot;Incenter locus&quot;)<br>plt.scatter([B[0], C[0]], [B[1], C[1]], c=&quot;red&quot;, label=&quot;Fixed base points&quot;)<br>plt.scatter(x_range, np.full_like(x_vals, y), c=&quot;green&quot;, s=1, label=&quot;Third vertex locus&quot;)<br>plt.xlabel(&quot;x&quot;)<br>plt.ylabel(&quot;y&quot;)<br>plt.legend()<br>plt.title(&quot;Locus of Incenter of a triangle with fixed base points and a fixed altitude&quot;)<br>plt.grid(True)<br>plt.axis(&quot;equal&quot;)<br>plt.show()</pre><p>This is how it looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*az1KwEtB50ngNBHYuq_gIg.png" /><figcaption>Fig 1. Locus of incenter of a triangle with fixed base points and a fixed altitude</figcaption></figure><p>You can get the code <a href="https://github.com/henk1729/Plotting-Curves/blob/main/incenter_fixed_base_and_altitude.py">here</a>.</p><blockquote><strong><em>2. GeoGebra</em></strong></blockquote><p>How about some controlled locus- something like a video? For that, we will use GeoGebra’s parametric equation plotter. So, let’s generate parametric equations for this curve first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*hEd7Pk_h7s7wVKnjqWWXZw.png" /><figcaption>Fig. Parametric equations for incenter locus</figcaption></figure><p>You can find the derivation <a href="https://github.com/henk1729/Plotting-Curves/blob/main/Incenter%20locus%20parametric%20equation%20derivation.pdf">here</a>.</p><p>Search for <a href="https://www.geogebra.org/m/cAsHbXEU">GeoGebra online parametric equation plotter</a>. Then, you get a window as shown in Fig below. All you need to do is put parametric equations for x and y in the textboxes against them. Next, you fix limits for the parametric variable. All set! Now, just vary t and you can see the path traced by incenter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*XlZVUZ97P6aXSeU89qinCQ.gif" /><figcaption>Fig. Animated view of locus of incenter as parametric variable, t varies</figcaption></figure><p>You can also add points and other curves through the Input textbox below. Just type the equation like y = 2x or point like (-1,0).</p><p>I have one more problem statement for you: <em>Plot the locus of incenter of a triangle with two of its vertices as focii of an ellipse and the third vertex lies on the ellipse.</em> Can you tell me what is the curve obtained?</p><h3>Conclusion</h3><p>That’s it from this story. Try to experiment with different configurations and centers for a triangle or any polygon. The more you visualize, you realize how less you could. These tools are a great help when it comes to 3D. I will cover more of such tools in my upcoming stories. So, my mathophilics, follow me for more of such stories. Till then, goodbye!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39dcc8c6ab8d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reflection of a Ray inside a Rectangle]]></title>
            <link>https://medium.com/@thakresopan72/can-you-solve-this-math-problem-430e459516b4?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/430e459516b4</guid>
            <category><![CDATA[geometry]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[graph-theory]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 20:18:12 GMT</pubDate>
            <atom:updated>2024-09-03T15:30:13.301Z</atom:updated>
            <content:encoded><![CDATA[<p>Around a week ago, while looking at a blank piece of paper a thought hit my mind- How will a ray behave on reflection inside this paper? What will be its trajectory? And that brought me to this discussion.</p><h3>Introduction</h3><p>We have a rectangle and a ray that is originated from a point on the rectangle. The ray is fired inside the rectangle from this arbitrary point at some angle. As it is incident on the sides it gets reflected continuously following the laws of reflection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*RjVMg6emmdfVyVkQcd1UkA.gif" /><figcaption>Fig 1. Continuous reflection of a ray fired from some point at an angle θ inside a rectangle</figcaption></figure><blockquote>So, for θ = π/4, is it possible for the ray to not follow the same path?</blockquote><blockquote>Is it possible that the ray keeps on visiting points infinitely and does not get caught in a loop?</blockquote><blockquote>Is it possible that there is no point that remains unvisited always?</blockquote><h3><strong>Terminologies and </strong>Assumptions</h3><ol><li><em>Firing point</em>: point from where the ray is released [T1]</li><li><em>Firing angle</em>: angle that the fired ray makes with the normal at the firing point [T2]</li><li><em>Base</em>: side on which the rectangle is rested (for firing) or side containing the initial point of reflection (from where first reflected ray originated) [T3]</li><li><em>Visited</em>: a point on rectangle is said to be visited if the ray was incident at it; an edge is said to be visited if it connects visited points [T4]</li><li><em>Mapping</em>: a point M is said to be a mapping of some other point P if there is a direct edge between the two [T5]</li></ol><p>This problem can be formulated as a graph problem, with every point on rectangle as a node. Hence, it is a graph with infinite nodes. As we fix the firing point and the firing angle, the graph is computed- it has edges connecting points which are visited in consecutive reflections of the ray. As the ray goes on reflecting, it traces out a path. With each reflection, the path gets longer unless the ray stumbles upon a visited edge. So, the problem is —</p><blockquote><strong>Formal problem statement</strong></blockquote><blockquote>For a rectangle with sides of length <strong>a</strong> and <strong>b</strong> (<strong>a, b</strong> <strong>∈ R </strong>and <strong>a</strong>, <strong>b</strong> <strong>&gt;</strong> <strong>0</strong>), does there exist a point on the base at a distance <strong>x</strong> from the bottom-left corner (<strong>0 ≤ x ≤ a</strong> when side with length <strong>a </strong>is the base, and <strong>0 ≤ x ≤ b</strong> when side with length <strong>b </strong>is the base) from where a ray with an angle <strong>θ</strong> (<strong>0 ≤ θ </strong>&lt;<strong> π/2</strong>) with the normal at the point is fired, such that the equivalent graph, <strong>G(a, b, x, θ)</strong>, has no disconnected component?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*arjHBLb2jqESInergd_vcg.png" /><figcaption>Fig 2. A ray fired from a point at distance x from bottom-left corner at an angle θ on a rectangle with sides a and b</figcaption></figure><p>We are going to deal with θ = π/4.</p><p>Here are some assumptions made about the problem, some of them pretty obvious —</p><ol><li>There is no friction or any sort of practicality involved in the problem — the case is completely ideal. [A1]</li><li>The ray follows laws of reflection — incident and reflected rays lie on either sides of the normal, make equal angles (angle of incidence and angle of reflection) with it and are contained in the same plane as the rectangle. [A2]</li><li>The normal at any corner is coincident with the angle bisector of the angle contained between the sides that contain the corner i.e. the normal is at an angle of π/4 with the sides. [A3]</li></ol><h3>Theorems</h3><p>Everything said in the below theorems is in the context of the problem —</p><blockquote><strong>[t1]</strong> Except the angles at a corner, the angle of reflection and the angle of incidence are always <strong>θ</strong> or<strong> π/2-θ</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KghyW8nW3LmYmKlN8QUkwg.jpeg" /><figcaption>Fig 3. Types of incident rays</figcaption></figure><p>RI₁ and RI₂ are rays incident on different sides. Considering the symmetry of configuration of points, these are the only possible cases (except the corner case discussed below) regardless of θ.</p><blockquote><strong>[t2] </strong>The angles at a corner are always <strong>|π/4-θ|</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDTt4FYQD8xiH-ysIyD2Dw.jpeg" /><figcaption>Fig 4. Incident ray at a corner with initial angle of reflection θ (θ &lt; π/4) and consequent reflected ray</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Eqf7_Jr-wIpWn69A9L2CQ.jpeg" /><figcaption>Fig 5. Incident ray at a corner with initial angle of reflection θ (θ &gt; π/4) and consequent reflected ray</figcaption></figure><p>From Fig 4 and 5, we can see that the angle of incidence (and the angle of reflection) at a corner is the absolute difference between θ and π/4. Again, these are generic cases. In Fig 4, if the left side of the rectangle was farther, the second reflected ray, I₁I₂ would have hit the base instead with an angle of incidence π/2-θ. A similar case for Fig 5 can be observed.</p><p>If θ = π/4, the first reflected ray, RI₁ would be normal to the corner and hence trace back the same path.</p><blockquote><strong>[t3]</strong> When the ray is reflected (or fired) from some point at an angle <strong>α</strong>, the angle of incidence of the second reflected ray is <strong>α</strong> when the ray hits the opposite side (opposite to side containing the point) and <strong>π/2-α</strong> when it hits the adjacent side. However, if it hits a corner, the second reflected ray makes an angle <strong>π/2-α</strong> when it hits the same side (side from which first reflected ray originated) and <strong>α</strong> when it hits the adjacent side.</blockquote><p>This is clear from Fig 3 to 5.</p><p>So, when the ray hits a corner, the {relative side of incidence : angle of incidence} mapping is switched. Like, from {opposite : θ} to {opposite : π/2-θ}. With even corner hits, the mapping is restored. In this way, it toggles.</p><h3>Proof</h3><p>We are dealing with a specific case, θ = π/4.</p><p>We saw that when we fix <em>x </em>and<em> θ</em>, the equivalent graph is computed. Also, every node except the corners has two edges implying the incident and reflected rays. In this way, every node is mapped with two distinct nodes. But for the corners, as we saw in [t2], the incident and the reflected ray would be coincident meaning these nodes are connected with just a single node — their only mapping (Fig 6).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hzSNc8MJZXI7ME3BWhFMA.png" /><figcaption>Fig 6. Corners c₁, c₂, c₃, c₄ with their respective mappings map(c₁), map(c₂), map(c₃), map(c₄)</figcaption></figure><p>So, all the nodes have a maximum degree of 2. Hence, one of the components of the graph may look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQTvbdz55CAtazsN6JiBoQ.png" /><figcaption>Fig 7. A component of equivalent graph, G with two corners</figcaption></figure><p>This is how a component which has two corners would look like with a finite number of non-corner points. As is evident, there is no room for any more corner in the component without exceeding the maximum degree of the points. Hence the graph has at least two disconnected components. This eliminates the possibility of a no-component graph.</p><h3>Conclusion</h3><p>If you have read this far, I would appreciate your patience and understanding. Thank you for sticking with me. I understand that the statements in the article could be ambiguous and there might even be errors. This is my first time trying to prove something combining geometry and graph theory. So, I would love if you could help me point out mistakes if any. I would also love if you could tell me what you feel about it.</p><p>One more thing, I am adding no reference as I couldn’t find any work done on this problem before. All that I have presented here is my own work.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=430e459516b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python- Compiled or Interpreted?]]></title>
            <link>https://medium.com/@thakresopan72/python-compiled-or-interpreted-13dee719ad81?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/13dee719ad81</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[interpretation]]></category>
            <category><![CDATA[compilers]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Thu, 16 May 2024 17:09:43 GMT</pubDate>
            <atom:updated>2024-05-16T17:09:43.873Z</atom:updated>
            <content:encoded><![CDATA[<h4>There’s more to it!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GDwKVX2-iCe-X3Y-" /><figcaption>Photo by <a href="https://unsplash.com/@rubaitulazad?utm_source=medium&amp;utm_medium=referral">Rubaitul Azad</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>“Give instances of compiled and interpreted languages and how are they different?” This is a common question that every Computer Science undergrad has gone through. And, just like every other student, I would quickly come up with- “A compiled language is the one which is translated into machine code first and is then executed by the machine e.g. C, C++. On the other hand, an interpreted language like Python executes directly on runtime without compilation.” Well, fair enough to get you passed through that viva but not quite the truth.</p><p><em>Python is an interpreted language</em> is not incorrect but also not completely true. Let’s understand the terms better.</p><h3><strong>Compilation</strong></h3><p>What do you mean by compilation? Compilation, simply put, is translation. The conversion of one programming language into another, not necessarily distinct (in that case, compilation may have significant transformations on the source code). And, in our context, it is the conversion of source code into machine understandable code- called machine language. An executable file is produced as a result. This file is architecture-specific meaning that the same file will not work on some other OS.</p><h3><strong>Interpretation</strong></h3><p>An interpreter directly executes the input code into machine language as it runs the program line by line. However, the input code need not be the source code of the program. It may be some intermediate code generated by the process of compilation.</p><h3>Compiled/Interpreted is a property of Implementation</h3><p>Now, before we jump on answering if Python is compiled or interpreted it is important to know that being compiled or interpreted is a property of the implementation that a language follows and not of the language itself.</p><p>The most popular and official implementation of Python- CPython is compiled as well as interpreted. The source code is converted into bytecode on compilation and is then fed to Python Virtual Machine for execution. This bytecode, unlike the machine code, is portable and not machine-specific. These steps are different for different implementations of Python.</p><h3><strong>Conclusion</strong></h3><p>Well, the official documentation of Python says that it is <em>interpreted</em> so there was nothing to debate here. However, things are more complex than written. Now you know that. It is very important to understand that there is no one-size-fits-all definition of terms covered here. For instance, the process of compilation- again, there’s more to it, different for different implementations.</p><p>Nevertheless, now you know a little more about Python, don’t you? ;)</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13dee719ad81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Knight’s Tour Problem]]></title>
            <link>https://medium.com/@thakresopan72/the-knights-tour-problem-cafd7bac53d0?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cafd7bac53d0</guid>
            <category><![CDATA[math]]></category>
            <category><![CDATA[graph-theory]]></category>
            <category><![CDATA[knights-tour]]></category>
            <category><![CDATA[bipartite-graph]]></category>
            <category><![CDATA[board-games]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 17:40:27 GMT</pubDate>
            <atom:updated>2024-04-17T17:40:27.618Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mp92N3OPgIf0W4Yp" /><figcaption>Photo by <a href="https://unsplash.com/@hpzworkz?utm_source=medium&amp;utm_medium=referral">Hassan Pasha</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>About a week ago, I came across a reel about the Knight’s tour problem. This reminded me of the same problem I encountered a few years ago and it made me curious to solve it.</p><h3><strong>Introduction</strong></h3><p>The Knight’s tour problem, formally put, states- “Does there exist a Hamiltonian path and a Hamiltonian cycle for a single knight on a chessboard of size m*n?”. In simpler terms, given a chessboard of size m*n and a knight placed randomly on the board, is it possible to devise a sequence of steps of knight moves such that it covers all the positions on the board visiting each position exactly once. That’s a Hamiltonian path. If the knight ends up at a position from where it can reach its starting position, we say that a Hamiltonian cycle exists.</p><p>Let’s explore!</p><h3><strong>Regular chessboards</strong></h3><p>We will look at regular chessboards first i.e. m = n.</p><p>What are your thoughts on n = 1, 2? There’s no solution possible, right? The knight has nowhere to move. What about n = 3? There are 3 symmetrically distinct initial positions- a1, a2 and b2. There’s no path for b2 as starting position. The two others are shown below (the number in yellow shows the possible no. of moves from the cell it appears on).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*R1HkHdvJXgZV0EQEfebkXw.png" /><figcaption>Fig 1. A 3x3 chessboard</figcaption></figure><figure><img alt="Knight path on a 3 x 3 chessboard starting from a1" src="https://cdn-images-1.medium.com/max/864/1*u_i1e-QbZyQOIELFLhS7zQ.gif" /><figcaption>Fig 2. Knight path for 3x3 chessboard starting from a1</figcaption></figure><figure><img alt="Knight path on a 3 x 3 chessboard starting from a2" src="https://cdn-images-1.medium.com/max/864/1*8du-pqxFAToGD5wXkTQOiw.gif" /><figcaption>Fig 3. Knight path for 3x3 chessboard starting from a2</figcaption></figure><p>Apparently, there’s no solution for 3*3 knight’s tour problem for a Hamiltonian path and hence not for a Hamiltonian cycle either.</p><p>If you observe carefully, a knight alternates between black and white cells every time it moves. Now, say we place our knight at a black cell (move 1). Next, it moves to a white cell (move 2). So, the knight is at a black cell for every odd move and at a white cell for every even one. If there is a Hamiltonian cycle, the last move (move n*n) has to be at a white cell i.e. n*n must be even. But this is not possible when n is odd. Hence, there exists no Hamiltonian cycle for odd value of n. In general, there exists no Hamiltonian cycle for an m*n board where m and n are both odd.</p><h4>Warnsdorff’s Heuristic</h4><p>For n = 4, a Hamiltonian path or an open tour does not exist. It can be checked by running the following code:</p><pre>#include&lt;bits/stdc++.h&gt;<br>#define n 4<br>using namespace std;<br><br>void displayBoard(vector&lt;vector&lt;int&gt; &gt; board){<br>    for(int r = 0; r &lt; n; r++){<br>        for(int c = 0; c &lt; n; c++){<br>            cout&lt;&lt;board[r][c]&lt;&lt;&#39;\t&#39;;<br>        }<br>        cout&lt;&lt;endl;<br>    }<br>    cout&lt;&lt;endl;<br>}<br><br>int getPosDegree(vector&lt;vector&lt;int&gt; &gt; board, int r, int c){<br>    vector&lt;pair&lt;int, int&gt; &gt; knightPositions{<br>        {r-2, c-1},<br>        {r-2, c+1},<br>        {r-1, c-2},<br>        {r-1, c+2},<br>        {r+1, c-2},<br>        {r+1, c+2},<br>        {r+2, c-1},<br>        {r+2, c+1}<br>    };<br><br>    int cnt = 0;<br>    for(int i = 0; i &lt; 8; i++){<br>        int row = knightPositions[i].first, col = knightPositions[i].second;<br>        if(row &gt;= 0 &amp;&amp; row &lt; n &amp;&amp; col &gt;= 0 &amp;&amp; col &lt; n &amp;&amp; board[row][col] == 0){<br>            cnt++;<br>        }<br>    }<br>    return cnt;<br>}<br><br>void verifyPositions(vector&lt;pair&lt;int, int&gt; &gt;&amp; knightPositions, vector&lt;vector&lt;int&gt; &gt; board){<br>    vector&lt;pair&lt;int, int&gt;&gt;::iterator it = knightPositions.begin();<br>    while(it != knightPositions.end()){<br>        bool outOfBoard = (it-&gt;first &lt; 0 || it-&gt;first &gt;= n || it-&gt;second &lt; 0 || it-&gt;second &gt;= n);<br>        if(outOfBoard){<br>            knightPositions.erase(it);<br>            continue;<br>        }<br>        bool posOccupied = (board[it-&gt;first][it-&gt;second] != 0);<br>        if(posOccupied){<br>            knightPositions.erase(it);<br>            continue;<br>        }<br>        ++it;<br>    }<br>}<br><br>vector&lt;pair&lt;int, int&gt; &gt; getPossiblePositions(vector&lt;vector&lt;int&gt; &gt; board, int r, int c){<br>    vector&lt;pair&lt;int, int&gt; &gt; knightPositions{<br>        {r-2, c-1},<br>        {r-2, c+1},<br>        {r-1, c-2},<br>        {r-1, c+2},<br>        {r+1, c-2},<br>        {r+1, c+2},<br>        {r+2, c-1},<br>        {r+2, c+1}<br>    };<br><br>    verifyPositions(knightPositions, board);<br>    return knightPositions;<br>}<br><br>bool solveKnightsTour(vector&lt;vector&lt;int&gt; &gt;&amp; board, int r, int c, int moveCnt){<br>    board[r][c] = moveCnt;<br>    if(moveCnt == n*n){<br>        return true;<br>    }<br><br>    vector&lt;pair&lt;int, int&gt; &gt; possibleMoves = getPossiblePositions(board, r, c);<br>    int len = possibleMoves.size();<br>    if(len == 0){<br>        board[r][c] = 0;<br>        return false;<br>    }<br>    multimap&lt;int, int&gt; numMovesFromPosInd;<br>    for(int i = 0; i &lt; len; i++){<br>        int deg = getPosDegree(board, possibleMoves[i].first, possibleMoves[i].second);<br>        numMovesFromPosInd.insert({deg, i});<br>    }<br>    <br>    for(auto position:numMovesFromPosInd){<br>        pair&lt;int, int&gt; pos = possibleMoves[position.second];<br>        if(solveKnightsTour(board, pos.first, pos.second, moveCnt+1)){<br>            return true;<br>        }<br>    }<br>    board[r][c] = 0;<br>    return false;<br>}   <br><br>vector&lt;pair&lt;int, int&gt; &gt; generateInitialPos(){<br>    vector&lt;pair&lt;int, int&gt; &gt; positions;<br>    int len = (n+1)/2;<br>    for(int i = 0; i &lt; len; i++){<br>        for(int j = i; j &lt; len; j++){<br>            positions.push_back({i, j});<br>        }<br>    }<br>    return positions;<br>}<br><br>int main(){    <br>    vector&lt;pair&lt;int, int&gt; &gt; initialPos = generateInitialPos();<br>    for(auto pos:initialPos){<br>        vector&lt;vector&lt;int&gt; &gt; board(n, vector&lt;int&gt;(n, 0));<br>        cout&lt;&lt;solveKnightsTour(board, pos.first, pos.second, 1)&lt;&lt;endl;<br>        displayBoard(board);<br>        cout&lt;&lt;endl;<br>    }<br>}</pre><p>You can get an open tour (if it exists) for an n*n board with the above code. It uses the Warnsdorff’s rule to devise a tour. According to it, out of all the possible moves for a knight choose the one with the least degree i.e. choose the one from where there are the least number of further knight moves. Warnsdorff’s heuristic for a 6*6 board is illustrated below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*5UHbPzjSThedG9zTN6daPA.gif" /><figcaption>Fig 4. 6x6 chessboard open tour with Warnsdorff’s heuristic</figcaption></figure><h3><strong>Irregular chessboards</strong></h3><p>Let’s talk about irregular boards now. It is known that:</p><pre>An m*n chessboard with m &lt;= n has a (closed) knight&#39;s tour unless<br>one or more of these conditions hold(s):<br>(a) m and n are both odd;<br>(b) m = 1, 2, or 4; or<br>(c) m = 3 and n = 4, 6, or 8</pre><p>We have already proved (a) above. For (b), when m = 1, the knight can’t move and for m = 2, the knight can only travel in one direction, hence no tour is possible. For m = 4, consider a 4*n board with the positions in outer rows marked red and those in inner rows marked blue (Fig 5). So, there are 2n red cells and 2n blue cells. Also, the knight can only reach a red cell from a blue cell and can go to only a blue cell from a red one which implies that no two consecutive moves end up on red cells. And, given the equal number of blue and red cells the only way a cycle may complete is by alternating red and blue cells i.e. alternating outer and inner rows. Moreover, we saw that a knight always alternates between black and white cells. That means, if there were to be a cycle, there has to be a one-to-one correspondence between red-white or red-black cells which means that all the cells marked red must be either all white or all black. But this contradicts the standard alternating pattern of black and white cells for the chessboard. Hence, there is no closed tour for a board of dimensions 4*n.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*0J1INvhXEW0zoys2Of-s5w.png" /><figcaption>Fig 5. 4x6 chessboard with outer rows marked red and inner rows marked blue</figcaption></figure><p>So, we have proved (a), (b) and first part of (c). All the other boards which do not fall into these categories ((a), (b), and (c)) have a closed tour (Hamiltonian cycle).</p><h3><strong>Conclusion</strong></h3><p>That’s all folks. But no, that’s not it. The knight’s tour is not limited to a board of size m*n. There can be multiple variations for the problem like a tour on the surface of a cube, or on that of a torus, or on an unbounded plane! There are endless possibilities and the complexities keep on adding up.</p><p>Hope you liked the story. Upvote if it helped you in understanding the problem and its approach better. :)</p><h3><strong>References</strong></h3><p>I’m grateful to <a href="https://charlotte-sweeney.medium.com/the-knights-tour-finding-some-of-its-solutions-37a52ab7a339">this</a> story by <a href="https://charlotte-sweeney.medium.com/">Charlotte Sweeney</a> and following references for their aid in the writing of this article:</p><ol><li>Schwenk, A. (1991). Which Rectangular Chessboards Have a Knight’s Tour? Mathematics Magazine, 64. (pp. 325–332)</li><li>Wikipedia contributors. (2024, April 2). Knight’s tour. In Wikipedia, The Free Encyclopedia. Retrieved 17:12, April 17, 2024, from <a href="https://en.wikipedia.org/w/index.php?title=Knight%27s_tour&amp;oldid=1216809546">https://en.wikipedia.org/w/index.php?title=Knight%27s_tour&amp;oldid=1216809546</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cafd7bac53d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualizing Variance and why is it Important]]></title>
            <link>https://medium.com/@thakresopan72/visualizing-variance-and-why-is-it-important-ee4c4ee70fca?source=rss-b4f7a997ab0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee4c4ee70fca</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[probability-distributions]]></category>
            <category><![CDATA[variance]]></category>
            <dc:creator><![CDATA[Sopan Thakre]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 18:01:46 GMT</pubDate>
            <atom:updated>2024-03-09T18:01:46.748Z</atom:updated>
            <content:encoded><![CDATA[<p>I have always wondered what variance for a sample ‘looked like’? It is easy to visualize mean and other measures of central tendency but when it comes to variance, visualization is tough. Isn’t it? Well, no more!</p><p>In this article I’m going to help you ‘visualize’ variance.</p><p>We know the formula for variance, s² of a sample of size, n with sample mean, x_bar of some population is:</p><figure><img alt="Equation for variance of a sample" src="https://cdn-images-1.medium.com/max/183/1*v43P_zvO76Ppao0i3QBk8w.gif" /><figcaption>Eq 1. Equation for variance of sample with size n</figcaption></figure><p>The n — 1 used in the equation instead of n, is due to degrees of freedom and is beyond the scope of this article. Let’s stick to our topic.</p><p>From the above equation (Eq 1), it is clear that variance is the mean of squared distances of sample points from the sample mean (where distance here is referred to |x_i — x|). If this were a weighted mean equation, we can say that the weight of all the points is the same. This leads us to another inference — all the points contribute solely on the basis of their distance from the mean. So, more the distance, greater the contribution, and hence greater the variance.</p><p>Here is a plot of three samples with their mean, extended on the y-axis for comparison. All these samples have the same mean but what is it that discriminates one from another? The distribution of the sample points or in other words the scatter. sample_2 is distributed more on the extremes while sample_3 (top) is concentrated at the center when compared to sample_1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YM9vCHSW4bu2RWn5xn0Qg.png" /><figcaption>Fig 1. Samples plot</figcaption></figure><p>As a result, the contribution of the points towards their respective variances is higher in sample_2 than that in sample_3 . Similarly, contribution of sample_1 points is greater than that of sample_3 points as it has points at farther distances. However, absence of points near the mean in sample_2 removes the poor contenders (smaller squared distance values) for variance thus increasing its value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*243f2aR_OWFWNr6Um9JcOw.png" /><figcaption>Fig 2. Variance comparison</figcaption></figure><p>Let’s try an example. Suppose there are three universities. Let’s label their past year’s placement package samples as a, b and c. The mean package for all the universities is the same, say 10 lpa. However, a had uniform packages in the range [0–20] lpa while b had fewer packages but in the range [0–5]U[15–20]lpa. c, on the other hand, had packages in the range [5–15]lpa. Now you want to refer one of these universities to a friend, named HENK. Which would it be? Mean package may be misleading and sometimes, like in this case, median too. Because median package for b could lie on either sides of the set — [0-5] or [15-20], and so, fails to provide an idea about the distribution. Well, what university HENK fits best in is up to you but variance really has got a part to play here.</p><p>That’s it folks! Hope I helped you visualize variance till a certain extent and made you understand why variance is important to know more about some sample. Well, words and my technical skills really hamper me from delivering what one can deliver on a board but I tried my best to make you understand. If you couldn’t ‘see’ enough of variance, check <a href="https://seeing-theory.brown.edu/basic-probability/index.html#section3">this</a> page out from <strong>Seeing Theory </strong>and play around with it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee4c4ee70fca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>