<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jagadeesh Kotra</title>
    <description>The latest articles on DEV Community by Jagadeesh Kotra (@jkotra).</description>
    <link>https://dev.to/jkotra</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%2F244403%2Fdfedf42c-89fb-43a6-a500-6b3092ecf3fd.jpg</url>
      <title>DEV Community: Jagadeesh Kotra</title>
      <link>https://dev.to/jkotra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jkotra"/>
    <language>en</language>
    <item>
      <title>Test your LUCK a Million Times(or more)</title>
      <dc:creator>Jagadeesh Kotra</dc:creator>
      <pubDate>Mon, 07 Oct 2019 11:43:25 +0000</pubDate>
      <link>https://dev.to/jkotra/test-your-luck-a-million-times-or-more-29i4</link>
      <guid>https://dev.to/jkotra/test-your-luck-a-million-times-or-more-29i4</guid>
      <description>&lt;p&gt;&lt;em&gt;LuckSimulations&lt;/em&gt; let's you play with well known gaming strategies such as martingale million of times within seconds, powered by Julia.  &lt;/p&gt;

&lt;p&gt;Think you are &lt;em&gt;lucky&lt;/em&gt;? Do you believe &lt;em&gt;'luck favors the bold'&lt;/em&gt;? &lt;strong&gt;Think Again&lt;/strong&gt;, This article will explain how you can you prove to yourself luck is just math - &lt;em&gt;1 roll&lt;/em&gt; or &lt;em&gt;100 million rolls&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aDXT78MX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/jkotra/LuckSimulations/master/luck.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aDXT78MX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/jkotra/LuckSimulations/master/luck.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Intro
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/jkotra/LuckSimulations"&gt;LuckSimulations at GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LuckSimulations is a collection of Julia snippets for rapid testing and experimentation with random-number-based games such as dice, coin flip etc.  &lt;/p&gt;

&lt;p&gt;Simulations such as The infamous &lt;a href="https://en.wikipedia.org/wiki/Monty_Hall_problem"&gt;monty hall problem&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Martingale_(betting_system)"&gt;martingale strategy&lt;/a&gt; in a dice game are available right now. I plan on adding more.&lt;/p&gt;

&lt;h1&gt;
  
  
  Implementation
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;LuckSimulations&lt;/em&gt; completely written in Julia. The reason to choose Julia is obviously, it's as fast as C and easy to write as python. The exact recipe for experiment programs which are often tweaked by users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V3bYlqB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/6/69/Julia_prog_language.svg/1280px-Julia_prog_language.svg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V3bYlqB---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/6/69/Julia_prog_language.svg/1280px-Julia_prog_language.svg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Design
&lt;/h2&gt;

