Key Information

Register
Submit
The challenge is finished.

Challenge Overview

This is the Medium - 500 point problem of RDM-Practice
Consolidated Match Leaderboard is available here.

Please Note - The files linked in the specs will only be accessible after you register for the challenge.


You have recently discovered that your roommate has hidden some delicious cookies in one of the rooms in your house. You want to get to them but when you try to open the door you find that the door cannot be opened without a pattern-based door lock. But interestingly, the pattern-based door lock has not been installed yet! The pattern-based door-lock has to be built by you in the form of an API. Thankfully, there is an instruction manual in front of the door that your friend inadvertently left, which describes how the pattern-lock should work.

The following are the contents of the instruction manual.
 

Pattern-lock making instruction manual:

Note - the images illustrated below are only for reference. The contestants are NOT required to develop the UI.

image
 

1. The pattern-lock consists of 9 circles. Each circle represents a digit, the digit can only be 1-9.
2. The circles can be connected by lines, making a pattern. A pattern makes up a number. For example, the following pattern can make up a number 14852 or 25841.

image

3. Here, one circle can be visited only once, unless there is a closed-loop, in this case, the end circle can be visited twice. For example, the pattern below can make up the numbers 124114212412214241244214.

image

4. A valid pattern (that opens the lock) should have the following features:

    - A pattern connects AT LEAST 2 circles and AT MOST 5 circles.
    - If 3 circles are in a line, two end circles cannot be connected without connecting the middle circle. For example, 1 and 3 cannot be connected without connecting 23 and 7 cannot be connected without connecting 5. So a pattern can never make up numbers like 132 or 378.

Requirements

In this challenge, you need to build an API using the instruction manual to implement the pattern lock, which you’ll eventually use to open the door and get your hands on the delicious cookies! 
 

API Requirements


Check the provided Swagger as a guide to build your API. It is in the challenge forum.


You should build an API with a POST /pattern-lock endpoint, where

  • The request header should contain a Bearer token, which should be a string Bearer patt3rnl0ckk3y.

The request body should be
{

  "number": <number>

}



The response contains the following conditions

(1) If the number has 2-5 digits and can be made up by a pattern, the response should be

Status code: 200

Response body:

 {

     "possible-numbers": <all possible numbers in an array, e.g. [123, 321]>.

 }


(2) If the bearer key is invalid, the response should be

Status code: 401

Response body:

 {

    "message": "Invalid key"

  }


(3) If the number is invalid or cannot be made up by a pattern, e.g., 1323781ab1 etc, the response should be

Status code: 400 (bad request)

Response body:

 {

    "message": "Invalid number"

 }

 

Sample Test Cases

These are sample test cases to check your pattern-lock solution for api:

  • Input = 99 

    • Possible Pattern-Lock = Invalid number!

  • Input = 0 

    • Possible Pattern-Lock = Invalid number!

  • Input = 1241

    • Possible Pattern-Lock = 1241,1421,2412,2142,4124,4214

  • Input = 123 

    • Possible Pattern-Lock = 123,321

  • Input = 5632 

    • Possible Pattern-Lock = 5632,2356

  • Input = 68542 

    • Possible Pattern-Lock = 68542, 24586
       

Sample Submission

This challenge uses a purely automated testing approach to score the submissions so we are providing a sample submission and an automated tester with a basic test case assembled in a way that simulates the final testing. Docker is used to achieving this. Please read the README.md file to find out how to run the setup.

The sample submission will be in the code folder and it should be extended to implement the requirements. The README.md file contains some guidelines on how to extend the sample submission.

Sample submission with local tester for this challenge: medium-sample-and-tester.zip
Sample Submission to submit on the platform: medium-sample-submission.zip



Final Submission Guidelines

Submission Deliverables

Your submission must be a single ZIP file not larger than 10 MB containing just the code folder with the same structure as the one from the sample submission. The sample tester should not be included in the submission. Also make sure you don't submit any build folders generated locally like node_modules, dist etc.

You must follow this submission folder structure so our automated test process can process your scoring:

  • Create a folder with “code” as the folder name then zip. 
  • Inside the “code” folder, there needs to be a file named Dockerfile. This is the docker file used to build the user’s submission. Refer to the provided Docker file in Sample Submission for each level.
  • Zip that “code” folder and submit to the challenge.

Execution Details and Submission Logs

Each time you submit, the platform will leverage Docker to run your code. The execution logs will be saved as “Artifacts” that can be downloaded from the Submission Review App: https://submission-review.topcoder.com/.

RDM-Execution-logs

RDM-Execution-Logs-2

Checking Passing and Failing Test Cases

Using the Submission Review App (https://submission-review.topcoder.com/), navigate to the specific challenge, then to your submission, and then to the Artifacts for your submission. The zip file you download will contain information about your submission including a result.json file with the test results.

Docker Structure

Make sure you can run your submission with Docker from a clean slate. Your Docker needs to expose port: 8080. It needs to build on a completely clean machine when the platform runs your submission. If you are using something locally to build and run your submission, make sure it’s included as part of your Docker configuration as well. Please look at the sample submission to understand the structure better.

ELIGIBLE EVENTS:

2021 Topcoder(R) Open

REVIEW STYLE:

Final Review:

Community Review Board

Approval:

User Sign-Off

SHARE:

ID: 30162208