Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the optimal algorithm design for a water-saving urinal? [closed]

Tags:

algorithm

At work, we have one of those nasty communal urinals. There is no flush handle. Rather, it has a motion sensor that sometimes triggers when you stand in front of it and sometimes doesn't. When it triggers, a tank fills, which when full is used to flush the urinal.

In my many trips before this nastraption, I have pondered both what the algorithm is the box uses to determine when to turn on and what would be the optimal algorithm, in terms of conserving water while still maintaining a relatively pleasant urinal experience.

I'll share my answer once folks have had a chance to share their ideas.

like image 564
Andrew Hedges Avatar asked Oct 26 '08 00:10

Andrew Hedges


1 Answers

OnUserEnter()
{
   if (UsersDetected == 0)
   {
      FirstDetectionTime = Now();
   }
   UsersDetected++;
   CurrentlyInUse = true;
}

OnUserExit()
{
  CurrentlyInUse = false;
  if (UsersDetected >= MaxUsersBetweenFlushes || 
         Now() - FirstDetectionTime > StinkInterval)
  {
     Flush();
  }
}

OnTimer()
{
   if (!CurrentlyInUse && 
          UsersDetected > 0 && 
          Now() - FirstDetectionTime > StinkInterval)
   {
      Flush();
   }
}

Flush()
{
   FlushTheUrinal();
   UsersDetected = 0;
}
like image 164
Gerald Avatar answered Sep 18 '22 13:09

Gerald