<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Chet Chopra</title>
    <description>The latest articles on Forem by Chet Chopra (@chetchopra).</description>
    <link>https://forem.com/chetchopra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F208630%2F2e8d9001-0645-43e5-b075-1f37190b822e.jpg</url>
      <title>Forem: Chet Chopra</title>
      <link>https://forem.com/chetchopra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chetchopra"/>
    <language>en</language>
    <item>
      <title>Recursion</title>
      <dc:creator>Chet Chopra</dc:creator>
      <pubDate>Thu, 10 Oct 2019 19:34:58 +0000</pubDate>
      <link>https://forem.com/chetchopra/recursion-4j7a</link>
      <guid>https://forem.com/chetchopra/recursion-4j7a</guid>
      <description>&lt;p&gt;To understand recursion you must first understand recursion&lt;/p&gt;

&lt;p&gt;&lt;i&gt;Hopefully this joke makes sense by the end of this!&lt;/i&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A bit of background
&lt;/h2&gt;

&lt;p&gt;Before we dive into recursion let’s go over some concepts that you’ll need.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens when you call a function?
&lt;/h3&gt;

&lt;p&gt;When a function is called an execution context is placed on the call stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the call stack?
&lt;/h3&gt;

&lt;p&gt;The call stack is a pretty deep topic but for our purposes just know that it keeps track of what function is being executed.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is an execution context?
&lt;/h3&gt;

&lt;p&gt;Don’t worry about it. Just know that when you call a function you are putting instructions, variables, and parameters onto for that function call onto the call stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Stack?
&lt;/h3&gt;

&lt;p&gt;A stack is a data structure that follows the first in last out procedure. Imagine, that you have a stack of plates. You can place one plate on top of the other and to remove a plate there must be no plates on top of it. With that in mind we know that the first plate we put down will be the last one we get we get out because we have to remove the plates on top of it first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Ruby&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;
  &lt;span class="n"&gt;sayWords&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sayWords&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Hello there"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;speak&lt;/span&gt;
&lt;span class="c1"&gt;#output --&amp;gt; "Hello there"&lt;/span&gt;

&lt;span class="c1"&gt;#Call Stack&lt;/span&gt;
&lt;span class="c1"&gt;#1. sayWords --&amp;gt; Speak calls sayWords so that gets placed on the stack as #well&lt;/span&gt;
&lt;span class="c1"&gt;#0. speak --&amp;gt; Our program begins by calling speak so it gets placed on #the stack&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The thing to note is that we call speak which calls sayWords but speak doesn't finish until sayWords finishes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recursion
&lt;/h2&gt;

&lt;p&gt;Recursion is the repeated application of a procedure. In software we see this concept in recursive functions.&lt;/p&gt;

&lt;p&gt;A recursive function is a function that calls itself…Let's play with that idea.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Ruby &lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;addUp&lt;/span&gt;
  &lt;span class="n"&gt;addUp&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="c1"&gt;#output --&amp;gt; Stack Overflow Error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We get an error here because the function is endlessly calling itself creating an infinite loop. This loop continues until the call stack is full and throws you a stack overflow error.&lt;/p&gt;

&lt;p&gt;At this point this idea seems pretty useless. Buts lets say we add a condition or a base case to this behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Ruby &lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;count_down&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;
    &lt;span class="n"&gt;count_down&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;count_down&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#output &lt;/span&gt;
&lt;span class="c1"&gt;#--&amp;gt; 3&lt;/span&gt;
&lt;span class="c1"&gt;#--&amp;gt; 2&lt;/span&gt;
&lt;span class="c1"&gt;#--&amp;gt; 1&lt;/span&gt;
&lt;span class="c1"&gt;#Call Stack&lt;/span&gt;
&lt;span class="c1"&gt;#3. count_down(0)&lt;/span&gt;
&lt;span class="c1"&gt;#2. count_down(1)&lt;/span&gt;
&lt;span class="c1"&gt;#1. count_down(2)&lt;/span&gt;
&lt;span class="c1"&gt;#0. count_down(3)&lt;/span&gt;
&lt;span class="c1"&gt;#What's going on&lt;/span&gt;
&lt;span class="c1"&gt;#Call to count_down(3)&lt;/span&gt;
&lt;span class="c1"&gt;#puts 3 &lt;/span&gt;

&lt;span class="c1"&gt;# Note that count_down(3) still isn't done because its waiting for #count_down(2) &lt;/span&gt;
&lt;span class="c1"&gt;#Call to count_down(2)&lt;/span&gt;
&lt;span class="c1"&gt;#puts 2&lt;/span&gt;
&lt;span class="c1"&gt;#Call to count_down(1)&lt;/span&gt;
&lt;span class="c1"&gt;#puts 1&lt;/span&gt;
&lt;span class="c1"&gt;#Call to count_down(0)&lt;/span&gt;
&lt;span class="c1"&gt;#Base Case Hit&lt;/span&gt;
&lt;span class="c1"&gt;#return to count_down(0)&lt;/span&gt;
&lt;span class="c1"&gt;#count_down(0) execution complete&lt;/span&gt;
&lt;span class="c1"&gt;#count_down(1) execution complete&lt;/span&gt;
&lt;span class="c1"&gt;#count_down(2) execution complete&lt;/span&gt;
&lt;span class="c1"&gt;#count_down(3) execution complete&lt;/span&gt;
&lt;span class="c1"&gt;#COMPLETE!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let’s do the same without recursion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Ruby &lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;count_down&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;
    &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;count_down&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#output &lt;/span&gt;
