GithubHelp home page GithubHelp logo

amarduwal / assignment Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 470 KB

Solution for number to possible words or combinations of words from the provided dictionary, that can be mapped back as a whole to the number.

Ruby 100.00%

assignment's Introduction

Number to possible words conversion

Given a 10 digit phone number, you should return all possible words or combinations of words from the provided dictionary, that can be mapped back as a whole to the number. With this we can generate numbers like 1-800-motortruck which is easier to remember than 1-800-6686787825.

The phone number mapping to letters is as follows:

2 = a b c
3 = d e f
4 = g h i
5 = j k l
6 = m n o
7 = p q r s
8 = t u v
9 = w x y z

The phone numbers will never contain a 0 or 1. Words have to be at least 3 characters.

To give you an initial idea, here are some numbers that return (a lot of) results. 6686787825 returns a (long) list with at least these word combinations:

  • motortruck
  • motor, truck
  • motor, usual
  • noun, struck
  • not, opt, puck

2282668687 returns a (long) list with at least these word combinations:

  • catamounts
  • acta, mounts
  • act, amounts
  • act, contour
  • cat, boot, our

The conversion of a 10 digit phone number should be performed within 1000ms.

Execution

Copy and paste this line to the Terminal and press Enter.

git clone https://github.com/amarduwal/assignment.git

Browse to root folder

cd assignment

Run code as below

ruby number_conversion.rb

OR

time ruby number_conversion.rb

Instruction

Successfully execute code on ruby 2.6.2. It requires 'pry'(for debugging) gem and 'benchmark'(to measure performance) for execution. And 'Rspec' for testing. So if your system doesn't have those gem please install before execution.

  • To install pry
gem install pry
  • To install RSpec
gem install rspec

assignment's People

Contributors

amar-duwal avatar

Watchers

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