Skip to content

spizm/NumericDecoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Here is a Javascript problem I was hoping to get the best solution on.
I've created the first pass that is a solution to the problem listed below in the single HTML file.

I used Javascript, but welcome other languages (just for fun).  Any improvements to the code would be awesome, would love to get the community input.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PROBLEM DEFINITION:

  Numbers are assigned to each letter of the alphabet, where a=1, b=2, ..., z=26.
  A word can then be encoded based on those numbers, so for example "apple" is encoded as "11616125".
  However, "11616125" can also be decoded to many other strings, such as "kfafay" (11 6 1 6 1 25) and "aafple" (1 1 6 16 12 5).

  Letters are never encoded with a leading 0. So '105' only has a single valid decoding, (10 5) = 'je'. You could not decode it (1 05) = 'ae'.

  Write a function that takes a string as input, such as "11616125", and returns an array of all possible decodings of that string. Here are some examples of input and correct output:
  decode('105') returns array('je')
  decode('2175') returns array('bage', 'bqe', 'uge')
  decode('2222') returns array('bbbb','bbv','bvb','vbb','vv')
  decode('0000') returns array()
  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
Who can come up with the best solution?  Least amount of code? Fastest running?

About

Decodes a numeric value to it's alphabet equivalent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published