&lt;p&gt;Its a design decision to &lt;em&gt;not&lt;/em&gt; make these functional. These are meant to snippets of code that should be run directly with required arguments directly in Terminal, any further processing(if required) can be done by user by capturing &lt;code&gt;STDOUT&lt;/code&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Monty Hall Problem:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4YF07Jm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Monty_open_door.svg/1920px-Monty_open_door.svg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4YF07Jm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Monty_open_door.svg/1920px-Monty_open_door.svg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://en.wikipedia.org/wiki/Monty_Hall_problem"&gt;Monty Hall problem&lt;/a&gt; is a counter-intuitive statistics puzzle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  There are 3 doors, behind which are two goats and a car.&lt;/li&gt;
&lt;li&gt;  You pick a door (call it door A). You’re hoping for the car of course.&lt;/li&gt;
&lt;li&gt;  Monty Hall, the game show host, examines the other doors (B &amp;amp; C) and opens one with a goat. (If both doors have goats, he picks randomly.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s the game: Do you stick with door A (original guess) or switch to the unopened door? Does it matter?&lt;/p&gt;

&lt;p&gt;Surprisingly, the odds aren’t 50-50. If you switch doors you’ll win 2/3 of the time!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://betterexplained.com/articles/understanding-the-monty-hall-problem/"&gt;[source]&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=TVq2ivVpZgQ"&gt;The Monty Hall Problem (DONG) Video&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://github.com/jkotra/LuckSimulations/blob/master/MontyHall/montyhall.jl"&gt;montyhall.jl&lt;/a&gt;&lt;/p&gt;




&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We start our code by using &lt;code&gt;ArgParse&lt;/code&gt; to parse command line arguments provided by user.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We now store the parsed arguments into variable. Note the &lt;code&gt;n_doors = 3&lt;/code&gt; is part of the problem.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The main loop starts here, &lt;/p&gt;

&lt;p&gt;&lt;code&gt;3&lt;/code&gt; - &lt;code&gt;A array with N values i.e in our case 3 -&amp;gt; [0,0,0]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;6&lt;/code&gt; - &lt;code&gt;A Door is randomly chosen to have money&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;7&lt;/code&gt; - &lt;code&gt;The door with the money values is changed to 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;9&lt;/code&gt; - &lt;code&gt;a door is randomly chosen as chosen_door&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;12&lt;/code&gt; - &lt;code&gt;Switch only happen if --switch arg is passed by user&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;17&lt;/code&gt; - &lt;code&gt;The host chooses to open door that does not contain money (also not the user chosen_door)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;24&lt;/code&gt; - &lt;code&gt;The result is checked and Win/Lose is counted&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;30&lt;/code&gt; - &lt;code&gt;Result of the simulation is printed to STDOUT&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;Here's a small demo how you can test this.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;No Switching&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fD4JGxiQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/jkotra/jkotra.github.io/blob/master/static/noswitch.gif%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fD4JGxiQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/jkotra/jkotra.github.io/blob/master/static/noswitch.gif%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Decide to Switch everytime&lt;/em&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tqgkNxi3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/jkotra/jkotra.github.io/blob/master/static/switch.gif%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tqgkNxi3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/jkotra/jkotra.github.io/blob/master/static/switch.gif%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Martingale Strategy in 🎲 Dice Game
&lt;/h1&gt;

&lt;p&gt;A martingale is any of a class of betting strategies that originated from and were popular in 18th century France. The simplest of these strategies was designed for a game in which the gambler wins the stake if a coin comes up heads and loses it if the coin comes up tails. The strategy had the gambler double the bet after every loss, so that the first win would recover all previous losses plus win a profit equal to the original stake. The martingale strategy has been applied to roulette as well, as the probability of hitting either red or black is close to 50%.&lt;/p&gt;

&lt;p&gt;Since a gambler with infinite wealth will, almost surely, eventually flip heads, the martingale betting strategy was seen as a sure thing by those who advocated it. None of the gamblers possessed infinite wealth, and the exponential growth of the bets would eventually bankrupt "unlucky" gamblers who chose to use the martingale. The gambler usually wins a small net reward, thus appearing to have a sound strategy. However, the gambler's expected value does indeed remain zero (or less than zero) because the small probability that the gambler will suffer a catastrophic loss exactly balances with the expected gain. (In a casino, the expected value is negative, due to the house's edge.) The likelihood of catastrophic loss may not even be very small. The bet size rises exponentially. This, combined with the fact that strings of consecutive losses actually occur more often than common intuition suggests, can bankrupt a gambler quickly. &lt;/p&gt;

&lt;p&gt;[Source- Wiki]&lt;/p&gt;




&lt;p&gt;&lt;a href="https://github.com/jkotra/LuckSimulations/blob/master/Dice/martingale.jl"&gt;martingale.jl&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Take a look at code, it should be easy to figure it out 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;julia martingale.jl --bank 1 --stake 0.00000010 --rolls 10000000 --multiplier 2 --report-freq 10000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J_zVXt_6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/jkotra/jkotra.github.io/blob/master/static/mart.gif%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J_zVXt_6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://github.com/jkotra/jkotra.github.io/blob/master/static/mart.gif%3Fraw%3Dtrue" alt=""&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Hope you like this small project, Contributions are very welcome, Please open PR/Issue's.&lt;/p&gt;

</description>
      <category>julia</category>
      <category>simulation</category>
      <category>random</category>
    </item>
  </channel>
</rss>