&lt;span class="c1"&gt;#--&amp;gt; 3&lt;/span&gt;
&lt;span class="c1"&gt;#--&amp;gt; 2&lt;/span&gt;
&lt;span class="c1"&gt;#--&amp;gt; 1&lt;/span&gt;
&lt;span class="c1"&gt;#Call Stack&lt;/span&gt;
&lt;span class="c1"&gt;#0. count_down(3)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Why should you use recursion?
&lt;/h3&gt;

&lt;p&gt;You probably shouldn’t. In most situations you can accomplish the same with a loop. Also, since recursion leverages the call stack the program could run into a stack overflow error.&lt;/p&gt;

&lt;p&gt;However recursive solutions can be more elegant to read. It’s said that recursive solutions divide and conquer the problem by turning a large problem into a series of smaller ones. Let’s take a look at an example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;The function we want to write takes in two numbers, multiplies them, and returns the value. The catch is that you can’t use the * operator.&lt;/p&gt;

&lt;p&gt;So our large problem is multiplication and we will use a series of additions to solve it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Regular Function
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="n"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;times&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#output --&amp;gt; 20&lt;/span&gt;
&lt;span class="c1"&gt;#Call Stack &lt;/span&gt;
&lt;span class="c1"&gt;#0. multiply(5, 4)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Recursive Function
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt; 
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#output --&amp;gt; 30&lt;/span&gt;

&lt;span class="c1"&gt;#Call Stack&lt;/span&gt;
&lt;span class="c1"&gt;#3. 2 + multiply(0, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#2. 2 + multiply(1, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#1. 2 + multiply(2, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#0. multiply(3, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#What's going on&lt;/span&gt;
&lt;span class="c1"&gt;#Call to multiply(3, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#Call to 2 + multiply(2, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#Call to 2 + multiply(1, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#Call to 2 + multiply(0, 2)&lt;/span&gt;
&lt;span class="c1"&gt;#Base Case Hit&lt;/span&gt;
&lt;span class="c1"&gt;#0 returned to 2 + multiply(0, 2) --&amp;gt; 2 + 0&lt;/span&gt;
&lt;span class="c1"&gt;#2 returned to 2 + multiply(1, 2) --&amp;gt; 2 + 2&lt;/span&gt;
&lt;span class="c1"&gt;#4 returned to 2 + multiply(2, 2) --&amp;gt; 4 + 2&lt;/span&gt;
&lt;span class="c1"&gt;#6 returned to multiply(3, 2)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That was a brief intro into recursion!&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Call_stack?source=post_page-----5156e152a608----------------------"&gt;https://en.wikipedia.org/wiki/Call_stack?source=post_page-----5156e152a608----------------------&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/recursion-is-not-hard-858a48830d83/?source=post_page-----5156e152a608----------------------"&gt;https://www.freecodecamp.org/news/recursion-is-not-hard-858a48830d83/?source=post_page-----5156e152a608----------------------&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.valentinog.com/blog/context/?source=post_page-----5156e152a608----------------------"&gt;https://www.valentinog.com/blog/context/?source=post_page-----5156e152a608----------------------&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/recursion/?source=post_page-----5156e152a608----------------------"&gt;https://www.geeksforgeeks.org/recursion/?source=post_page-----5156e152a608----------------------&lt;/a&gt;&lt;/p&gt;

</description>
      <category>recursion</category>
      <category>ruby</category>
    </item>
    <item>
      <title>NAtUrE CaN prOgRAM</title>
      <dc:creator>Chet Chopra</dc:creator>
      <pubDate>Sat, 05 Oct 2019 18:25:54 +0000</pubDate>
      <link>https://forem.com/chetchopra/nature-can-program-308a</link>
      <guid>https://forem.com/chetchopra/nature-can-program-308a</guid>
      <description>&lt;p&gt;My hope is that by the end of this you will believe that nature can program. I had originally picked one topic for this post but I quickly realized that I had gone all over the place. So please join me on this directionless journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Solving
&lt;/h2&gt;

&lt;p&gt;There are many different ways to solve the same problem. But let's talk about the problem solving framework or process in an extremely general sense. The framework below demonstrates an indirect problem solving process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N4mk2_le--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AjfP-pQtn1FKicdTv2uwGBg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N4mk2_le--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AjfP-pQtn1FKicdTv2uwGBg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From this we can see that we have a problem, and through analysis we can come up with a representation of a problem. Then, from this representation of a problem we can design a representation of a solution. If we implement then hopefully we will have a working solution!&lt;/p&gt;

&lt;p&gt;This seems like a pretty simple process but it holds a lot of power. Because this is so general and abstract we can mix problems and solutions from different fields of study. One field of study in particular is biology or the natural world.&lt;/p&gt;

&lt;p&gt;“Nature is the most complex system known to man and it contains countless designs in the form of the biological species and environmental phenomena that make our world unique.”- (( Steven A. Korecki, 2008))&lt;/p&gt;

&lt;h2&gt;
  
  
  Biomimicry
&lt;/h2&gt;

&lt;p&gt;“Biomimicry is a maturing science of studying the designs, processes, and phenomena in nature as a source of inspiration for human creations. It acknowledges nature as a model for us to imitate, a measure for us to evaluate our designs, and a mentor from which we can learn.” - ((J. M. Benyus, 2002))&lt;/p&gt;

&lt;p&gt;So in a simpler sense, the core idea behind biomimicry is that nature has already come up so solutions or processes for solving problems. Why not apply them to how we engineer things today.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s look at some examples
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XeH-hZ16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1534/1%2AL8wzb5KvBD569LXRnSfP6Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XeH-hZ16--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1534/1%2AL8wzb5KvBD569LXRnSfP6Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 1989 Japan’s Shinkansen bullet train had a problem. The issue was that it was really fast which is great if you want to get to work on time but bad if you’re coming out of a tunnel. The train would exit the tunnel with a sonic boom which could be heard from 400 meters away. This is bad for dense residential areas. So an engineering team was brought in to design a quieter, faster, and more efficient train. Luckily the general manager of this team, Eiji Nakatsu, was a bird watcher.&lt;/p&gt;

&lt;p&gt;Different components of the redesigned bullet train were modeled after different birds.&lt;/p&gt;

&lt;p&gt;Owls inspired the pantograph, the rig that connects the train to the electric electric wires above. The new pantograph was modelled after their feathers. Using the same serrations and curvature that allows Owls to catch prey quietly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sqOqNy1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1334/1%2ApbqRGyqNUQDDWAZaTc3sxQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sqOqNy1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1334/1%2ApbqRGyqNUQDDWAZaTc3sxQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Adelie Penguin, whose smooth body allows it to swim effortlessly, inspired the pantographs supporting shaft lowering wind resistance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Be-iFoJO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1854/1%2AVJSPUB_Qi5SzqpVeY2W_AA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Be-iFoJO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1854/1%2AVJSPUB_Qi5SzqpVeY2W_AA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The kingfisher, whose unique beak shape allows it to catch prey in the water without a splash, inspired the nose of the new train.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IYIYt3Zh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1490/1%2AENLVkml1ALafgX649mPtLQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IYIYt3Zh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1490/1%2AENLVkml1ALafgX649mPtLQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Sourced from Vox on YouTube.com &lt;a href="https://www.youtube.com/watch?v=iMtXqTmfta0"&gt;https://www.youtube.com/watch?v=iMtXqTmfta0&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;In the end the engineering team had made a train that was 10% faster, used 15% less energy, and stayed under the noise limit in residential areas.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HU11oceQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1632/1%2AUKDnG7ZV7u9GUSgrcm9iyQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HU11oceQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1632/1%2AUKDnG7ZV7u9GUSgrcm9iyQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All information regarding the bullet train was sourced from the Vox Channel&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=iMtXqTmfta0"&gt;https://www.youtube.com/watch?v=iMtXqTmfta0&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How does this relate to programming?
&lt;/h2&gt;

&lt;p&gt;Much like the engineers of the train used nature to solve their problems, we as programmers can do the same.&lt;/p&gt;
&lt;h3&gt;
  
  
  The study of Evolutionary Computing
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--demANI-C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/886/1%2AJ1Zs2GBdq3NwTf6fVWaugQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--demANI-C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/886/1%2AJ1Zs2GBdq3NwTf6fVWaugQ.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Genetic Algorithms
&lt;/h3&gt;

&lt;p&gt;Genetic algorithms mimic the process of natural selection. Which means that those who adapt best to their environment will survive. Aka survival of the fittest.&lt;/p&gt;
&lt;h4&gt;
  
  
  How they work?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Individuals in a population compete for resources and mate&lt;/li&gt;
&lt;li&gt;Those individuals who are successful (fittest) then mate to create more offspring than others&lt;/li&gt;
&lt;li&gt;Genes from “fittest” parent propagate (trickle down) throughout the generation&lt;/li&gt;
&lt;li&gt;Then each successive generation is more suited for their environment&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Genetic Algorithm Example
&lt;/h4&gt;

&lt;p&gt;Let’s say that you’re working in an environment where animals are represented as strings. Let’s call them string animals and the king (fittest) of all strings is the (Representation of the behavior you want to achieve) target = “Puffin”. Each character in the string correlates to a specific trait that that string animal has. Traits can be repeated and the order of the traits matters.&lt;/p&gt;

