11
\$\begingroup\$

This is a simple challenge which hopefully may lead to some creative answers.

Quoting Wikipedia: "Dual-tone multi-frequency signaling (DTMF) is an in-band telecommunication signaling system using the voice-frequency band over telephone lines between telephone equipment and other communications devices and switching centers."

Task

Given two integers representing the column and row frequencies in the following table, your task is to output the corresponding key:

       | 1209 Hz | 1336 Hz | 1477 Hz
-------+---------+---------+---------
697 Hz |    1    |    2    |    3
770 Hz |    4    |    5    |    6
852 Hz |    7    |    8    |    9
941 Hz |    *    |    0    |    #

Examples

  • If the input is [ 1209, 852 ], the expected output is "7".
  • If the input is [ 1477, 941 ], the expected output is "#".

Rules

  • You must take input as integers in any reasonable format, such as two separate variables or an array of two variables. Please specify in which order your program is expecting them (either column_freq, row_freq or row_freq, column_freq).
  • The input is guaranteed to be valid.
  • You must print or output a character. However, you're also allowed to output an integer for digit keys.
  • This is , so the shortest answer in bytes wins!
\$\endgroup\$

7 Answers 7

8
\$\begingroup\$

JavaScript (ES6), 39 35 bytes

a=>b=>"310*58# 47269"[a%b%83%16%13]

Maps the two inputs into numbers in the range [0, 13) by calculating:
col % row % 83 % 16 % 13.
Takes input in currying syntax (f(col)(row)) and returns a single-char string.

Test Cases

let f=
a=>b=>"310*58# 47269"[a%b%83%16%13]

console.log( f(1336)(941) )
console.log( f(1209)(697) )
console.log( f(1336)(697) )
console.log( f(1477)(697) )
console.log( f(1209)(770) )
console.log( f(1336)(770) )
console.log( f(1477)(770) )
console.log( f(1209)(852) )
console.log( f(1336)(852) )
console.log( f(1477)(852) )
console.log( f(1209)(941) )
console.log( f(1477)(941) )
.as-console-wrapper{max-height:100%!important}

History

Started with the range of [0, 20) with calculation col % row % 29 % 20, which required 8 wasted characters in the mapping.

\$\endgroup\$
4
\$\begingroup\$

Haskell, 42 37 bytes

x#y="_1425__#9__*70836"!!mod(2*x+y)18

Just some math to index a string. Input order is <column> # <row>, e.g. 1336 # 697.

Try it online!

Edit: @flawr found a formula that works on shorter string. Overall -5 bytes. Thanks!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I just wrote a little program to optimize your approach, and it appears you can save a few bytes: x#y="_1425__#9__*70836"!!mod(2*x+y)18 \$\endgroup\$
    – flawr
    Commented Aug 19, 2017 at 21:49
3
\$\begingroup\$

MATL, 23 bytes

13*+79\'186#294*3750'w)

Inputs are: column frequency, then row frequency.

Try it online!

Explanation

Multiplying the column frequency by 13, adding the row frequency, and computing modulo 79 gives a different value for each of the 12 pairs of inputs.

13*               % First input (implicit) times 13
+                 % Add to second input (implicit)
79\               % Modulo 79
'186#294*3750'    % Push this string
w                 % Swap
)                 % Index
\$\endgroup\$
2
\$\begingroup\$

Jelly, 19 bytes

DḢ×3++6ị9R;“*0#  ”¤

Try it online!

Takes input as row, column in two arguments.

This uses 3*<first digit of row> + <column> + 6 % 14 to give a different value for each. This is indexed into [1,2,3,4,5,6,7,8,9,"*","0","#"," "," "] to give the output. The spaces could really be any character; they are just buffer to create an implicit mod 14.

Low level

DḢ×3++6ị9R;“*0#  ”¤
D                     - digits (of <row>)
 Ḣ                    - head (get first element)
  ×3                  - multiply by 3
    +                 - add (<column>)
     +6               - add 6
       ị              - index into:
                  ¤   - the nilad:
        9R              - range(9)
          ;             - concatenate
           “*0#  ”      - the string "*0#  "
\$\endgroup\$
2
\$\begingroup\$

Jelly, 24 bytes

%157ị9R;“*0#”¤s3¤ị@⁹%11¤

Try it online!

\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 34 bytes

(a,b)=>'806739214*#5'[a*b%2785%12]

Try it online!

Python 3, 39 bytes

lambda a,b: '806739214*#5'[a*b%2785%12]

Try it online!

row,column can be supplied in any order.

\$\endgroup\$
1
\$\begingroup\$

Befunge, 34 bytes

&"~"/9-4*&"d"/6-+1g,@
147*2580369#

Try it online!

Explanation:

&"~"/9-4*                (Get number / 126 - 9) * 4 = 0, 4, or 8
         &"d"/6-         Get number / 100 - 6 = 0, 1, 2, or 3
                +        Add the above results - this becomes the x-coordinate in the "lookup table"
                 1g,@    Get a value on row 1 column x, output it, and end
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.