Git Product home page Git Product logo

lottery-picks's Introduction

Uncle-Morty-s-Lottery-Picks

Winning Ticket!

Your favorite uncle, Morty, is crazy about the lottery and even crazier about how he picks his “lucky” numbers. And even though his “never fail” strategy has yet to succeed, Uncle Morty doesn't let that get him down.

Every week he searches through the Sunday newspaper to find a string of digits that might be potential lottery picks. But this week the newspaper has moved to a new electronic format, and instead of a comfortable pile of papers, Uncle Morty receives a text file with the stories.

Help your Uncle find his lotto picks. Given a large series of number strings, return each that might be suitable for a lottery ticket pick. Note that a valid lottery ticket must have 7 unique numbers between 1 and 59, digits must be used in order, and every digit must be used exactly once.

For example, given the following strings:

[ "569815571556", “4938532894754”, “1234567”, “472844278465445”]

Your function should return:

4938532894754 -> 49 38 53 28 9 47 54 1234567 -> 1 2 3 4 5 6 7

Logic to the solution: The number is passed as a string at the beginning . validate() function validates the length of the string which in turn goes through parses the string (parseStr function) and removeDuplicates function to give the end result Get all the pair combinations of the string: For eg: 4798 will give 47,79,98. If length of the string < 7 -> INVALID = 7 & not a zero , is unique and <59 -> OUTPUT >7 -> passes through a logic explained below

  Taking two consecutive elements (val1,val2) at a time,
  Scenario 1 : If val1 <val2 && val1 <59 ---> retain val1 and discard val2
  Scenario 2 : If val1< val 2 && val1>59 ----> Split val1 and take first digit, discard val2
  Scenario 3: If val1 >val2 && val1 <59 ----> retain val1 
  Scenario 4 : If val1> val 2 && val1>59 ----> Split val1 and take first digit, discard val2

Parse the result to check for the length again : if >7 , aggregate the adjacent single digits to double until length is 7. else , split the double digits until length is 7.

Check the result from parsing to make sure there are no duplicates.

lottery-picks's People

Contributors

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