&lt;p&gt;— — — — — — — — — — — — P→ “ Polite ” — — — — — — — — — — — — — —&lt;br&gt;
— — — — — — — — — — — — U→ “ Understanding ” — — — — — — — — — —&lt;br&gt;
— — — — — — — — — — — — F→ “ Fun ” — — — — — — — — — — — — — —&lt;br&gt;
— — — — — — — — — — — — F→ “ Fun ” — — — — — — — — — — — — — —&lt;br&gt;
— — — — — — — — — — — — I→ “ Intelligence ” — — — — — — — — — — —&lt;br&gt;
— — — — — — — — — — — — N→ “ Nice ” — — — — — — — — — — — — — —&lt;/p&gt;

&lt;p&gt;All of a sudden the environment changes and the fittest string is no longer the Puffin and it is now the target= “Rabbit”. So the rest of the string animals must evolve into Rabbit’s as well. We can use natural selection modeled by a genetic algorithm to do this.&lt;/p&gt;
&lt;h4&gt;
  
  
  Terms
&lt;/h4&gt;

&lt;p&gt;A Population is a group of string animals.&lt;br&gt;
A Chromosome is a string animal.&lt;br&gt;
A Gene is one letter/characteristic of the string animal&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nw7EaAT_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1446/1%2AVvCCXnudf3E9DJMIT5I5dA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nw7EaAT_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1446/1%2AVvCCXnudf3E9DJMIT5I5dA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Selection Operator&lt;/li&gt;
  &lt;p&gt;The fittest (best fitness score) individuals are selected to pass on their genes. So our string animals will get a ranking based on how close they are to matching the exact string of “Rabbit”. The best will be selected.&lt;/p&gt;
  &lt;li&gt;Crossover Operator&lt;/li&gt;
  &lt;p&gt;Mating happens. Two string animals are chosen and chunks, crossover points, or sub-strings are randomly selected. The selected chunks will recombine into a new string animal child.&lt;/p&gt;
  &lt;li&gt;Mutation Operator&lt;/li&gt;
  &lt;p&gt;Random genes are inserted. Nature has randomness. We want this randomness to maintain genetic diversity among all the string animals.
&lt;/p&gt;


&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f7L8J2UV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1448/1%2AyGPWdPhbnAEMMGZFW98fSQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f7L8J2UV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1448/1%2AyGPWdPhbnAEMMGZFW98fSQ.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YCB0LVoo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/788/1%2Ah3cYOrwq1VCENjxJvxy6hQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YCB0LVoo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/788/1%2Ah3cYOrwq1VCENjxJvxy6hQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Algorithm Summary
&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;Randomly initialize population&lt;/li&gt;
  &lt;li&gt;Determine fitness of population&lt;/li&gt;
  &lt;li&gt;Until convergence (isRabbit?) repeat:&lt;/li&gt;
  &lt;ol&gt;
    &lt;li&gt;Select parents from population&lt;/li&gt;
    &lt;li&gt;Crossover and generate new population&lt;/li&gt;
    &lt;li&gt;Perform mutation on new population&lt;/li&gt;
    &lt;li&gt;Calculate fitness for new population&lt;/li&gt;
  &lt;/ol&gt;
&lt;/ol&gt;

&lt;p&gt;You may be thinking “what a stupid way to change a string”. This is true, but we didn’t change the string. We modeled a process that generates a string based on a target.&lt;/p&gt;

&lt;h4&gt;
  
  
  Genetic Algorithm Usage
&lt;/h4&gt;

&lt;p&gt;Copies image to its left&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jpZy13xT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1406/1%2AtIilUkCrEN5ooo2BYWjs_w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jpZy13xT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1406/1%2AtIilUkCrEN5ooo2BYWjs_w.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WzlipMAy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2ATzu3KyynpnyvKX5_gP2Bwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WzlipMAy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2ATzu3KyynpnyvKX5_gP2Bwg.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eNrWbpXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1394/1%2ASYjsL0stjAPY11XVIMBQbQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eNrWbpXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1394/1%2ASYjsL0stjAPY11XVIMBQbQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can watch a video about this project on Cody Husky on YouTube.&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=Q-CDOHkQWBw"&gt;https://www.youtube.com/watch?v=Q-CDOHkQWBw&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is another one where someone used evolution to drive a car in unity&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=FKbarpAlBkw&amp;amp;t=196s"&gt;https://www.youtube.com/watch?v=FKbarpAlBkw&amp;amp;t=196s&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So while nature can’t pick up a computer and start programming. We as programmers can and have taken inspiration from nature to solve problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://scholarworks.gvsu.edu/cistechlib/?utm_source=scholarworks.gvsu.edu%2Fcistechlib%2F44&amp;amp;utm_medium=PDF&amp;amp;utm_campaign=PDFCoverPages"&gt;https://scholarworks.gvsu.edu/cistechlib/?utm_source=scholarworks.gvsu.edu%2Fcistechlib%2F44&amp;amp;utm_medium=PDF&amp;amp;utm_campaign=PDFCoverPages&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/genetic-algorithms/?source=post_page-----cb393da0e67d----------------------"&gt;https://www.geeksforgeeks.org/genetic-algorithms/?source=post_page-----cb393da0e67d----------------------&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://biomimicry.org/?source=post_page-----cb393da0e67d----------------------"&gt;https://biomimicry.org/?source=post_page-----cb393da0e67d----------------------&lt;/a&gt;&lt;/p&gt;

</description>
      <category>biomimicry</category>
      <category>bullettrain</category>
      <category>geneticalgorithm</category>
    </item>
    <item>
      <title>A Brief Intro to Multi-Threaded Programming</title>
      <dc:creator>Chet Chopra</dc:creator>
      <pubDate>Wed, 25 Sep 2019 21:30:04 +0000</pubDate>
      <link>https://forem.com/chetchopra/a-brief-intro-to-multi-threaded-programming-546j</link>
      <guid>https://forem.com/chetchopra/a-brief-intro-to-multi-threaded-programming-546j</guid>
      <description>&lt;p&gt;Of course before we start talking about multithreaded programs we need some background information. Even though there is a lot of background information for this concept, we will only discuss the bare minimum.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Thread?
&lt;/h3&gt;

&lt;p&gt;A thread is a sequential flow of control in a program. So it's essentially a sequence a program instructions that are managed by the scheduler so they can be executed.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a scheduler?
&lt;/h3&gt;

&lt;p&gt;Don't worry about it for now. Just know that it's a part of the operating system. There is a link in the references section if you want to know more.&lt;/p&gt;

&lt;p&gt;Let's say your working on a system with multiple physical cores or multiple virtual cores in a hyper threaded environment. Multi-Threading is a way of telling your operating system that these are the different threads or chunks of instructions that I want to run on my computer. The operating system (scheduler) is responsible for choosing which thread gets time on the CPU cores whether they are physical or virtual. So if you have a single program running on multiple threads that proposes some interesting issues and some very powerful advantages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Issue
&lt;/h3&gt;

