Coder Social home page Coder Social logo

538's Introduction

538.com Riddles: Code & Simulations

This is a repository for code, apps & simulations I whip together to solve puzzles posed by FiveThirtyEight.com's The Riddler.

Misanthropic Neighbors

First simulation is for the 4/22/16 puzzle, which goes as follows:

The misanthropes are coming. Suppose there is a row of some number, N, of houses in a new, initially empty development. Misanthropes are moving into the development one at a time and selecting a house at random from those that have nobody in them and nobody living next door. They keep on coming until no acceptable houses remain. At most, one out of two houses will be occupied; at least one out of three houses will be. But what's the expected fraction of occupied houses as the development gets larger, that is, as N goes to infinity?

My a priori reasoning:

  • Best case = 1/2 occupied houses

  • Worst case = 1/3 occupied houses

  • Mean case = 5/12 occupied houses

As N grows infinitely large, the fraction of occupied houses will approach the mean case.

There are variances in the distributions of best, worst, & median cases depending on N being odd or even, as well as its size (in fact, odd N's can do better than 1/2 in edge cases for large N's, and very often for small N's). However, these marginal variances should shrink asymptotically to zero as N approaches infinity.

To test this, I created a simulation in R. I then wrapped that code in an interactive shiny app, which can be accessed here: https://dnlmc.shinyapps.io/misanthrope_app/

Per this simulation, the proportion of occupied houses converges to โ‰ˆ .432... as N grows larger.

My a priori conjecture was 5/12, which equals roughly .41666...

As we used to say in my old job: close enough for government work.

The underlying R code for the simulation is 'misanthropic_neighbors.R' in this repository. The ui.R & server.R scripts pertain to the shiny app implementation.

I'm thinking about adding a representation of a typical row of occupied & unoccupied houses at the end of a given trial, but its utility & interpretability also approaches zero as N increases (& becomes relevant to the problem posed).

538's People

Contributors

dnlmc avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.