设置我的自动拨号器


16

过去,电话自动拨号器使用打孔卡,每列要拨打的号码中的每一列都有一栏。列有七行。前三行分别代表数字(1,2,3),(4,5,6)和(7,8,9)。最后三行将这种排列旋转90°:(1,4,7),(2,5,8)和(3,6,9)。中间的行用于0。任何数字1-9都会打两个孔-前三个行一个,下三个行一个。零将只打中间行。让我们可视化数字6的打孔列(.x打孔,已打孔,左侧的指南仅用于说明编码):

123 .
456 x
789 .
 0  .
147 .
258 .
369 x

我们寻找哪些行包含我们要拨打的号码。对于6,这是第二行,第九行。这两行被打孔,其余五行未打孔。这是所有0-9数字的打孔模式:

    0 1 2 3 4 5 6 7 8 9
123 . x x x . . . . . .
456 . . . . x x x . . .
789 . . . . . . . x x x
 0  x . . . . . . . . .
147 . x . . x . . x . .
258 . . x . . x . . x .
369 . . . x . . x . . x

您的目标是(编写程序或函数)为我打这些卡。

输入:一个数字,采用任何合理的格式(字符串,整数,整数列表等),且不得超过9999999999999。

输出:与数字输入相对应的打孔网格。您不需要上面显示的标题或多余的空格,只需要打孔的列本身即可。可以使用前导/后跟换行,只要行/列之间的空格一致,也可以。可以说,只要它们是一致的,就可以将任何(非空白)字符用于打孔,而将其他任何字符用于打孔(这很明显,请指定您使用的字符)。

这是代码高尔夫球,因此最短的代码获胜。不允许出现标准漏洞

测试用例(全部.用于未x打孔,已打孔):

In: 911
Out: .xx
     ...
     x..
     ...
     .xx
     ...
     x..

In: 8675309
Out: ....x..
     .x.x...
     x.x...x
     .....x.
     ..x....
     x..x...
     .x..x.x

In: 5553226
Out: ...xxx.
     xxx...x
     .......
     .......
     .......
     xxx.xx.
     ...x..x

2
完全不需要解决这个问题,但是这里有这些卡/设备的整洁的小画廊
brhfl

您可以将任何字符用于打孔,而将其他任何字符用于打孔,则表示任何非空白字符?
暴民埃里克(Erik the Outgolfer)'18年

是的,我想这样做会更好,因为在其他地方允许使用空格。并且为了能够看到。将在编辑,谢谢。
brhfl

1
很酷的挑战...试图写一个FORTRAN 77的答案,但idk如何打高尔夫球
qwr

@qwr随意创建“ Fortran打高尔夫球技巧”帖子。
mbomb007 '18

Answers:



3

Pyth,25个字节

.tm?djNmX*3NkZ.Dtd3X*7N3Z

用途0用于冲压和"为未穿孔。
在这里尝试

说明

.tm?djNmX*3NkZ.Dtd3X*7N3Z
  m                      Q  For each number in the (implicit) input...
   ?d                       ... if the number is nonzero...
              .Dtd3         ... get (n - 1) divmod 3...
       mX*3NkZ              ... replace each position in `"""` with `0`...
     jN                     ... and stick them together with `"`. ...
                   X*7N3Z   ... Otherwise, `"""0"""`.
.t                          Transpose the result.

3

JavaScript(ES6),60 54字节

将输入作为整数数组。返回一个二进制矩阵,其中0 =未打孔/ 1 =打孔。

a=>[14,112,896,1,146,292,584].map(n=>a.map(i=>n>>i&1))

在线尝试!


3

05AB1E 16 15字节

使用01

ε9ÝÀ3ôD¨ø«¢O}ø»

在线尝试!

说明

ε           }     # apply to each digit in input                
 9Ý               # push the range [0 ... 9]
   À              # rotate left
    3ô            # split into pieces of 3
      D¨          # duplicate and remove the last digit (0)
        ø         # transpose
         «        # append
          ¢O      # sum the counts of each in the current digit     
             ø    # transpose
              »   # format output



