Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A restroom protocol library

NotificationsYou must be signed in to change notification settings

robatron/loo.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

A restroom protocol library.

Features

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

Examples

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

varstalls=[true,false,false,false,true,false,false]

Calculate theoretical maximum occupants (non-awkward)

Useloo.max_occupants to calculate the theoretical maximumnumber of people that can use this set of stalls without thingsgetting 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 and6th stall (0-indexed), as they are the greatest distance awayfrom any occupied stall.

Create a Minesweeper-like distance map

You're a decisive person. You don't need a computer choosingthings for you! But that doesn't mean you can't be informedbefore 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.

About

A restroom protocol library

Topics

Resources

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp