Simple DTMF decoding: find the phone key!

11

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!

Arnauld

Posted 2017-08-19T19:03:28.457

Reputation: 111 334

Answers

2

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#  "

fireflame241

Posted 2017-08-19T19:03:28.457

Reputation: 7 021

8

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.

Justin Mariner

Posted 2017-08-19T19:03:28.457

Reputation: 4 746

4

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!

nimi

Posted 2017-08-19T19:03:28.457

Reputation: 34 639

1I 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 – flawr – 2017-08-19T21:49:07.423

3

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

Luis Mendo

Posted 2017-08-19T19:03:28.457

Reputation: 87 464

2

Jelly, 24 bytes

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

Try it online!

Erik the Outgolfer

Posted 2017-08-19T19:03:28.457

Reputation: 38 134

2

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.

Doug Coburn

Posted 2017-08-19T19:03:28.457

Reputation: 141

1

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

user55852

Posted 2017-08-19T19:03:28.457

Reputation: