高尔夫代码:电话号码到单词 [英] Code Golf: Phone Number to Words

查看:104
本文介绍了高尔夫代码:电话号码到单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于SO上代码高尔夫球的指南

我们都看到过拼写成字的电话号码:1-800-BUY-MORE,等等.

We've all seen phone numbers that are put into words: 1-800-BUY-MORE, etc.

您可以编写的最短代码量将为7位美国电话号码生成所有可能的单词组合.

What is the shortest amount of code you can write that will produce all the possible combinations of words for a 7 digit US phone number.

输入将是一个七位数的整数(或字符串,如果更简单的话),并假定输入格式正确.

Input will be a seven-digit integer (or string, if that is simpler), and assume that the input is properly formed.

输出将是包含七个字符的字符串的列表

Output will be a list of seven-character strings that

例如,将产生数字428-5246

For instance, the number 428-5246 would produce

GATJAGM
GATJAGN
GATJAGO
加特贾姆
GATJAHN
GATJAGO
GATJAIM
加泰因
加泰奥 等等.....

GATJAGM
GATJAGN
GATJAGO
GATJAHM
GATJAHN
GATJAGO
GATJAIM
GATJAIN
GATJAIO and so on.....

获胜标准将是来自任何语言的字符最少的代码,该代码会产生每种可能的字母组合.

Winning criterion will be code from any language with the fewest characters that produces every possible letter combination.

附加说明:

  • 为了使它更有趣,请用文字 只能通过使用 北美经典上的字母 带有三个字母的键盘电话 每个数字如此处定义. 这表示Z和Q排除在外.
  • 对于数字"1",请放置一个空格.
  • 对于数字'0',请加上连字符'-'
  • To make it more interesting, words can be formed only by using the letters on a North American Classic Key Pad phone with three letters per number as defined here.That means that Z and Q are excluded.
  • For the number '1', put a space.
  • For the number '0', put a hyphen '-'

由于将输出识别为真实的英语单词而获得的奖励积分.好吧,不是真的. ;-)

Bonus points awarded for recognizing output as real English words. Okay, not really. ;-)

已添加:好吧,让我们开始吧,"Nick's Modified North America Classic Key Pad"在6键上带有一个"O"(哦,不是零).

Added: Okay, lets go with "Nick's Modified North American Classic Key Pad" which has an 'O' (oh, not zero) on the 6 key.

推荐答案

q, 52 39个字符

q, 52 39 chars

(cross/)(3 cut"--- ",.Q.A except"QZ")

q是从右向左求值的.

q is evaluated left of right.

.Q.A包含向量"ABC ... XYZ"

.Q.A contains the vector "ABC...XYZ"

except返回x,不包括y中的值

except returns x excluding values in y

将-"连接到修改后的char向量上

join "--- " to the modified char vector

切成3块

cross返回所有可能的组合,并应用于所有块

cross returns all possible combinations, and is applied across all chunks

q)(cross/)(3 cut"---   ",.Q.A except"QZ")[4 2 8 5 2 4 6] 
"GATJAGM"
"GATJAGN"
"GATJAGO"
"GATJAHM"
"GATJAHN"
"GATJAHO"
"GATJAIM"
"GATJAIN"
"GATJAIO"
....

这篇关于高尔夫代码:电话号码到单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