A snail is at the bottom of a well of H height and wants to climb to the top. The snail can climb U feet while the sun is up, but slides down D feet at night while sleeping. The snail has a fatigue factor of F %, which means that on each successive day the snail climbs F % * H = W feet less than it did the previous day. The distance lost to fatigue is always F % of the *first* day's climbing distance. All four numbers must be between 1 and 100, inclusive.
Depending on the parameters of the problem, the snail will eventually either leave the well — Success — or slide back to the bottom of the well — Failure.
This app aims to solve the snail problem. It provides the solution as a RESTful web service that takes in the parameters of the problem and provides the solution as a string, which says if the snail succeeded or failed. This solution is facilitated by a User Interface (UI) hosted on the web, which can be found here.
This application follows the Model-View-Controller (MVC) architectural design pattern. As the backend portion of the solution, this repository contains the Model and Controller pieces of the architecture. The View (frontend) can be found here.
This application was developed using the PHP web application framework, Laravel. It provides great tools for building robust applications and allows for the implementation of MVC patterns smoothly. See below for more details.
The database for this application is a PostgreSQL database instance hosted on Heroku. The application itself (web service) is also hosted on Heroku.
- config/database.php: allows the database connection set up
- Migrations file: defines the schema for the database and allows you to set up that schema with a php command after the database is configured
- Seeders: populate your database with mock data for testing via a php command.
- app/Models: provides mapping for the database schema by leveraging Laravel's Eloquent ORM (obejct relational mapper). It works great out of the box and performs a lof of the heavy lifting related to database mapping and queries automatically.
- app/Http/Controllers: contains control logic. The endpoints of the RESTful service that will be reachable by outside parties (API) live here.
You can see a list of all the attempts the snail has made to escape the well, which includes the date, attempt parameters, and result.
GET /api/snailAttempts
You can provide the parameters for the snail to attempt escaping the well. The result will be calculated and returned to you. The parameters and its corresponding result will be stored in the database.
PUT /api/snailCheck
- h: height of the well in feet
- u: distance in feet that the snail can climb during the day
- d: distance in feet that the snail slides down during the night
- f: fatigue factor expressed as a percentage
All parameters are required. All parameters must be between 1 and 100, inclusive.
- PHP and Composer installed
- Node and NPM for dependency and package management.
If you are developing on macOS, PHP and Composer can be installed via Homebrew.
- Use
npm install
to download all project dependencies. - Start Laravel's local development server using the Laravel's Artisan CLI serve command:
php artisan serve
- One the development server starts, the application will be accessible at
http://localhost:8000
- You can now make API calls via cURL, Postman, or other methods. An example of the GET endpoint looks like
localhost:8000/api/snailAttempts