<?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 Zachary Paine Sabin on Medium]]></title>
        <description><![CDATA[Stories by Zachary Paine Sabin on Medium]]></description>
        <link>https://medium.com/@zacharysabin?source=rss-f37ab9c8632f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iyC3LvlTYK6GcqUy.</url>
            <title>Stories by Zachary Paine Sabin on Medium</title>
            <link>https://medium.com/@zacharysabin?source=rss-f37ab9c8632f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:06:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zacharysabin/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[Full Stack Door Buzzer]]></title>
            <link>https://medium.com/@zacharysabin/full-stack-door-buzzer-26f355274024?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/26f355274024</guid>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Wed, 08 May 2019 16:32:49 GMT</pubDate>
            <atom:updated>2019-05-08T17:39:13.999Z</atom:updated>
            <content:encoded><![CDATA[<p>Winter in Seattle is a cold and rainy season. And there’s nothing worse than walking back from frisbee or the gym and realizing that your keys are buried inside a messy bag and you have to dig them out in the cold, or, even worse, discovering that you don’t have them at all. So I’ve been hunting for a way to get into our building without needing my keys.</p><p>Luckily, our building has an old (although I suspect it was cutting edge at the time) buzzer system, where you can push a button at the front door and a dedicated phone rings in the apartment you selected. You can then chat via the intercom and, if you’re charming enough, the person in the apartment can push a button on the phone to buzz you in. Which means that the wiring was already in place to unlock the door electronically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*LmvHFu1_XHs8-L5s" /><figcaption>Early draft of the system, you can see how simple the switch wiring was</figcaption></figure><p><strong>Hardware</strong></p><p>The first step was to dismantle the system in our apartment to see what the options were. The age of the system was very much in my advantage here, since it came apart easily and was spacious on the inside (as opposed to modern electronics which are typically hard to dismantle and very compact). It turned out the buzzer button was simply a pressing a long metal strip into a small nub — connecting a circuit and causing the door to unlock. All that was needed to automate the process was to create a system that allowed a computer to complete that circuit without the button being physically pushed.</p><p>After mucking about with transistors for a while to no success, I ended up using a relay. A relay is is a small electrical device consisting of a switch and a separate wire. When current is running through the wire, the switch goes to one position, and when the wire is dead the switch is in the other one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*rQX4fhIMhEat-x_kHXJVLA.png" /><figcaption>From the datasheet for the relay I am currently using</figcaption></figure><p>Essentially, I simply replaced the button with the relay’s switch, and when the computer runs current through the wire in the relay it connects the switch, buzzing the door.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*-YwFFPRotXUR4y54" /><figcaption>Holes drilled and wires cleaned up. Note that I didn’t solder inside the phone, that seemed excessively risky.</figcaption></figure><p>The reason for using this relay is that the Raspberry Pi (and most computers in general) doesn’t have a way to say “if this conditions are met, complete this circuit”. The only way to interface with the outside world is to send current out of a number of wires, often called “logic pins”. For this use case, the code essentially says “when the link to open the door is visited, output a current onto logic pin 21 for 3 seconds”. That current flowing through the logic pin flips the switch in the relay for those three seconds, causing the door to be connected.</p><p>After some testing with an Arduino (and really hoping my neighbors didn’t get annoyed by the door buzzer going off repeatedly for a few minutes) I had the relay set up to trigger the buzzer when the current from the logic pin was on. Once I was sure the circuit wouldn’t explode the computer, I switched to using the Raspberry Pi (since an Arduino can’t host a web server as easily).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*VO9N27MP5lmTgp3k" /><figcaption>Final product. I think it looks kind of neat!</figcaption></figure><p><strong>Software</strong></p><p>Now that the buzzer could be controlled by the logic pins from the Pi, all that was left was to to write some software. Luckily I’m a “professional”, so this part was more straightforward (and bore less of a risk of neighbor’s rage).</p><p>I knew ahead of time that my goal was to have a unique link that I could visit from my phone and that would trigger the door to open. This would allow me to open my door with a single shortcut, since Chrome on Android allows you “pin” links to your home page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Io_zP8zTj2EwpnUPYURZ8w.png" /><figcaption>The simplest possible interface</figcaption></figure><p>The easiest way to do that (as far as I know) is to run a webserver on the Raspberry Pi and have a URL point to a script that turns on the logic pin. That does require opening up a port on your home router to the public internet, so you should avoid common ports (80 and 443, maybe 8000 as well?). Additionally, I wanted the URL to be long and randomized, to reduce the chance of getting visited by somebody randomly guessing URLs. So I ended up opening a random port (which I won’t publish here) and a 32 character long random string as the URL. <em>(A port, by the way, is literally just an arbitrary number that allows a computer to run multiple websites at once. Often websites are run on ports 80 or 443 by convention)</em></p><p>I thought this was great until I sent the link to someone via FB messenger and my LED suddenly lit up, indicating someone was opening the door. It turns out Facebook visits all links sent via Messenger to generate a preview. I also discovered that iPhones visit bookmarks occasionally (presumably to update a cache?), so it was clear that just visiting a link would be a bad strategy if I didn’t want the door to open arbitrarily a few times a day.</p><p>But, I really didn’t want to have to type a passcode or verify my location in order to open the door, so I took the laziest route and simply added a confirmation dialog to the open door script. Now when you visit the “open door” URL it pops a dialog asking you to confirm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lMJyVakZuw3m1QVyyyFDuQ.png" /><figcaption>Final product</figcaption></figure><p>After some testing, that appeared to solve the problem of previews / caches following the link. However I was still worried about using the same link for too long, and I also wanted to be able to log who was opening the door, not just when the door was opened. I won’t get into the details here, but I ended up writing a simple build script that takes in a config file and a list of usernames / email addresses, and generates a unique link for each user (and emails it to that user’s email address so they can actually know the link). You can check out all the code on my <a href="https://github.com/zpaines/Doorbell">github here!</a></p><p>Currently there are only two users (myself and Sarah), but in the long term I would like to add more granularity over users so that we can add certain users with the restriction that they can only enter during specific times, or perhaps add one time codes (e.g. for a party). I would also like to be able to use this for package deliveries (currently they often end up needing to be picked up since the delivery person can’t enter the building), although I suspect shipping companies frown on their employees visiting random links from customers.</p><p>I’d love to hear comments on this (particularly anything around the security of this setup) so please send me an email or leave a comment on the post! And if you want to use the github code for your own door buzzer authentication scheme let me know and I would love to help!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26f355274024" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Most Common Technical Interview Mistakes]]></title>
            <link>https://medium.com/@zacharysabin/5-most-common-technical-interview-mistakes-8d227dc36369?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d227dc36369</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Tue, 04 Dec 2018 13:08:02 GMT</pubDate>
            <atom:updated>2018-12-05T19:16:46.648Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve given 50+ phone screens in the past year and a half, and there are similar patterns in many of the interviews that fail. As someone who’s been nervous on the other side of the phone, I thought I would write up a few of the most frequent reasons people fail to get a question, and how to correct them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*ZpBDYWbi8ICxW-V_.jpg" /><figcaption>Source: <a href="http://www.commitstrip.com/en/2015/05/20/coder-interview/">http://www.commitstrip.com/en/2015/05/20/coder-interview/</a>?</figcaption></figure><p><strong>(1) Assuming the question has a fancy silver bullet.</strong></p><p>When you’re interviewing for a generalist position at a software company, it’s pretty unlikely that their phone screen is going to require you to know what a Bloom filter is (although they are quite cool) and how to use it. And yet candidates consistently scrap OK solutions that aren’t quite optimized and start diving into crazy tangents. Just like in an actual programming job, save the complex and specialized data structures for situations where their usage is clear. There’s a reason why we’re all still using <a href="https://en.wikipedia.org/wiki/Array_data_structure#History">arrays (and merge sort) 70+ years later</a>.</p><p><em>How to fix: use standard algorithms and data structures as building blocks.</em></p><p><strong>(2) Ignoring interviewer hints and suggestions.</strong></p><p>This one can manifest itself in a couple ways. The most egregious is when the interviewer makes a fairly clear hint such as “what if we used a stack instead of a tree?”, and the suggestion is either ignored or dismissed out of hand. As an interviewer, I’m trying to help you! There is no situation in which people will intentionally mislead you. When the interviewer makes an explicit suggestion, they are either trying to guide you along the right path or trying to have you prove that your current solution is optimal (in which case you’ll probably already know that your current solution is a good one). Regardless of which they are doing, just ignoring the hint won’t do you any good.</p><p>Occasionally candidates will take the hint, spend a little bit of time trying to work it into their solution, and then cast it aside and return to whatever wasn’t working before (or onto a new thing). If someone gives you a suggestion and you don’t think it works that’s fine, but you should have a clear explanation for why an alternative solution is better than the one suggested to you. Remember, we’re trying to help you get the right solution and we have the answer key, so it’s likely that our suggestions are going to be helpful (not to say that people don’t occasionally come up with great solutions that aren’t in the answer key).</p><p><em>How to fix: give any input from your interviewer strong consideration.</em></p><p><strong>(3) Forcing a square peg into a round hole.</strong></p><p>This ties into the one above, but candidates will frequently pick a solution early on and tack on enhancements for every problem that it has. If your answer doesn’t feel like a clean fit for the problem, then there is most likely a flaw with the foundation of your solution, not the wallpaper. Don’t be afraid to scrap your current solution (especially if you can articulate why it’s bad) and pick a new one. The right answer is usually also a fast one, so don’t worry about time constraints on that front.</p><p><em>How to fix: don’t be afraid to scrap a solution and try out something new.</em></p><p><strong>(4) Diving too far into details right away.</strong></p><p>This one doesn’t sink candidates immediately, but it hurts them in two ways. First, once they’ve described a solution in great detail they get invested and don’t want to change it, leading to problem <strong>(3). </strong>The bigger issue, though, is that it takes more time for the interviewer to figure out that it is a wrong solution. Interviewers will typically direct you away from wrong solutions and towards correct ones, so the faster they understand your solution the faster they can put you on the right track. Since interviews are time limited, it’s better to give a wrong solution in 30 seconds than in 5 minutes. And if the solution you gave is correct, or close to it, the interviewer can always prompt you for more detail.</p><p><em>How to fix: get it wrong or right quickly, then iterate from there.</em></p><p><strong>(5) Filling the silence at all times.</strong></p><p>I blame bad advice from college “how to pass a technical interview” seminars and online advice columns for this one. It is important to let your interviewer know what you’re thinking, but just rambling is bad. The same way none of us sit down at a computer and start coding instantly when presented with a problem, it’s OK to not start talking right away when presented with an interview question. Just saying something like “just let me think for a second” is perfectly fine and can give you 30 seconds or a minute to concentrate. For the reasons discussed in <strong>(4)</strong>,<strong> </strong>don’t take too long, but 1 minute of silence followed by a correct answer is a lot better than 2 minutes of talking but no good answer. A brief silence also allows candidates to gather their thoughts and then present a coherent answer, which is definitely preferable to a jumbled answer.</p><p><em>How to fix: still communicate your thoughts, but don’t be afraid to organize them first.</em></p><p>Most of the candidates I interview clearly have enough knowledge to get our questions right, but nervousness or an unfamiliarity with how to present their thinking during an interview cause them to perform poorly. I think that by combining the tips in this article with a strong knowledge of CS fundamentals, you can pass the vast majority of technical phone screens.</p><p><em>If you’re interested in working at a company that prioritizes practical skills and critical thinking over trivia, check out </em><a href="https://jobs.lever.co/everlaw"><em>Everlaw’s job page</em></a><em> and shoot me an email.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d227dc36369" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fist Bump: The Social Network For Your Office]]></title>
            <link>https://medium.com/@zacharysabin/fist-bump-the-social-network-for-your-office-614b85628084?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/614b85628084</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[culture]]></category>
            <category><![CDATA[legaltech]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Fri, 26 Oct 2018 23:19:22 GMT</pubDate>
            <atom:updated>2018-11-02T20:14:07.120Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first interviewed at <a href="https://www.everlaw.com/Careers.html">Everlaw</a>, there were 22 employees (6 of whom had won USAU Nationals). By the time I started (1 year later), there were 33 employees. Now, 2 years after I started, we are pushing 100 employees and accelerating.</p><p>One of the best things about Everlaw, and what attracted me to working there in the first place, was the fantastic company culture. We emphasize growth, respect, and fun. Board games, team lunches, and escape rooms help everyone get to know each other and realize what makes their colleagues particularly qualified and capable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fVqDosWiH2vNSblV.jpg" /><figcaption>Playing video games in the early days (pre-author)</figcaption></figure><p>But amidst rapid growth that closeness and camaraderie can disappear. How can you get to know everyone when we have 9 people start in a week? And when teams grow to 10x their original size, it becomes difficult to get any insight into what is going on inside them. Fist Bump is an attempt at solving these problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rVolzBd0umN22ROF6iIDEA.png" /><figcaption>The hypothetical Star Wars office</figcaption></figure><p>Being located on the <a href="https://www.bizjournals.com/sanfrancisco/news/2018/10/23/startups-move-oakland-everlaw.html">same side of the Bay</a> as the Warriors, we know a little bit about winning sports teams. One thing that <a href="https://www.youtube.com/watch?v=-R9qyWEJuDI">great teams do</a> is high five each other, a lot. And since we already have some <a href="https://www.everlaw.com/Careers.html">great athletes</a> in the office, and we would like to think of ourselves as the Golden State Warriors of the legal tech world, we wanted to translate that into the office.</p><p>So in the spirit of Silicon Valley, we took a face to face interaction and moved it into the cloud. We call it Fist Bump (high fives are like on-premise discovery solutions: so 2008), and it is essentially a social network for the office. Its main feature is a feed of “fist bumps” that colleagues have sent to each other, as well as the ability to send your own “bumps”. You can bump a single colleague, a set of them, or even an entire team! The site also allows you to create your own bio with a profile picture and answers to a set of fun and informative questions. The goal is to create a fun space where people can appreciate each other, be goofy, and learn about what their colleagues are working on.</p><p>Overall it’s been a great success. We have sent over 5500 bumps, and people have commented over 700 times on those bumps! We’ve continued to improve it to try and encourage people to use the platform more, including introducing gif support (400 gifs have been sent) and building a visualization that maps connections between coworkers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/0*drnqdCxqcToYiSl0" /><figcaption>Different colors represent different teams. So you can see that sales and engineering don’t interact much.</figcaption></figure><p>The site was developed fully in-house, and it’s built using the Django web framework. It’s hosted on an EC2 micro instance, so it costs pennies per month to maintain. A major benefit of in-house development is that we can fully customize it to match our company culture. For example, we have a set of <a href="https://blog.everlaw.com/2015/10/21/values-recognition-program/">culture tokens</a> that get passed around to people who exemplify certain aspects of our company culture. Although we haven’t scrapped the physical tokens, we added a token feature to Fist Bump so that people can see who has each token at any given time. We’ve also been <a href="https://blog.everlaw.com/2018/06/28/everlaw-raises-series-b-investment/">growing quickly</a>, and it was becoming difficult to keep up with all of our new hires! We used to use a Google Doc as a company directory, but it became unwieldy as we surpassed a head count of 70. So Fist Bump now has a company directory, where you can quickly peruse people’s pictures and a set of questions and answers. You can also view any bumps they’ve been a part of, which can hopefully give you a bit of insight into what they’ve been working on.</p><p>On top of adding features that we think promote good company culture, we avoid adding ones that detract from it. For example, we’ve avoided any kind of “Most Bumps Received” feature, or any way to sort people based on their stats on the site. We want to avoid creating any competition around the site, the same way that NBA players shouldn’t be competing to give the most high fives in a game.</p><p>As we’ve expanded and begun to approach the magical <a href="https://en.wikipedia.org/wiki/Dunbar%27s_number">Dunbar’s number</a>, Fist Bump has helped preserve some of the best aspects of startup culture. For our newest employees, they can learn what people look like and what Harry Potter house they belong to even if they haven’t met everyone. People can match the appropriate gif to a successful sales call, and debate the pronunciation of GIF (here at Everlaw, we pronounce it “híf”) in the comments. And if anyone wants a quick update on what’s going on outside of their team’s bubble, all they have to do is browse down the Fist Bump feed.</p><p><strong>Technical Thoughts</strong></p><p>Fist Bump is by far the most fleshed out product I’ve built from scratch, and it was fun to make all the decisions (and stressful). I so far haven’t made any terrible ones, but the volume of usage and the scale of the site are quite low.</p><p>For a DB I’m currently using SQLite. It works fine for the scale of transactions that Fist Bump handles, and the db file is only 2.5 MB at the moment. It has some major benefits as well. The fact that db is just a single file means that it’s easy to back up, and easy to transfer around between instances. It is also incredibly easy to set up a new database (basically you just have to make sure SQLite is installed) which was important for me since I wanted other devs to contribute to the code base, which means local instance setup has to be easy.</p><p>The site itself is built in Django. I like Django, and it abstracts away a lot of the messiness of dealing with request routing, storing / querying objects in the DB, and managing user accounts. It also comes with the Django admin console, which is a massive time saver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1KhebxKyZNuC6cILZhAxaw.png" /><figcaption>An admin can change DB objects without any command line necessary</figcaption></figure><p>When you create the app, Django builds a full web site for managing the objects in the DB. The UI for each object is created based on the data type you assign to the table / column, and it automatically populates Foreign Keys as dropdowns (in the example above, the team field is a key into the Team table). This is a massive time saver for the engineering team, since it allows non technical employees (e.g. Ian, our VP of Operations) to administer the site without any intervention from devs.</p><p>However if you want to do something that is not within the design philosophy of Django, it can end up being quite messy. So far it hasn’t been too bad, although static asset management is beginning to crop up as an issue.</p><p>Django encourages you to include static assets with static tags. If you include these in the HTML template the the server fills out and sends to the client, Django will automatically fill out the tag with the URL of the static asset. Unfortunately this is not compatible with ES6 import tags (since those import static files within a different static file) so you can’t use those tags very effectively if you want to use modern Javascript imports.</p><p>This compounds if you want to use Django’s version management. This generally modifies the name of the static file to reflect the content of the file. If the content changes, the filename (and the URL inserted into static tags) change as well. But there’s no way to automatically update the filenames in import tags. I still haven’t settled on the best solution for static asset versioning in Fist Bump yet, so please let me know if you have a good idea!</p><p><strong>Final Notes</strong></p><p>Fist Bump has sort of been a side project, although I have spent a good number of hours working on it during the workday (and a good number working on it outside of that as well). Everlaw doesn’t have a 20% policy a la Google, but employees are encouraged to work on stuff to improve the company, even if it’s outside the scope of their current major feature.</p><p>If Everlaw sounds great to you (it is), let me know and I can refer you to work here! Check out our <a href="https://jobs.lever.co/everlaw">current jobs</a> and reach out.</p><p>Shoutout to <a href="https://medium.com/u/db33ce84bf49">bryant 🌊🔥</a>for doing the initial design work on Fist Bump, I’ve followed the design framework and philosophy he laid out as the site expanded.</p><p>There’s a possibility Fist Bump will be open sourced and made public, so let me know if it’s something you want for your workplace (or personal use!).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=614b85628084" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flood Insurance: The Biggest Bubble You’ve Never Heard Of]]></title>
            <link>https://medium.com/@zacharysabin/flood-insurance-the-biggest-bubble-youve-never-heard-of-5b9f14430dd0?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b9f14430dd0</guid>
            <category><![CDATA[flooding]]></category>
            <category><![CDATA[climate-change]]></category>
            <category><![CDATA[economics]]></category>
            <category><![CDATA[hurricane-florence]]></category>
            <category><![CDATA[politics]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Wed, 12 Sep 2018 23:47:21 GMT</pubDate>
            <atom:updated>2018-09-13T23:28:48.073Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Our system for helping flooded homeowners is underwater, and sinking quickly.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A8-wozCdMCr3A5Zb.jpeg" /></figure><p>With Hurricane Florence bearing down on the East Coast, homeowners are double checking their flood insurance paper work and preparing to file claims. If they’re smart they’ll be moving valuables out of the basement (damage in basements is not included as part of the $100,000 “contents” coverage) and digging receipts for their larger purchases out of filing cabinets. Luckily for them, the federal government requires homeowners in high risk flood areas to have insurance, and encourages owners in flood prone areas to have it as well.</p><p>Unluckily for these homeowners, they’ve decided to live in areas of the country so prone to flooding that private insurers have deemed them “uninsurable”. But in its immortal wisdom, the US government stepped in in 1968 and created the NFIP (National Flood Insurance Program), a taxpayer subsidized insurance program that allows for people to live in flood prone areas without risking financial ruin. The program is widely used, thanks in part to a mandate forcing those in high risk flood zones (Special Flood Hazard Area, or SFHA) to purchase it, and is now one of the largest financial obligations of the US government. The total coverage in 2016 was about $1.25 trillion for about 5 million households. On top of insurance, the NFIP also maps flood zones and risk, as well as attempting to incentivize better floodplain management.</p><p>So that sounds pretty good right? On its face, the NFIP is government doing what it should be in America: identifying a group of people being failed by private industry and stepping it to provide a solution. Similar to how Obamacare allowed people with chronic health issues to get health insurance, the NFIP allows high risk homeowners to get insurance that they wouldn’t be able to otherwise.</p><p>But there are a litany of issues with the NFIP, from broken incentives to outdated technology to poor enforcement. We’ll go through them in the next few paragraphs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bnd2OzqeonocC98_B_S82g.png" /></figure><p>The first, and perhaps the most blood boiling one, is known as “repetitive loss properties”. As you may have guessed from the name, these are properties that flood frequently and receive payouts each time. Since 1978, repetitive loss properties have accounted for 25% of payouts. In 2013 these properties accounted for only 1.3% of premiums but were expected to account for 15–20% of payouts going forward. For many types of insurance that’s not unreasonable —you would expect a small percentage of people to account for the majority of expenditures in health insurance since only a small number of people get very sick, most of us just get yearly checkups — but flood insurance is different.</p><p>For one, only high risk properties get flood insurance! Contrast this with health or car insurance where everyone has a policy. Even within high risk areas, we can identify tiers of risk and estimate which houses are the most likely to get severely flooded. Also, people can move. There is no inherent right to live on the Louisiana or Florida coasts. But the incentive structure of the NFIP does the opposite of what it should. It’s far easier to get money to rebuild a house destroyed by a flood than it is to get money to help you move. This inverted incentive structure is furthered by the fact that premiums are fixed by policy, and do not take into account past events. So your home can flood every year, but the NFIP can never raise your premiums. Imagine if that were the case for car insurance!</p><p>The NFIP also grandfathers in older homes, essentially fixing people’s insurance policies to reflect the year they were granted, rather than modern laws and flood science. While the NFIP currently includes many incentives to make homes less flood prone — for example by raising their base level above the expected height of flood water — older homes are exempt from these requirements, and simply pay their old (and lower) premiums regardless. This also creates a perverse incentive to never move and simply rebuild a home each time it is flooded as long as you continuously carry the flood insurance on it.</p><p>So despite the fact that a small percentage of policy holders account for a large plurality of payouts, the NFIP does not incentivize these policy holders to change their behavior in any way. In fact it flips the incentives and encourages them to stay put.</p><p>The NFIP has another major flaw to do with how it quantifies and discloses flood risk. I’ve already mentioned the SFHA (Special Flood Hazard Area) which is supposed to create a map of areas subject to 100 year floods (aka a 1% chance of flooding each year). Anyone within this line is required to carry flood insurance, it is available but not required to those outside of it. Additionally, sellers must disclose to home buyers that a home is located within the SFHA. However, these creates a binary risk profile for a phenomenon that is decidedly on a sliding scale.</p><p>A home immediately outside of the SFHA may have a .99% chance of flooding each year, but there is no requirement for the seller to disclose the flood risk to the buyer, and no requirement for the homeowner to carry flood insurance. And if a home has no flood insurance, the money to rebuild after a natural disaster often comes from taxpayer funded disaster relief funds, even worse than NIFP funds since the beneficiary of the money never paid any premiums.</p><p>On top of the false SFHA dichotomy created by NIFP, the way that premiums are calculated ignores modern techniques and groups homes in an inaccurate way. Premiums are set on a per community basis (the exact methodology is difficult to uncover, I only found one link to a book that cost $50), grouping large swaths of homes into the same calculation of flood risk. There are far more accurate ways of measuring this flood risk on a home by home basis using satellite data, but the NFIP does not set risk on a specific basis. Essentially this subsidizes the riskiest homes in a swatch and charges the least risky home extra.</p><p>There is also little enforcement of the SFHA mandate. The mortgage lender is supposed to ensure that homeowners in the flood zone have insurance, but actual coverage is spotty. Many homeowners in high risk areas do not continuously carry the insurance, and will require disaster relief funds when a storm hits their area. These funds are fully taxpayer funded.</p><p>After all that, or perhaps because of it, it is often hard to get the NFIP to pay out on a claim, no matter how legitimate. This <a href="https://www.nytimes.com/2017/11/04/business/a-broke-and-broken-flood-insurance-program.html">New York Times piece</a> outlines how difficult homeowners found getting paid after filing claims to be. And if the NFIP fails to pay out, homeowners are left to sue the government and taxpayers are left to foot the legal bill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*WcB0UA3MxcH1i7rqBhe5EQ.png" /><figcaption>NFIP debt over the years</figcaption></figure><p>It’s perhaps unsurprising that the NFIP is deeply in debt. Of course it was never designed to break even, as it is intended to subsidize these plans, but it has recently done far worse than expected. This is mostly attributable to super damaging storms that have each cost massive amounts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lh9PFL5q58NfjOq4v5eB1w.png" /></figure><p>And that brings us to the biggest problem with the NFIP, one that makes the previous issues all the more urgent. Climate Change! As ocean levels rise and waters warm, storms will only get more massive and damaging. Notice how 1978–2004 did not have a single massively damaging storm, but the subsequent ten years had three (and we’ve had at least two since 2012, with Florence possibly being another one). These storms will continue to grow as a threat to persons and property. But the NFIP, at least right now, is not doing anything to address this. In fact, perversely, development in high risk coastal areas is at an all time high, only possible because of the heavy subsidies and distribution of risk that the NFIP provides.</p><p>So why is flood insurance a bubble? Well it has many similar properties to the 2008 financial crisis. You have a government program meant to encourage home ownership in a risky fashion (subsidized flood insurance vs. encouragement to give risky borrowers mortgages) which leads to expansion in that area (lots of construction in risky flood areas vs. massive number of variable rate mortgages on inflated home values). Finally, the fact that that expansion was economically untenable asserts itself and the bubble pops. In 2008 it was a confluence of variable rate mortgages kicking up to a higher interest level and falling home prices (meaning people couldn’t refinance). In the case of the NFIP, it will be climate change suddenly causing both the number and the severity of claims to skyrocket.</p><p>Continuing to subsidize people living in these high risk areas is completely irrational, and it becomes less defensible every day that passes and every millimeter that ocean waters rise. When this bubble pops it will cost more than money. Every person whom the government encourages to live and stay in a high risk coastal area is someone who is at risk of dying in a climate change fueled storm.</p><p>We need to stop incentivizing coastal construction, living, and rebuilding. Instead, we should be subsidizing people to leave these areas and move to areas less prone to flooding and storm damage. Those that want to remain should be paying market rate for their insurance, rather than having their lifestyle funded by the rest of us.</p><p><strong>Sources / Further Reading:</strong></p><p><a href="https://www.ucsusa.org/global_warming/science_and_impacts/impacts/flood-insurance-sea-level-rise.html">Overwhelming Risk: Rethinking Flood Insurance in a World of Rising Seas</a><br><em>A very thorough and interesting examination of the history and risk associated with the NFIP, as well as specific case studies of areas affected by floods.</em></p><p><a href="https://www.nytimes.com/2017/11/04/business/a-broke-and-broken-flood-insurance-program.html">A Broke, and Broken, Flood Insurance Program</a><br><em>New York Times opinion piece about the NFIP in the aftermath of Hurricane Sandy.</em></p><p><a href="http://www.rff.org/files/document/file/RFF-PB-17-01.pdf">A Discussion of the National Flood Insurance Program</a><br><em>A Wharton presentation talking about many of the issues with the NFIP</em></p><p><a href="https://www.rpc.senate.gov/policy-papers/flood-insurance-reauthorization">FLOOD INSURANCE REAUTHORIZATION</a><br><em>A policy paper put out by the Republican party discussing their proposal to reauthorize and fund the NFIP after it expired in 2017</em></p><p><a href="https://www.youtube.com/watch?v=pf1t7cs9dkc">John Oliver: Floods</a><br><em>This discusses a wider array of flooding problems in the US as well as the NFIP, along with that classic John Oliver humor.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b9f14430dd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Win Credit Card Roulette]]></title>
            <link>https://medium.com/@zacharysabin/how-to-win-credit-card-roulette-759ffb64a9b6?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/759ffb64a9b6</guid>
            <category><![CDATA[payments]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[game-theory]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[credit-cards]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Thu, 02 Aug 2018 18:04:05 GMT</pubDate>
            <atom:updated>2018-08-02T22:22:25.037Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: All graphs are for a bill of 50 people, each with a $20 share</em></p><p>Picture this: 20 people at a brewery, each ordering an entree, a couple beers, maybe even some fries to split. Eventually the bill comes. How do you split it up? You could have everyone go through it, figure out what they ordered, what % of the shared fries they’re responsible for, and what percent to tack on top of that to take care of tax and tip.</p><p>Or you could put everyone’s credit card into a hat and pick one poor sucker to pay for it all. That is the essence of credit card roulette, or CCR.</p><p>The way that it’s typically played is that everyone puts a credit card into a hat, and then cards are pulled out one at a time until only one remains. That card has to pay for the meal. One additional rule, which makes the game a little more interesting, is that those who don’t want to participate can be “bought” out by somebody. What that means is that in return for $20 (or whatever their share of the bill is), I put an extra card of mine in the hat instead of theirs. That way they just have to pay for their own bill, and I have a chance of actually making money if I don’t end up having to pay the whole check.</p><p>It’s fairly obvious that if everyone’s contribution to the bill is equal, then the expected value of playing CCR is the same as just paying your own bill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*gF5NCcUyrAIktLW4.png" /></figure><p>And, of course, no matter how many people you buy out, that won’t ever change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/0*owsuZIMd8AJtCv2A.png" /></figure><p>But expected value doesn’t tell the whole story. Intuitively, you might think that buying out increases your risk. After all, you are putting more cards into the mix, which means you have a higher chance of losing. But all those losses are somewhat mitigated by the guaranteed payout from the people you are buying out! The safest move in CCR, in fact, is to buy out everybody, which guarantees that you only pay for own meal. So depending on your appetite for risk, you can select how many people to buy out. Also note that by participating, you are basically buying out yourself (since you make $20 or whatever in the form of your food).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fcO1va-l50X9qHx_vYPJxw.png" /><figcaption>Variance for the number of cards you have in the hat</figcaption></figure><p>You can see in the graph above that the “riskiest” move, the one with the highest variance, is to buy out half the people. That means you have a 50% chance of losing half the check and a 50% chance of winning half the check. Also note that buying out everybody is the same as not playing.</p><p>You might also consider whether you care more about losing a lot and winning a little, or losing a little and winning a lot. The more people that you buy out, the less money you stand to lose and the more you stand to gain (until you’ve bought out everyone, at which point you can’t make money). You could even win the entire cost of the check, minus one person’s bill!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uDYgmE7o0tlB494fCKwiMQ.png" /><figcaption>How much you could lose or win for every person you buy out on a 50 person check of $20 each</figcaption></figure><p>The far right of that graph sure looks good, doesn’t it? But bear in mind you have an extremely high chance of losing a little money in that case. Since all strategies have an equal expected value, which one you choose in this case is really just a question of how loss averse you are. Frankly, looking at that graph makes me want to start buying people out more. It seems more fun to occasionally win $480 at the cost of frequently paying $20 then it does to avoid paying $20 at the occasional cost of $480.</p><p>However, there is a situation where CCR’s expected value is not level! Rarely are peoples’ actual shares of the bill equivalent, and in those cases, the people who spend more have a better expected value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdJaTR02sizEhZsVXXga9g.png" /><figcaption>Expected value of participating in CCR for bills from $0-100, assuming 49 other people spent $20 each</figcaption></figure><p>Also note that it lowers your expected value to buy people out who spent less than the average amount.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T63mrgbTOnOvlmz07TzzHg.png" /><figcaption>Your expected value, assuming you have a $50 bill and buy out n people with a $20 bill</figcaption></figure><p>“Ah, so I should spend the most then, and not buy anyone out”, think you, the clever reader. Yes, but of course there comes a point where you don’t want more food or even (perhaps) more beer. Additionally, if you spend more for the sake of improving your position in CCR, the only gains come during that meal. It doesn’t increase the actual amount of cash you could win, and increases the amount of cash you could lose. What you really want to do is get the benefits of a higher bill, without being forced to put all your money into food.</p><p>Now is where we get to the winning move in CCR. Buy out anyone who spent more than the average on the check! If you do this enough you are guaranteed, statistically speaking, to win money playing CCR.</p><p>This introduces a little bit of game theory into CCR. Ignoring the battle over buying out anyone who spent more than the average, you can increase your EV by ordering more. But so can everybody else.</p><p>Looking at this from a game theory perspective, there is no Nash Equilibrium here. No matter what strategy your opponent is deploying, it is always in your interest (in an expected value sense), to order more food.</p><p>Unfortunately, there is no easy solution to this, so you’ll have to be a little honorable when playing CCR. And be careful trying to max out your expected value, because a high expected value won’t help you when you can’t get up from the table!</p><p><em>P.S. You can solve all the “problems” with CCR by adjusting everybody’s odds to match the % of their contribution to the check and picking somebody with an random number generator. This is what the developers at Everlaw do, although it’s certainly less exciting than pulling cards out of a hat.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=759ffb64a9b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ethics of Bike Commuting]]></title>
            <link>https://medium.com/@zacharysabin/the-ethics-of-bike-commuting-2ed154103c94?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ed154103c94</guid>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[cycling]]></category>
            <category><![CDATA[ethics]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 22:39:55 GMT</pubDate>
            <atom:updated>2018-07-25T16:26:24.525Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Warning: Some potentially poor philosophy ahead</em></p><p>On my commute to and from work, I cross a fairly busy street by bicycle. The directions that I go have stop signs, whereas the directions that the most traffic is going (to and from the highway on the major street) do not.</p><p>As a biker, you can dismount and walk the bike across the intersection on the crosswalk. Cars will typically stop for you since you have, in essence, become a pedestrian. Once across the street you can then get back on your bike and resume riding. Since this is a common bike route, people often do this to avoid waiting for the infrequent gaps in traffic.</p><p>There are rarely cars in the intersection since the street is a “bicycle route”, meaning that it has lots of stop signs and speed bumps, but when there are cars they are generally turning right or left to get onto the major road. On the occasions that the cars are going straight, they often are stuck waiting quite a while unless a biker opens up the gap by claiming the crosswalk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5ccteBIH5jFml2vRnA7Og.png" /><figcaption>The intersection in question, seen as I ride North</figcaption></figure><p>So the question is, is it alright to dismount my bike and force traffic to stop for me versus waiting for a gap in traffic as somebody in a vehicle would have to? Cyclists, myself included, often want drivers to respect us as they do other drivers — by doing things such as switching lanes to pass us, not coming incredibly close behind us at stoplights, and just generally sharing the road. So I feel bad forcing them to all of sudden treat me like a pedestrian simply so I can cross the street faster. It also seems like that would encourage drivers to continue to think of cyclists as second class users of the road.</p><p>I decided to think about the question through three avenues. The first is what the legal status of the crosswalk move is, and I then wanted to look at it through a Kantian ethical framework and a Utilitarian one.</p><p>There’s nowhere in California that states exactly whether it’s legal to dismount and use the crosswalk, but as far as I can tell it is. <a href="https://patch.com/california/alameda/bp--is-the-crosswalk-a-safe-way-for-a-bicycle-rider-t110edb3937">This</a> article from a local paper in Alameda indicates that while you cannot claim right of way on a crosswalk if you are riding your bike, walking it across is perfectly fine. That aligns with common sense as well, if you’re walking with a bike then of course you can use a crosswalk as any pedestrian would, and it would be surprising if there was a provision specifically prohibiting dismounting and then using the crosswalk.</p><p>Which brings us to the much thornier question of whether it’s the right thing to do. I’m ignoring the ethics of biking vs driving for this; although I think that biking is better for the environment, cities, and the commuter themselves, I recognize that I am one of a lucky few who is able to live close enough to work to bike. The question simply becomes: is it alright for someone on a bike to dismount and claim right of way, thus blocking a major road for a brief period of time, in order to shorten the cyclist’s wait time?</p><p><em>(This is where some poor philosophy kicks in)</em></p><p>The gist of Kant’s ethics is the statement: “I ought never to act except in such a way that I could also will that my maxim should become a universal law”. In other words, don’t do anything unless the maxim for your action could be used by everyone without ill effect. Of course, that leaves figuring out what their “maxim”is as an exercise for the reader, but in this case I’ll say that the maxim of the crosswalk is that “it’s alright for a cyclist to force traffic to stop briefly in order to expedite the cyclist’s crossing”.</p><p>It seems pretty clear that this is not a maxim that can be applied universally. The intersection was structured this way for a reason (presumably), and if all cyclists forced traffic to stop every time they crossed a major road then it could slow down traffic pretty substantially at certain intersections. Now I might think that this intersection is an exception, but in that case I should try and get a light installed there to fix the flow of traffic, not intentionally circumvent the intended flow of traffic by going from cyclist to pedestrian and back to cyclist.</p><p>Of course, Kant is not the only moral philosopher, so let’s take a look at another framework. Utilitarianism is the idea that the morality of any action is determined by its contribution to the overall well-being / happiness. The overall well-being is a murky concept, but for the sake of this question lets define it as the action that makes the overall commuting time the shortest (since everybody wants a shorter commute). In this case, I actually think that the ethical thing to do is to use the crosswalk, especially if I select a somewhat optimal moment to do so.</p><p>If traffic is moving slowly, then I don’t add any time to peoples’ commutes. They brake for me as I cross, and then accelerate to catch up with the car in front of them. If traffic is sparse, then I don’t need to use the crosswalk so it’s a not an issue. The awkward middle ground, where there is a a dense flow of cars but they are moving quickly, is the hardest to judge. However, in my experience, cars will catch up with seconds of the car in front of them even if they stop to let me cross, so the total time added to people’s commutes is probably under a minute, whereas I have often waited around a minute to find an opportune moment to cross. I often end up crossing when somebody stops for me despite me still being on my bike, which is a net loss since the same amount of time for drivers is lost as if I had just used the crosswalk immediately. So it seems like using the crosswalk quickly is generally alright under a utilitarian framework.</p><p>Which leaves us not much further along than we started. Kant would probably say we shouldn’t use the crosswalk, John Stuart Mill would push us across it, and Jerry Brown wouldn’t mind if we did. In the end, ethics are often a personal decision, and although we may use frameworks to guide us, we must decide for ourselves what is the right thing to do. So I think I will continue to do what I’ve done, which is to bike across if I think there will be a gap in traffic within a reasonable amount of time, but otherwise to use the crosswalk quickly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ed154103c94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux on Windows 10]]></title>
            <link>https://medium.com/@zacharysabin/linux-on-windows-10-83897d02fa22?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/83897d02fa22</guid>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 05:41:18 GMT</pubDate>
            <atom:updated>2018-07-06T05:41:18.338Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently bought a Lenovo T440 on eBay, and it came with Windows 10. I’ve been skeptical of Windows 10 for a while because of the issues with telemetry and tracking, so I’ve tried to avoid using it. However, Windows 10 does have a killer feature that I was really excited about — Windows Subsystem for Linux!</p><p>Basically, you can install a Linux distro (originally it was only Ubuntu, they’ve now expanded it to a larger variety) from the Windows App Store, and then you can run a command line environment of that OS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B_2yN8SirOUL9ruAGEAK7A.png" /><figcaption>This is a program running in Windows!</figcaption></figure><p>The main draw of this is that you can get all the developer horsepower of the Linux terminal without any of the typical hassles. No more messing with graphics card drivers, trying to get the touchpad to disable while you’re typing, or solving the catch 22 of downloading drivers for your wifi card. I was pretty excited about this because I like to use Windows for day to day stuff, and not having to reboot into Ubuntu (as you would for a dual boot system) would lower the barrier to entry for casually programming when I’m at home, a habit that has drifted away from me in the past couple years.</p><p>Anyway I got it all set up, although I had to reinstall it once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LsBSAKwe-vXgrFaBrhswbw.png" /><figcaption>Don’t close the window while this is happening, or you’ll have to reinstall</figcaption></figure><p>The internal environment is pretty nifty. The Linux files are stored somewhere on the Windows machine, although Microsoft warns against modifying them outside of the Linux shell. You can access Windows files from the Linux shell at “/mnt/c”. One very annoying thing I encountered is that Linux does not play nice with all of the symbolic links that Microsoft scatters around the filesystem. I can’t even see the named symbolic links in File Explorer or Windows Command Prompt, I’m not sure where they are from or what purpose they serve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*qGoyfav7XowDkn2jF7AF3g.png" /><figcaption>They make ‘ls’ a lot less concise</figcaption></figure><p>I think the main use of this terminal will be to run code, since it doesn’t fully support GUIs yet, so any non terminal based text editors or IDEs won’t work. But Microsoft has done something very cool w.r.t converting between Windows style line endings and Linux style ones, so that you can edit a file in Windows and have it work in the terminal as if you had wrote it there!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*reSPcnLVYjn4I1pbB246xg.png" /><figcaption>It doesn’t say “Hello World”, so it might not actually count as a working program.</figcaption></figure><p>I noticed that it was extremely slow to install stuff via “sudo apt-get install”. “npm” took 15–20 minutes. I eventually got a django project up and running just to test out how a local webserver would work, and the most basic django project worked well!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3bl377O8BIRGFlm_b1KacQ.png" /><figcaption>Django running its lightweight server from within the Ubuntu terminal</figcaption></figure><p>Overall, I don’t think this can replace a dual boot setup since you can’t run GUI Linux apps and the shell management is limited (can’t use organizers like Terminator, can’t open new instances with a keyboard shortcut). But it’s a really useful tool for developing with Linux tools while still making use of Windows’ hardware compatibility and power management. I hope Microsoft keeps supporting it and doesn’t let it fall by the wayside!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83897d02fa22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Should You Roll 1 or 2 Dice in Risk Defense?]]></title>
            <link>https://medium.com/@zacharysabin/should-you-roll-1-or-2-dice-in-risk-defense-e36bd7df24c5?source=rss-f37ab9c8632f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e36bd7df24c5</guid>
            <category><![CDATA[risk]]></category>
            <category><![CDATA[games]]></category>
            <dc:creator><![CDATA[Zachary Paine Sabin]]></dc:creator>
            <pubDate>Tue, 19 Jun 2018 06:42:18 GMT</pubDate>
            <atom:updated>2021-10-19T06:07:27.914Z</atom:updated>
            <content:encoded><![CDATA[<p>TL;DR: The defender should roll two dice.</p><p>Last week I was playing Risk with a couple friends, and we got into a bit of a debate on defensive strategies. In particular, the number of dice that you should roll when defending with two or more armies. For those of you who don’t know the rules of Risk, the attacking player can roll up to three dice, assuming they have four or more troops in the territory that they are attacking from, and the defender can roll two dice as long as they have two or more defending units. The defender then compares their highest roll with the attacker’s highest, and their second highest (if they rolled two) with the attacker’s second highest (if the attacker rolled two or three). Players lose a unit for each matchup in which the opponent has a better roll, so the possible results if the defender rolls two dice are that the attacker loses two, the defender loses two, or each player loses one. However if the defender only rolls one, then they can lose a unit or the attacker can lose a unit. Importantly, the defender wins ties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*SQR_XCoXSb2RI5dGgkuN_Q.png" /><figcaption>Lord of the Rings Risk staging area where you put the unit pieces that each dice represents</figcaption></figure><p>There is obviously a thrill to taking out two attacking units as a defender, but due to how the board is set up initially you are often defending with only two units, so losing both in a single roll is devastating. But my intuition was that a defender, due to winning ties, has a better chance at taking out at least one attacking unit if they roll close to as many dice as the attacker. An alternative way of thinking about it was that rolling two at once only allowed the attacker three rolls to beat the defender’s two, as opposed to the six they would get if the defender only rolled one at a time. But, of course, my friend did not accept these arguments as incontrovertible facts, so I left the table on a mission to prove that two was better than one.</p><p>I decided to go with a brute force method rather than proving it analytically because my stats skills are rusty and it seemed easier to understand, and therefore more convincing. My code is below, but essentially the program just tallies up the different outcomes for every possible result of the 3v1 battle and the 3v2 battle. I would like to sit down at some point and actually prove it, and maybe come up with a general formula for the odds of any n vs. m battle.</p><p>It turns out that I was correct that the defender should roll two dice, although the expected results are fairly similar. If the defender rolls one dice, their expected outcome is to lose .32 units, and if they roll two, their expected outcome is to lose .16 units. So one dice is almost twice as bad as two dice, but the difference is fairly small in absolute numbers. Interestingly, if you played with dice that have 16 or more sides, the defender is better off only rolling one dice.</p><p>Here are the total number of roll results that lead to the various outcomes (the attacker is rolling three dice in all of these situations).</p><p><strong>Defender rolls one die, kills one attacker: 441<br>Defender rolls one die, loses one troop: 855</strong></p><p><strong>Defender rolls two die, kills two attackers: 2275<br>Defender rolls two die, splits: 2611<br>Defender rolls two die, loses two troops: 2890</strong></p><p>And here is my (hastily written, non-optimized) code:</p><pre>import heapq<br>numbers = [1,2,3,4,5,6]</pre><pre>#0th index is number of results where defender wins<br>#1st index is number of results where attacker wins<br>one_die = [0,0]</pre><pre>#0th index is number of results where attacker loses two<br>#1st index is number of splits<br>#2nd index is number of results where defender loses two<br>two_die = [0,0,0]</pre><pre>for a1 in numbers:<br> for a2 in numbers:<br>  for a3 in numbers:<br>   top_two = heapq.nlargest(2, [a1, a2, a3])<br>   for d1 in numbers:<br>    #If defender rolls one, match it up with highest attacking die<br>    if (d1 &gt;= top_two[0]):<br>     one_die[0]+=1<br>    else:<br>     one_die[1]+=1<br>    for d2 in numbers:<br>     sorted_d = heapq.nlargest(2, [d1, d2])<br>     ind = 0<br>     #If defender rolls two, match up dice in sorted order<br>     for i in [0,1]:<br>      if (sorted_d[i] &lt; top_two[i]):<br>       ind += 1<br>     two_die[ind]+=1</pre><pre>ev_one = (one_die[0] + one_die[1]*-1) / sum(one_die)<br>print(ev_one)<br>ev_two = (two_die[0] * 2 + two_die[2] * -2) / sum(two_die)<br>print(ev_two)</pre><p>P.S. <a href="https://en.oxforddictionaries.com/definition/dice">Apparently</a> dice is both the singular and the plural of the word, and “die” is no longer the singular.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e36bd7df24c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>