2

Python 3中84 80个字节

def f(s):[print(*[int(i in[~-n//3,6--n%3-3*(n<1)])for n in s])for i in range(7)]

在线尝试!


第五行和第六行似乎有些时髦(它们似乎被翻转了)。例如[1,2,3]应该向下形成一条对角线。
brhfl

@brhfl感谢您告诉我,将其修复
ovs

2

C(铛)108个 107字节

c,i;f(*q){char*r;for(i=~0;i++<6;puts(""))for(r=q;c=*r++;c-=48,putchar(".X"[(c--?16<<c%3|1<<c/3:8)>>i&1]));}

在线尝试!

将输入数字作为字符串。.X示例中一样输出输出。

学分

-1个字节,感谢@ ASCII-only


1
107,并删除了标头,否则您需要在字节数中包含标头
ASCII,

能否请您指出我的普遍共识,即对于函数解决方案(不是完整程序),必须将头文件包含的内容计为字节数
GPS,

123
ASCII仅

建议putchar(".X"[(c--?16<<c%3|1<<c/3:8)>>i&1]))c-=48而不是c-=48,putchar(".X"[(c--?16<<c%3|1<<c/3:8)>>i&1]))
ceilingcat '18

2

J31 20字节

-11个字节感谢FrownyFrog!

(e."1],0,|:)1+i.@3 3

在线尝试!

J,31个字节

1*@|:@:#.(a,0,|:a=.1+i.3 3)=/~]

在线尝试!

将输入作为数字列表

0-未打孔,1-打孔

说明:

   a=.1+i.3 3 - generates the matrix and stores it into a
1 2 3
4 5 6
7 8 9

   (a,0,|:a=.1+i.3 3) - generates the entire comparison table 
1 2 3
4 5 6
7 8 9
0 0 0
1 4 7
2 5 8
3 6 9

   ]=/ - creates an equality table between the input and the comparison table

 ((a,0,|:a=.1+i.3 3)=/~]) 9 1 1
0 0 0
0 0 0
0 0 1
0 0 0
0 0 0
0 0 0
0 0 1

1 0 0
0 0 0
0 0 0
0 0 0
1 0 0
0 0 0
0 0 0

1 0 0
0 0 0
0 0 0
0 0 0
1 0 0
0 0 0
0 0 0

  1*@|:@:#. - adds the tables, transposes the resulting table and finds the magnitude

  (1*@|:@:#.(a,0,|:a=.1+i.3 3)=/~])  9 1 1
0 1 1
0 0 0
1 0 0
0 0 0
0 1 1
0 0 0
1 0 0

@FrownyFrog谢谢!您一如既往的辉煌!
Galen Ivanov '18



1

木炭,28字节

E⁴⭆θI⁼ι÷﹪⊖λχ³E³⭆θI∧Iλ¬﹪⁻⊖λι³

在线尝试!链接是详细版本的代码。使用0/1,但可以以1字节为代价支持任意字符:在线尝试!。说明:

E⁴              Loop from 0 to 3
  ⭆θ            Loop over input string and join
           λ     Current character
         ⊖      Cast to integer and decrement
        ﹪  χ    Modulo predefined variable 10 (changes -1 to 9)
       ÷    ³   Integer divide by literal 3
     ⁼ι         Compare to outer loop variable
    I           Cast to string
                Implicitly print each outer result on a separate line

E³              Loop from 0 to 2
  ⭆θ            Loop over input string and join
            λ   Current character
           ⊖    Cast to integer and decrement
          ⁻  ι  Subtract outer loop variable
         ﹪    ³ Modulo by literal 3
        ¬       Logical not
       λ        Inner loop character
      I         Cast to integer
     ∧          Logical and
    I           Cast to string
                Implicitly print each outer result on a separate line

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.