Git Product home page Git Product logo

autolotto's Introduction

AutoLotto from lottery.com exercise

Description

Powerball is a popular US lottery game with draws twice a week. For the purposes of this exercise, a Powerball lottery "ticket" includes one or more "picks". Each "pick" is a set of 5 integers (from 1-69) along with a 6th integer (the Powerball, from 1-26) that the user has chosen to play during a specific draw.

For example, a pick for the draw on 2017-11-09 might be:

02 14 19 21 61 25

The application's API accepts data for a lottery ticket, and respond with whether each pick has won, the prize won per-pick, and the total of all prizes won on the ticket.

The test end point used is:

https://games.api.lottery.com/api/v2.0/results?game=59bc2b6031947b9daf338d32

To calculate the prize, the prize matrix image below is used:

Multiplier Power Rules used are

When the advertised annuity jackpot is less than or equal to the Major Jackpot Level, the multiplier will be either 2X, 3X, 4X, 5X or 10X.

When the advertised annuity jackpot is greater than the Major Jackpot Level, the multiplier will be either 2X, 3X, 4X or 5X.

The Major Jackpot Level is defined as "the level above which Powerball drawings will no longer include a Power Play of 10X." The Major Jackpot Level is currently $150,000,000.

The 10X multiplier is not available when the jackpot is above the Major Jackpot Level

Installation

This app requires:

  • A Linux or MacOS Environment (Windows Untested)
  • Node.js 8.9+

If you do not have node.js installed:

  1. Install NVM
  2. Install Node 8.9 nvm install 8.9
  3. Switch to Node 8.9 nvm use 8.9

Starting the App

From the checked-out application folder, run:

npm start

You should see output like this:

node index.js
App listening on port 3000

You can then hit the endpoint with POST:

with a REQUEST LIKE:

Example REQUEST

[
    {
    "message": "2 Win the Lotto!",
    "game": "powerball",
    "gameDate": "2018-04-01",
    "powerPlay": true,
    "line": [
        {
          "value": "8",
          "type": "NUMBER"
        },
        {
          "value": "4",
          "type": "NUMBER"
        },
        {
          "value": "2",
          "type": "NUMBER"
        },
        {
          "value": "5",
          "type": "NUMBER"
        },
        {
          "value": "1",
          "type": "NUMBER"
        },
        {
          "value": "71",
          "type": "NUMBER",
          "name": "Powerball",
          "category": "EXTRA"
        }
      ]
},
{
    "message": "Win the Lotto!",
    "game": "powerball",
    "gameDate": "2018-04-01",
    "powerPlay": false,
    "line": [
        {
          "value": "8",
          "type": "NUMBER"
        },
        {
          "value": "24",
          "type": "NUMBER"
        },
        {
          "value": "52",
          "type": "NUMBER"
        },
        {
          "value": "55",
          "type": "NUMBER"
        },
        {
          "value": "61",
          "type": "NUMBER"
        },
        {
          "value": "21",
          "type": "NUMBER",
          "name": "Powerball",
          "category": "EXTRA"
        }
      ]
}
]

Your local end point to use is

http://localhost:3000/api

You should see something like this:

{
    "totalAmountWon": 50000000,
    "results": [
        {
            "date": "2018-04-01",
            "powerPlay": true,
            "powerBall": "71",
            "originalWhites": [
                "8",
                "4",
                "2",
                "5",
                "1"
            ],
            "matchedPowerBall": false,
            "matchingNumbers": [
                "8"
            ],
            "amountWon": 0
        },
        {
            "date": "2018-04-01",
            "powerPlay": false,
            "powerBall": "21",
            "originalWhites": [
                "8",
                "24",
                "52",
                "55",
                "61"
            ],
            "matchedPowerBall": true,
            "matchingNumbers": [
                "8",
                "24",
                "52",
                "55",
                "61"
            ],
            "amountWon": 50000000
        }
    ]
}

To shutdown the server simply send a ^C.

Testing

To run the existing (sample) tests simply use:

npm test

You should see output like this:

  
  ✔ app › App Environment
  ✔ app › App Base Path
  ✔ app › App Includes Error Handler Middleware
  ✔ controllers › index › Hello World Controller
  ✔ controllers › index › Fail Controller
  ✔ controllers › index › Not Found Controller
  ✔ middleware › errors › Error Handler Middleware
  ✔ middleware › errors › Error Handler for NotFound Case
  ✔ routes › routes › Router Setup
  
  9 tests passed
  

autolotto's People

Contributors

timothyjeffcoat avatar

Watchers

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