Coder Social home page Coder Social logo

loo.js's Introduction

loo.js

A restroom protocol library.

Features

  • Calculate the maximum number of occupants that can use a set of contiguous stalls without things getting too awkward
  • Choose the most socially-acceptable stall given a set of contiguous stalls and their occupant status
  • Calculate Minespeeper-like distances away from occupied stalls for each empty stall so you can be as informed as possible when making that imporant decision

Examples

Let's say you have five contiguous stalls with the 0th, and 4th stalls occupied. You can represent these stalls with an array of Booleans, true for occupied, and false for vacant.

var stalls = [true, false, false, false, true, false, false]

Calculate theoretical maximum occupants (non-awkward)

Use loo.max_occupants to calculate the theoretical maximum number of people that can use this set of stalls without things getting too awkward:

>>> loo.max_occupants(stalls.length)
3

Yes ladies, that is a closed-form function.

Choose a stall

Which stalls are most socially-acceptable to use?

>>> loo.choose(stalls)
[2, 6]

The most socially-acceptable stalls to use are the 2nd and 6th stall (0-indexed), as they are the greatest distance away from any occupied stall.

Create a Minesweeper-like distance map

You're a decisive person. You don't need a computer choosing things for you! But that doesn't mean you can't be informed before making your decision.

>>> loo.minesweeper(stalls)
[0, 1, 2, 1, 0, 1, 2]

These are the distances away from the nearest occupied stall, for each stall, all in O(2n) time complexity.

loo.js's People

Contributors

robatron avatar joeframbach avatar cmsimike avatar

Watchers

Robert Martone avatar James Cloos 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.