Giter Club home page Giter Club logo

screen-locking-patterns's Introduction

Screen Locking Patterns

Tests

This is based on the Screen Locking Patterns Codewars exercise.

If you own an Android smartphone, you are familiar with the pattern you chose to lock your phone with. Every time, you pick up your phone and mechanically draw these lines on your screen, connecting the dots to form the unlock pattern. To unlock the device, you need to connect a sequence of dots/points in a grid by swiping your finger without lifting it as you trace the pattern through the screen.

Android Screen Lock

The challenge is to implement a function that returns the number of possible patterns starting from a given first point, that have a given length. Assume the grid as the following:

Association between points and numbers

For a function countPatternsFrom(firstPoint, length), the parameter firstPoint is a number corresponding to the point in the grid (e.g.: 1) where your patterns start, and the parameter length is an integer indicating the number of points (length) every pattern must have.

For example, countPatternsFrom(3, 2), should return the number of patterns starting from 3 that have 2 two points. The return value, in this case, would be 5, because there are 5 possible patterns:

(3 → 2), (3 → 4), (3 → 5), (3 → 6), and (3 → 8).

Bear in mind that this kata requires returning the number of patterns, not the patterns themselves, so you only need to count them. Also, the name of the function might be different depending on the programming language used, but the idea remains the same.

Pattern Rules

  1. In a pattern, the points cannot be repeated: they can only be used once, at most.
    1. You can’t have a path as 2 → 3 → 4 → 2.
  2. In a pattern, any two subsequent points can only be connected with direct straight lines in either of these ways:
    1. Horizontally: like (1 → 2).
    2. Vertically: like (4 → 7).
    3. Diagonally: like (I → E), as well as (2 → 9).
  3. Passing over a point that has already been 'used' as like 5 → 4 → 7 → 3 passing over 5 from 7 → 3. Normally, you wouldn't be able to connect 7 → 3 going through 5 but, for the context of the exercise, you can have a pattern like 5 → 4 → 7 → 3, since the path from 7 → 3 is valid and 5 has been already used in the pattern.

Unit test to validate the implementation

Check patterns.test.ts for the unit tests to validate the implementation.

screen-locking-patterns's People

Contributors

ruisaraiva19 avatar

Stargazers

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