GithubHelp home page GithubHelp logo

challenge-260-easy's Introduction

Challenge-260-Easy

Solution to a Garage Door Opener. A simple Finite State Machine with 6 States and 2 inputs.

link: https://www.reddit.com/r/dailyprogrammer/comments/4cb7eh/20160328_challenge_260_easy_garage_door_opener/

Description of Challenge:

You just got a new garage door installed by the Automata™ Garage Door Company. You are having a lot of fun playing with the remote clicker, opening and closing the door, scaring your pets and annoying the neighbors.

The clicker is a one-button remote that works like this:

If the door is OPEN or CLOSED, clicking the button will cause the door to move, until it completes the cycle of opening or closing.

Door: Closed -> Button clicked -> Door: Opening -> Cycle complete -> Door: Open.

If the door is currently opening or closing, clicking the button will make the door stop where it is. When clicked again, the door will go the opposite direction, until complete or the button is clicked again.

We will assume the initial state is CLOSED. Formal Inputs & Outputs Input description

Input will be a series of commands (can be hard coded, no need to parse):

button_clicked cycle_complete button_clicked button_clicked button_clicked button_clicked button_clicked cycle_complete

Output description

Output should be the state of the door and the input commands, such as:

Door: CLOSED

Button clicked. Door: OPENING Cycle complete. Door: OPEN Button clicked. Door: CLOSING Button clicked. Door: STOPPED_WHILE_CLOSING Button clicked. Door: OPENING Button clicked. Door: STOPPED_WHILE_OPENING Button clicked. Door: CLOSING Cycle complete. Door: CLOSED

Notes/Hints

This is an example of a simple Finite State Machine with 6 States and 2 inputs. Bonus

Bonus challenge - The door has an infrared beam near the bottom, and if something is breaking the beam, (your car, your cat, or a baby in a stroller) the door will be BLOCKED and will add the following rules:

If the door is currently CLOSING, it will reverse to OPENING until completely OPEN. It will remain BLOCKED, however, until the input BLOCK_CLEARED is called.
Any other state, it will remain in that position, until the input BLOCK_CLEARED is called, and then it will revert back to it's prior state before it was blocked. Button clicks will be discarded. If the door was already in the process of opening, it will continue to OPEN until CYCLE_COMPLETE is called.

Bonus Challenge Input

button_clicked cycle_complete button_clicked block_detected button_clicked cycle_complete button_clicked block_cleared button_clicked cycle_complete

Bonus Challenge output:

Door: CLOSED

Button clicked Door: OPENING Cycle complete Door: OPEN Button Clicked Door: CLOSING Block detected! Door: EMERGENCY_OPENING Button clicked. Door: EMERGENCY_OPENING Cycle complete. Door: OPEN_BLOCKED Button clicked Door: OPEN_BLOCKED Block cleared Door: OPEN Button clicked Door: CLOSING Cycle complete Door: CLOSED

challenge-260-easy's People

Contributors

mmstiver 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.