Discussion
· Jan 26

Code Golf: Multi-Tap technique

Multi-tap or multi-press is the name given to the historic technique of writing SMS on the first mobile phones with a keyboard of 10-12 numeric keys.
For example, to type LOL you need to press 5 three times, 6 three times and 5 three times again.
Your task is to write a function that takes a string as input and returns the repeated digits associated with each character according to the multi-tap system.
Should consider letters from A to Z, doesn't distinguish between upper/lowercase characters.
Numbers are allowed, and any punctuation should be ignored.

multitap system

Input

"Example"

Output

"339926755533"

Note

Rules

  1. The signature of the contest entry MUST be:

    Class codeGolf.MultiTap Extends %RegisteredObject
    {
        ClassMethod ToKeyPad(phrase) As %String
        {
            Return "" // Your solution here
        }
    
    }
    
  2. It is forbidden to modify class/signature, including but not limited to:

    • Adding inheritance
    • Setting default argument values
    • Adding class elements (Parameters, Methods, Includes, etc).
  3. It is forbidden to refer to non-system code from your entry. For example, this is not a valid entry:

    ClassMethod Build(f As %Integer)
    {
      W ##class(myPackage.myClass).test(a)
    }
    
  4. The use of $ZWPACK and $ZWBPACK is also discouraged.

  5. You can use this test case:

    Class codeGolf.unittest.MultiTap Extends %UnitTest.TestCase
    {
        Method TestMultiTap()
        {
            Do $$$AssertEquals(##class(codeGolf.MultiTap).ToKeyPad("Example"), "339926755533")
            Do $$$AssertEquals(##class(codeGolf.MultiTap).ToKeyPad("Dumbphone TEXT"), "38862274466666330833998")
            Do $$$AssertEquals(##class(codeGolf.MultiTap).ToKeyPad("InterSystems IRIS"), "44466833777777799977778336777704447774447777")
            Do $$$AssertEquals(##class(codeGolf.MultiTap).ToKeyPad("Code Golf"), "22266633304666555333")
            Do $$$AssertEquals(##class(codeGolf.MultiTap).ToKeyPad("L33T C0d3r"), "55533333333802220033333777")
        }
    }
    
Discussion (18)4
Log in or sign up to continue