&lt;p&gt;Take the same code below for example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bad Multi-Threaded Code
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# include &amp;lt;stdio.h&amp;gt;
# include &amp;lt;stdlib.h&amp;gt;
# include &amp;lt;pthread.h&amp;gt;
# include &amp;lt;unistd.h&amp;gt;
volatile long int a = 0;
void threadOne(void *arg) {
  int i;
  for (i = 1; i &amp;lt; 500000; i++) {
    a = a + i;
  }
}
void threadTwo(void *arg) {
  int i;
  for (i = 500000; i &amp;lt;= 1000000; i++) {
    a = a + i;
  }
}
int main (int argc, char **argv) {
  pthread_t one, two;
  int i;
  pthread_create(&amp;amp;one, NULL, (void*)&amp;amp;threadOne, NULL);
  pthread_create(&amp;amp;two, NULL, (void*)&amp;amp;threadTwo, NULL);
  pthread_join(one, NULL);
  pthread_join(two, NULL);
  printf("%ld\n", a);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;All this program does is add up all of the numbers from 1 to 190009000. But the catch is that it does it using two threads of execution. So one thread will add up the numbers from 1 to 500,000 and the other from 500,000 to 1,000,000.&lt;/p&gt;

&lt;p&gt;Let's run this code multiple times and observe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Run #1 Output - 370752617319
Run #2 Output - 336751282108
Run #3 Output - 250846382315
Run #4 Output - 314774608001
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hmmm… why do we get different answers every time we run this code? In theory, we should get the right answer in half the amount when compared to using a single thread.&lt;/p&gt;

&lt;p&gt;Here is another program that does the same thing but uses only one thread.&lt;/p&gt;

&lt;h3&gt;
  
  
  Single Thread
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# include &amp;lt;stdio.h&amp;gt;
# include &amp;lt;stdlib.h&amp;gt;
# include &amp;lt;unistd.h&amp;gt;
volatile long int a;
int main (int argc, char **argv) {
  int i;
  a = 0;
  for (i = 1; i &amp;lt;= 1000000; i++) {
    a = a + i;
  } 
  printf("%ld\n", a);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As expected we get the same value every time. So what is the multithreaded program doing that makes it produce different incorrect answers?&lt;/p&gt;

&lt;p&gt;Each thread loads the variable A from memory, makes a local copy, adds a value to it, and then stores it back into A. The issue is that both threads are using the global variable A to add up their numbers but they aren't they aren't working in sync. They could both load variable A at the same time add a value to it then store it back into A. Depending on which one stores the value back to A first, one update will be overwritten by the other.&lt;/p&gt;

&lt;p&gt;The solution to this issue would be to synchronize these two threads so that they don't try to operate/access A at the same time. One way to do this would be to use a mutex (mutual exclusion). You can use tokens as an analogy. Let's say that now each thread can only access A if it has the token. This means that if thread one has the token and is working with A, then thread two can not access A and is forced to wait until thread one releases the token.&lt;/p&gt;

&lt;p&gt;Let's look at some code&lt;/p&gt;

&lt;h3&gt;
  
  
  Better but still bad Multi-Threaded Code
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# include &amp;lt;stdio.h&amp;gt;
# include &amp;lt;stdlib.h&amp;gt;
# include &amp;lt;pthread.h&amp;gt;
# include &amp;lt;unistd.h&amp;gt;
pthread_mutex_t a_mutex = PTHREAD_MUTEX_INITIALIZER;
volatile long int a = 0;
void threadOne(void *arg) {
  int i;
for (i = 1; i &amp;lt; 500000; i++) {
    pthread_mutex_lock(&amp;amp;a_mutex);
    a = a + i;
    pthread_mutex_unlock(&amp;amp;a_mutex);
  }
}
void threadTwo(void *arg) {
  int i;
  for (i = 500000; i &amp;lt;= 1000000; i++) {
    pthread_mutex_lock(&amp;amp;a_mutex);
    a = a + i;
    pthread_mutex_unlock(&amp;amp;a_mutex);
  } 
}
int main (int argc, char **argv) {
  pthread_t one, two;
  int i;
  pthread_create(&amp;amp;one, NULL, (void*)&amp;amp;threadOne, NULL);
  pthread_create(&amp;amp;two, NULL, (void*)&amp;amp;threadTwo, NULL);
  pthread_join(one, NULL);
  pthread_join(two, NULL);
  printf("%ld\n", a);
}
Run #1 Output - 500000500000
Run #2 Output - 500000500000
Run #3 Output - 500000500000
Run #4 Output - 500000500000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can see that there are some new lines that lock and unlock the resource from being accessed. Now we get the correct output! But there is still a problem since using threads this way is pointless. It's pointless because while thread one is working with A thread two is forced to wait until thread one releases the resource. In theory this is as slow as using a single thread.&lt;/p&gt;

&lt;p&gt;Time to fix it!&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantage
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Good Multi-Threaded Code
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# include &amp;lt;stdio.h&amp;gt;
# include &amp;lt;stdlib.h&amp;gt;
# include &amp;lt;pthread.h&amp;gt;
# include &amp;lt;unistd.h&amp;gt;
pthread_mutex_t a_mutex = PTHREAD_MUTEX_INITIALIZER;
volatile long int a = 0;
void threadOne(void *arg) {
  int i;
  long int localA = 0;
  for (i = 1; i &amp;lt; 500000; i++) {
    localA = localA + i;
  }
  pthread_mutex_lock(&amp;amp;a_mutex);
  a = a + localA;
  pthread_mutex_unlock(&amp;amp;a_mutex);
}
void threadTwo(void *arg) {
  int i;
  long int localA = 0;
  for (i = 500000; i &amp;lt;= 1000000; i++) {
    localA = localA + i;
  }
  pthread_mutex_lock(&amp;amp;a_mutex);
  a = a + localA;
  pthread_mutex_unlock(&amp;amp;a_mutex);
}
int main (int argc, char **argv) {
  pthread_t one, two;
  int i;
  pthread_create(&amp;amp;one, NULL, (void*)&amp;amp;threadOne, NULL);
  pthread_create(&amp;amp;two, NULL, (void*)&amp;amp;threadTwo, NULL);
  pthread_join(one, NULL);
  pthread_join(two, NULL);
  printf("%ld\n", a);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this code we are using a local variable called localA in each function. We do this so that thread one will add numbers from 1 to 500,000 to its own localA and at the same time thread two is adding numbers from 500,000 to 1,000,000 to its own localA. After one thread is done adding it will lock A, update it, then unlock it so the next thread can use it. So now we have significantly reduced the time one thread waits on the other. In theory this should run twice as fast as opposed to using a single thread.&lt;/p&gt;

&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;p&gt;This blog is based off of a great video on Youtube made by Computerphile&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/7ENFeb-J75k"&gt;https://youtu.be/7ENFeb-J75k&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pdfs.semanticscholar.org/a23b/22fb7bc0286101bdf4794e1e61bcad2fa896.pdf"&gt;https://pdfs.semanticscholar.org/a23b/22fb7bc0286101bdf4794e1e61bcad2fa896.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Scheduling_(computing)"&gt;https://en.wikipedia.org/wiki/Scheduling_(computing)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>c</category>
      <category>multithreading</category>
    </item>
    <item>
      <title>Technology and Medicine</title>
      <dc:creator>Chet Chopra</dc:creator>
      <pubDate>Wed, 25 Sep 2019 21:17:27 +0000</pubDate>
      <link>https://forem.com/chetchopra/technology-and-medicine-2mk8</link>
      <guid>https://forem.com/chetchopra/technology-and-medicine-2mk8</guid>
      <description>&lt;h1&gt;
  
  
  Why
&lt;/h1&gt;

&lt;p&gt;The why here is about why I am choosing to write about this topic. While I feel like this topic has already been pretty well explored. I also feel like many people could benefit from re-exploring how technology has impacted the face of medicine. I hope to give the reader an appreciation for how things have been accelerated and to provide them with hope if needed. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article will adhere to the following format&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increased Outreach / Communication&lt;/li&gt;
&lt;li&gt;3D Printing&lt;/li&gt;
&lt;li&gt;Big Data&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Increased Outreach and Communication
&lt;/h2&gt;

&lt;p&gt;As we all could've all guessed, by how long we've had to wait to see a doctor, they are very busy people. With that being said before technology really came into play in the medical field it was difficult for doctors to easily reach patients and vice versa. Now through the power of the internet and web applications, technologies focused on improving the link in between patients and doctors have emerged. &lt;/p&gt;

&lt;p&gt;In the past one might have had to wait for a letter to come in the mail or a phone call discussing results of tests. With mail the issue is that you have to wait a couple days for it to arrive and with a phone call you can only go into so much detail. &lt;/p&gt;

&lt;p&gt;Now, apps like Medici and SoundCare have removed these barriers and improved the overall communication in between patients and doctors. These apps have allowed secure messaging, appointment requests, lab result sharing, documenting personal information, and even voice communication. This has allowed patients to ask health related questions easily and has let doctors answer those questions in less time than before. &lt;/p&gt;

&lt;p&gt;Besides of the convenience of being able to reach your doctor via an app technology has also increased outreach and communication within the medical community as well. &lt;/p&gt;

&lt;p&gt;Let's play a bit of pretend. You are now a doctor (hooray), and a patient has come in with an issue you just can't seem to diagnose. In the past a doctor may have continued to struggle with diagnosis or just sent the patient home without one. Now, you as a doctor can use medical reference apps such as Epocrates and Medscape to assist with diagnosis. If that also doesn't help you can reach out to a vast community of doctors from all over the world via a forum, blog, or email. Someone somewhere has probably seen something similar and with technology the distance from you and that someone is no longer an issue. &lt;/p&gt;

&lt;h2&gt;
  
  
  3D Printing
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xoU3BC6P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ytimg.com/vi/ipP-z_koTZs/maxresdefault.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xoU3BC6P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ytimg.com/vi/ipP-z_koTZs/maxresdefault.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3D printing has an ever growing number of applications in many industries and the medical industry is no exception. &lt;/p&gt;

&lt;p&gt;Kaiser Permanente's Los Angles Medical Center is perfecting the use of 3D printing to replicate multidimensional models of problematic areas inside patients. Surgeons can handle the models and simulate a variety of possible operation replicas before performing the actual surgery.&lt;/p&gt;

&lt;p&gt;3D printing goes beyond just helping surgeons prepare for surgery, it also helps the handicap-able. A prosthetic hand can cost thousands of dollars; however, a 3D printed prosthesis could be made for as little as $50. 3D printing materials cannot yet replace the long-term durability of traditionally-made prostheses. However, this will soon change. In the meantime, technology is making cost-effective prosthetics a reality and encouraging creative people from all over the world to participate in their design.&lt;/p&gt;

&lt;p&gt;Researchers are also working on the ability to 3D print bones and organs as replacements for people. Research is currently being conducted on artificial heart, kidney, and liver structures, as well as other major organs. Some printed organs are approaching functionality requirements for clinical implementation, and primarily include hollow structures such as the bladder, as well as vascular structures such as urine tubes. So its not there just yet, but we can imagine a future where someone could print you a kidney instead of giving you one of theirs. &lt;/p&gt;

&lt;h2&gt;
  
  
  Big Data
&lt;/h2&gt;

&lt;p&gt;Big data has become bigger and bigger in recent years. It seems that in modern times data is everything, especially in the medical industry. It can help diagnose a patient and also provide more accurate diagnosis based on the data collected. &lt;/p&gt;

&lt;p&gt;IBM research teams say that the same super-computer that won a game of Jeopardy in 2011 is now being used to help physicians make more accurate diagnoses and recommend treatments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.hunimed.eu/news/technology-changing-world-medicine/"&gt;https://www.hunimed.eu/news/technology-changing-world-medicine/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.amputee-coalition.org/3d-printed-prosthetics/"&gt;https://www.amputee-coalition.org/3d-printed-prosthetics/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/Organ_printing"&gt;https://en.wikipedia.org/wiki/Organ_printing&lt;/a&gt;&lt;/p&gt;

</description>
      <category>medicine</category>
    </item>
    <item>
      <title>Be Lazier</title>
      <dc:creator>Chet Chopra</dc:creator>
      <pubDate>Wed, 07 Aug 2019 18:40:05 +0000</pubDate>
      <link>https://forem.com/chetchopra/lazy-loading-488l</link>
      <guid>https://forem.com/chetchopra/lazy-loading-488l</guid>
      <description>&lt;h1&gt;
  
  
  Lazy Loading
&lt;/h1&gt;

&lt;p&gt;Do you want to increase the performance of your applications without compromising on user experience?&lt;/p&gt;

&lt;p&gt;Fast page loads are absolutely critical for web applications. The initial load time of an app effects everything about the users experience.&lt;/p&gt;

&lt;p&gt; - Audience Retention - If they'll stay &lt;br&gt;
 - Audience Conversion - If they'll come back &lt;br&gt;
 - Overall user experience &lt;/p&gt;

&lt;p&gt;Over time users have come to expect an increasingly rich and interactive experience. They want more features, more content, and they want it faster. As developers this means more Javascript, more data sent back and forth, but when we're working with so much more how could we possibly make our application faster. Especially when are devices and network conditions are not the same.&lt;br&gt;
 &lt;br&gt;
So the problem is we want more, faster. But in general if you want to load faster then you simply load less. This is a total contradiction!&lt;br&gt;
While most strategies for speeding up page load include reducing the size of your initial payload this doesn't mean you need to strip features and content from your app. &lt;/p&gt;

&lt;p&gt;You can get pretty far by simply reconsidering what is absolutely critical for the initial load. Do you really need everything all at once to make give the user? Defer the non-critical resources for later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsazhbrwpcrgy8sr0hlrm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsazhbrwpcrgy8sr0hlrm.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fya62okgywbirtsg0fual.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fya62okgywbirtsg0fual.png"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;br&gt;
So instead of having one massive file that you send, try splitting up the resources so that you can deliver them on demand. There are several ways you can do this&lt;/p&gt;

&lt;p&gt; - Code Splitting &lt;br&gt;
 - Lazy Load images and videos &lt;br&gt;
 - Lazy load application data&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Lazy Loading
&lt;/h2&gt;

&lt;p&gt;At this point you can probably guess what lazy loading is all about. But just to reiterate the main idea behind it, Lazy Loading is loading the content as its needed, not all at once. &lt;/p&gt;

&lt;p&gt;Here is a simple example to help solidify the concept.&lt;/p&gt;

&lt;p&gt;Let's say you're visiting reddit/r/cats, and ofcourse there are thousands if not millions of cat pictures / content. If reddit was to try to send you all of these when you first visited the site you'd be waiting quite some time before you could look at all your favorite cats. Instead what reddit does is it only sends you a limited amount of cats when you first load the page, after that more and more cats are brought in as you scroll down. &lt;/p&gt;
&lt;h2&gt;
  
  
  Load on Scroll
&lt;/h2&gt;

&lt;p&gt;This kind of lazy loading works off of an event listener that monitors the scroll bar. When you hit the bottom of the page the event fires thus loading more cats giving the user the feeling of being able to infinitely scroll down the page. &lt;/p&gt;
&lt;h2&gt;
  
  
  Intersection Observers 
&lt;/h2&gt;

&lt;p&gt;We take the idea of only loading what's needed even further by trying to only load what the user is looking at. This behavior can be accomplished by using an intersection observer. For example you can find an Intersection Observer API at here. &lt;/p&gt;

&lt;p&gt;The Intersection Observer API lets code register a callback function that is executed whenever an element they wish to monitor enters or exits the viewport, or when the amount by which the two intersect changes by a requested amount. &lt;/p&gt;

&lt;p&gt;This does mean that you will need placeholders for all of your content and when the viewport intersects with that placeholder then the callback function is fired. In this call back you perform a fetch to quickly retrieve (typically) one resource to populate the placeholder with. In most circumstances it's faster to fetch one resource rather than 10.&lt;br&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  Asynchronous Rendering 
&lt;/h2&gt;

&lt;p&gt;While a component is loading or fetching the rendering of it is suspended. That means that the component will only show up when it's ready. While its not ready a fallback component takes its place. There are multiple ways to achieve this behavior. &lt;/p&gt;

&lt;p&gt;-High Order Components&lt;/p&gt;

&lt;p&gt;React Suspense&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component, lazy, Suspense } from 'react';
import './App.css';;
const MyComp = lazy(() =&amp;gt; import('./components/myComp'));

class App extends Component {
  render() {
    return (
      &amp;lt;div className="App"&amp;gt;
        &amp;lt;header className="App-header"&amp;gt;
          &amp;lt;div&amp;gt;another component&amp;lt;/div&amp;gt;
          &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading.....&amp;lt;/div&amp;gt;}&amp;gt;
            &amp;lt;MyComp /&amp;gt;
          &amp;lt;/Suspense&amp;gt;
        &amp;lt;/header&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

export default function myComp() {
  return &amp;lt;div&amp;gt;Hi there I am now loaded!&amp;lt;/div&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;YouTube Channel&lt;br&gt;
techsith - &lt;a href="https://www.youtube.com/watch?v=tV9gvls8IP8&amp;amp;list=LL-3Wvw55vza7tgX28XooW1Q&amp;amp;index=18&amp;amp;t=288s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=tV9gvls8IP8&amp;amp;list=LL-3Wvw55vza7tgX28XooW1Q&amp;amp;index=18&amp;amp;t=288s&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Geeks for Geeks &lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/what-is-lazy-loading/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/what-is-lazy-loading/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>suspense</category>
      <category>lazyloading</category>
    </item>
  </channel>
</rss>
