模拟7段显示


24

任务

任务是显示7段显示器的128种可能状态中的任何一种 。

你的程序应该接受7个字符(“位”)是一个字符串01。输入的第一位对应下图的A段,第二位对应B,依此类推(忽略dp):

7段

显示的方式取决于您-单个Unicode或ASCII符号, ASCII艺术作品,粗体或其他任何形式。但是,每个输入必须具有自己的不同输出。如果您提出了一些幻想,我相信您可以通过展示一些例子来收获赞誉。

显示屏的全部128种可能状态为:

状态

规则

  • 高尔夫
  • 就像我说的,任何类型的输出都是允许的,但是如果您指定它会很好。
  • 输入可以是stdin或命令行参数。

例子

输入项

1101101

输出量

作为ASCII / Unicode:
2
不同种类的ASCII艺术(我不太擅长此事)
 _   ╺┓  ╒╗   ---
 _|  ┏┛  ╔╝     |
|_   ┗╸  ╚╛   ---
              |
              ---


@DavidCarraher:是的,它们是相关的;我什至自己链接了它。但是,我会说这有点困难,因为您还有118个“数字”要生成。另一个问题的大多数(?)答案在这里不起作用,或者必须大量重写。同样,在这里您不需要编码不同的数字,因此其他优化应该是可能的。
daniero 2012年

你是对的。感谢您指出了这一点。
DavidC 2012年

我们必须使用您提供的编码吗?例如“ 1101101”应始终代表“ 2”?
ardnew

@ardnew:是的。输入中位的位置应映射到第一张图片中段A到G的字母顺序。
daniero

Answers:


5

J(51)

1 2 1#"1[5 3$' #'{~,|:>0;(88707#:~7#7){>".&.>1!:1[1

输出:

1101101
 ## 
   #
 ## 
#   
 ## 

1
只需一点努力,即可将其减少到38个字符1 2 1#"1' #'{~5 3$,0,.502 A.".&>1!:1]1
algorithmhark

16

C,106

如果允许重命名程序“ W00WG5WW1GW66WG4WW2GW33WG”,则大小为74个字符

main(int i,char**s){
    for(s[0]="W00WG5WW1GW66WG4WW2GW33WG";i=*s[0]++;putchar(s[1][i&7]-49?i==71?10:32:42));
}

运行:

./a.out 1101101
 ** 
   *
 ** 
*   
 ** 

笔记:

选择“ W”和“ G”(0x47和0x57),使得值&7 = 7,即它们安全地索引了终止输入字符串的空字符。


15

脑干-224

++++++++++[>+>+++<<-]
>>++>,>,>,>,>,>,>,
<<<<<<<.
>[<+.->-]<<.
>>
>>>>>[<<<<<+<+>>>>>>-]<<<<<<.>[<->-]<.>>[<<+.->>-]<<<.>.
>>>>>>>[<<<<<<<+.->>>>>>>-]<<<<<<<<.
>>>>>>[<<<<+<+>>>>>-]<<<<<.>[<->-]<.
>>>[<<<+.->>>-]<<<<.>.
>>>>[<<<<+.>]

使用感叹号打印:

 ! 
! !
 !
! !
 !

不是最易读,但也不是太可怕。

惊讶的是它离最后的位置有多近。


13

后记121 107

1 12 moveto{}5 0{0 -5 rmoveto}0 5 0 5 -5 0 0 -5 0 -5 5 0
n{49 eq{rlineto}{rmoveto}ifelse exec}forall stroke

需要n定义为要处理的字符串,因此调用

gs -g7x14 -sn=1101101 lcd.ps

要得到

image of number two

完整的是

complete set of characters


11

Mathematica:135 129 118,图像显示

Image[MorphologicalComponents@Import@"http://goo.gl/j3elE" /. 
      Thread[Range@7 -> IntegerDigits[#, 2, 7][[{7, 2, 6, 1, 3, 5, 4}]]]] &

空格“为了清楚”

enter image description here

编辑

对于那些挑剔的站点用户:不使用外部掩码:

Image[MorphologicalComponents[ColorNegate@Rasterize@8, CornerNeighbors -> False] /. 
    Thread[Range@7 ->IntegerDigits[#, 2, 7][[{7, 2, 6, 1, 3, 5, 4}]]]] &

该代码似乎不完整。我认为您不希望您的程序以终止&
DavidC 2012年

@DavidCarraher这是一个函数,因此以结尾&
belisarius博士2012年

是的,但是它不适用于任何东西。一个人如何获得输出?
DavidC 2012年

2
@belisarius我仍然不喜欢您嵌入外部资源的事实。
FUZxxl 2012年

1
我认为删除我以前的评论没有任何意义,因为这会使其他人更难以关注此讨论。您导入的外部数据虽然很有趣,但是却不是认真的高尔夫答案代码的一部分。-1
FUZxxl 2012年

10

APL,58 55

' _|'[1+3 3⍴0,x[1],0,(x←1 2 2 1 2 2 1×⍞='1')[6 7 2 5 4 3]]

输入示例:

1101101

输出:

 _ 
 _|
|_ 

⍞='1' 将输入作为字符数组并将其转换为数字数组。

1 2 2 1 2 2 1×⍞='1'将该数组转换为:0对于空白,1对于_2对于|

(x←1 2 2 1 2 2 1×⍞='1')[6 7 2 5 4 3] 将该数组分配给变量 x并重新排序以表示段F,G,B,E,D,C

0,x[1],0,(x←1 2 2 1 2 2 1×⍞='1')[6 7 2 5 4 3] 将一个空白,段A和另一个空白连接到前面

3 3⍴0,x[1],0,(x←1 2 2 1 2 2 1×⍞='1')[6 7 2 5 4 3] 重塑为3x3矩阵

1+3 3⍴0,x[1],0,(x←1 2 2 1 2 2 1×⍞='1')[6 7 2 5 4 3] 转换为基于1的索引

最后使用字符串' _|'将索引转换为字符


编辑

' _|'[1+3 3⍴(0,1 2 2 1 2 2 1×⍞='1')[1 2 1 7 8 3 6 5 4]]

通过将a连接0到数组前面并使用重复的索引来减少3个字符,从而防止了变量分配


如果您的APL支持它,我认为from函数{比方括号索引短1个字符[]
luser droog 2015年

9

PHP 66字节

<?for(;11>$i;)echo++$i&3?$argv[1][md5(¡æyÚ.$i)%8]?$i&1?~ƒ:_:~ß:~õ;

略有改善使用md5魔术公式,但是需要额外的3个字节的二进制:
¡æ,和Ú是字符161,230和218分别。如果直接复制,并保存为ANSI格式,它应该可以正常工作。


PHP 73(70)字节

<?for($s=327638584;3<$s;)echo++$i&3?$argv[1][7&$s/=8]?$i&1?'|':_:' ':'
';

如果您允许我输入三个二进制字符,则可以减少到70个字节

<?for($s=327638584;3<$s;)echo++$i&3?$argv[1][7&$s/=8]?$i&1?~ƒ:_:~ß:~õ;

其中ƒßõ分别是字符131、223和245。

接收输入作为命令行参数。用法示例:

$ php seven-seg.php 1101101
 _
 _|
|_

$ php seven-seg.php 0111011

|_|
 _|

我试图运行你的代码,但我得到错误的负载:(我不明白你的逻辑,但似乎有趣。
D34dman

1
@ D34dman它将产生的唯一消息是通知(未定义的变量等)。这些可以关闭php.ini(默认情况下已经关闭),或进行测试,您可以在脚本之前添加以下代码:<? error_reporting(E_ALL & ~E_NOTICE); ?>
primo 2013年

太棒了!我工作了:D Naice!
D34dman

7

的JavaScript + jQuery的+ HTML + CSS(210 201)

此解决方案使用CSS精灵和提供的图像作为示例

HTML(3)

<a>

CSS(82 71)

感谢xem提供的“ background:url ”技巧:

a{background:url(//bit.ly/VesRKL);width:13px;height:23px;display:block}

JavaScript(为便于阅读,删除此处添加的换行符后为125)

i=prompt();
x=-parseInt(i.substr(0,3),2)*23;
y=-parseInt(i.substr(3),2)*13.75;
$('a').css('background-position',y+'px '+x+'px');

在线测试:http//jsfiddle.net/zhqJq/3/


1
嘿,但是图像的17.937字节呢?;)
Thomas W.

@ThomasW。我不知道这是否也应该计算在内。让我们将其留给OP来决定。
克里斯蒂安·卢帕斯库

您可以在CSS上使用<p>标记并避免使用display:block以节省空间
Roberto Maldonado 2014年

background-image:url(bit.ly/VesRKL); => background:url(// bit.ly/VesRKL);
xem

@xem感谢您的提示;我已经编辑了答案
克里斯蒂安·卢帕斯库

6

R(65个字符):

plot((3^(1i*1.5:-4.5)*(1:7!=7)),col=strsplit(readline(),'')[[1]])

依靠一些先验数字的一些宽松近似...


6

Python 2-65

s=raw_input()+'0\n'
for i in`0x623C239E38D2EAA1`:print s[int(i)],

例:

echo 1101101|python2 7seg.py
0 1 0 
0 0 1 
0 1 0 
1 0 0 
0 1 0

5

PostScript:53个二进制,87个ASCII 52二进制,86 ASCII

使用二进制令牌对程序进行十六进制转储:

$ hexdump -C lcd_binary.ps 
00000000  28 34 34 30 34 30 38 30  34 30 34 30 30 30 30 34  |(440408040400004|
00000010  30 34 30 34 34 34 34 34  38 34 38 30 38 29 7b 7d  |0404444484808){}|
00000020  92 49 6e 7b 92 70 31 92  04 92 96 92 6b 92 63 92  |.In{.p1.....k.c.|
00000030  a7 7d 92 49                                       |.}.I|
00000034

下载此文件进行尝试。

使用ASCII令牌:

(4404080404000040404444484808){}forall
n{not 1 and setgray moveto lineto stroke}forall

第一个forall循环将所有必需的坐标放入堆栈中。坐标存储在字符串中以最小化所需空间。坐标是相反的顺序,即最后4个字符用于段A。为此段我们从(0,8)到画一条线(4,8)(实际上,我们必须在所有坐标上加上48,因为forall将所有ASCII码都放在了堆栈上)。

第二个forall循环遍历输入字符串中的所有0s和1s,并将它们转换为灰度值。0s绘制为白色(灰色值1),1s绘制为黑色(灰色值0)。然后,我们使用第一个forall循环在堆栈上留下的坐标来绘制线条。

就像Geoff Reedy的一样,使用Ghostscript调用程序:

gs -sn=1101101 lcd.ps

显示: Sample output


我认为您可以将替换neg 49 add(很棒的顺便说一句)1 and
luser droog 2012年

@luserdroog:出色的按位运算符,还没有想到。但这一定是not 1 and吧?仍以ASCII和二进制形式保存一个字节。
Thomas W.

我觉得必须有一个1bit位图的巧妙方法。但是bitshift这个词很长。
luser droog 2012年

但这只是一个两字节的二进制令牌
Thomas W.

是的 但这仍然让我感觉像是在作弊。:)我觉得在诉诸二进制文件之前,我需要对可读源做尽可能多的事情。
luser droog 2012年

4

APL 101 86 73 69

m←45⍴' '⋄m[¯40+⎕av⍳(⍎∊3/' ',¨⍕⍞)/')*+16;EJOQRSAFK-27=>?']←'⎕'⋄9 5⍴m

通过from从屏幕输入

1101101

生成由空格和composed组成的9x5字符矩阵,如下所示:

 ⎕⎕⎕
     ⎕
     ⎕
     ⎕
 ⎕⎕⎕
⎕
⎕
⎕
 ⎕⎕⎕

七位数转换为分区向量以选择⎕坐标。


我的头好痛...
Rob

4

数学112 103 100 96 88,利用图形

HighlightGraph[z=GridGraph@{3,2},Pick[EdgeList[z][[{3,4,1,2,6,7,5}]],Characters@#,"1"]]&

enter image description here

Using it to show a calculator display

l = {7-> 7, 1-> 6, 0-> 63, 8-> 127, 9-> 111,3 -> 79, 5-> 109,  2-> 91, 4-> 102, 6-> 125}; 
GraphicsRow[
  HighlightGraph[z = GridGraph[{3,2}, EdgeStyle-> {White}, GraphHighlightStyle-> {"Thick"}], 
    EdgeList[z][[{3, 4, 1, 2, 6, 7, 5}]][[IntegerDigits[#, 2, 7] Range@7]]] & /@
            (IntegerDigits[8736302] /. l)]

Mathematica graphics


您期望什么样的输入?既不[123]是[“ 123”],也不是IntegerDigits[123]为我工作。我只有z,没有突出显示。
DavidC

@dude尝试`HighlightGraph [z = GridGraph @ {3,2},Pick [EdgeList [z] [[{3,4,1,2,2,6,7,5}]],字符@#,“ 1”] ]&@“ 1111111”``:)
belisarius博士

3

巨蟒(107)

绝对更适合打高尔夫球。

a=map(int,raw_input())
for i in(0,6,3):print' .. '*a[i]+('\n'+' .'[a[5-i/6]]+'  '+' .'[a[1+i/6]])*(2*(i!=3))

输出:

1101101
 .. 
   .
   .
 .. 
.   
.   
 .. 

说明:

a is a list of booleans extracted from the input.
When you multiply a string with a number, it will return the string repeated (number) times.
If that number happens to be zero, it returns an empty string.
i is iterated through 0 (pos A), 6 (pos G), and 3 (pos D).
' .. ' will print either section A, G, or D, depending on the value of i.
([string here])*(2*(i!=3)) will print [string here] twice only if i!=3.
Breaking down [string here]:
 - '\n' will print a newline for each repetition.
 - '  ' is the null space between horizontal sections.
 - ' .'[(bool)] will return either ' ' if (bool) is 0, and '.' if (bool) is 1.
 - 5-i/6 will return 5 if i=0 and 4 if i=6. a[5] is section F and a[4] is section E.
 - 1+i/6 will return 1 if i=0 and 2 if i=6. a[1] is section B and a[2] is section C.

3

Python 2.7(93个字符):

print (' {0}\n{5} {1}\n {6}\n{4} {2}\n {3}').format(*map(lambda x:int(x)and'*'or' ',raw_input()))

说明:

通过stdin输入,使用临时三元运算符*为true 给出空格,为false 给出空格。取这些值,并将其插入7位数显示格式的format语句中。如果显示器的工作方式如下,则最多为83个字符:

 a
b c
 d
e f
 g

但是订购会使它更长。有人有办法解决吗?

例:

$ ./7seg.py
111000

 *
  *

  *

$ ./7seg.py


1111111

 *
* *
 *
* *
 *

1
很好,但是lambda似乎是不必要的:print' {0}\n{5} {1}\n {6}\n{4} {2}\n {3}'.format(*[' *'[i=='1']for i in raw_input()]);)也不需要在括号和空格的打印语句。
daniero 2013年

哇!我不知道您可以将布尔值放入索引器中。谢谢:-)
Brigand

Np。另外,也可以使用和>'0'代替=='1'input()(带有反引号,但由于此处的格式而不会显示)raw_input()
daniero

仅供参考,如果代码中需要反引号,则可以使用三重反引号x = `input()`
Brigand

凉。然后我今天也学到了一些东西:)
daniero

3

我以为我们需要一个狡猾的答案...

Clojure,159个字符

(print(apply str(flatten(interpose\newline(partition 3(map(fn[x](if(= x\1)\o" "))(str" "(apply str(interpose" "(map(vec(read-line))[0 5 1 6 4 2 3])))" ")))))))

上面的代码将在REPL中运行,并提供正确的答案。例如:

1111111
 o 
o o
 o 
o o
 o 

对其进行少量修改即可抛出数字:

(doseq [i ["1111110" "0110000" "1101101" "1111001" "0110011" "1011011" "1011111" "1110000" "1111111" "1111011"]]
(println (apply str(flatten(interpose\newline(partition 3(map(fn[x](if(= x\1)\o" "))(str" "(apply str(interpose" "(map(vec i)[0 5 1 6 4 2 3])))" "))))))) 
(println))

产量:

 o 
o o

o o
 o 


  o

  o


 o 
  o
 o 
o  
 o 

 o 
  o
 o 
  o
 o 


o o
 o 
  o


 o 
o  
 o 
  o
 o 

 o 
o  
 o 
o o
 o 

 o 
  o

  o


 o 
o o
 o 
o o
 o 

 o 
o o
 o 
  o
 o 

nil

不容易阅读,但是它们在那里!


3

JavaScript 123

s=prompt(i=o='');for(m=' 0516423';i++<15;i%3==0?o+='\n':1)o+=' ─│'[~i%2&(A=+s[+m[~~(i/2)]])+(A&+'110'[i%3])];console.log(o)

如果我们仅将一个字符用于“ on”状态,那么我可以将字符数降低(101),但它的可读性较差:

s=prompt(i=o='');for(m=' 0516423';i++<15;i%3==0?o+='\n':1)o+=' ■'[~i%2&s[+m[~~(i/2)]]];console.log(o)

+1这令人印象深刻。我仍在尝试对其进行反向工程。它已经教了我几件事!
guypursey

2

附言136

不是赢家,而是另一种方法。

15 string exch{1 and 255 mul}forall
[7 3 9 13 11 5 1]{count 1 sub index 3 1 roll exch put}forall
3 5 8[.02 0 0 .05 0 0]{}image showpage

期望输入字符串在堆栈中:

$ echo '(1101101)'|cat - 7seg.ps |gs -sDEVICE=png16 -sOutputFile=6c.png -

这更糟。294制作一个“二进制”位图。我花了一段时间来记住,每一行都填充为偶数字节。因此,一个3x5位图是5个字节,其中3 msb位有效。

2#1101101
(12345)exch
2 copy 64 and 0 exch put %A
2 copy 2 and 6 bitshift 2 index 32 and or 1 exch put %F B
2 copy 1 and 6 bitshift 2 exch put %G
2 copy 4 and 5 bitshift 2 index 16 and 1 bitshift or 3 exch put %E C
2 copy 8 and 3 bitshift 4 exch put
pop
3 5 1[.02 0 0 .02 0 0]{}image showpage

输出与其他输出一样丑陋。:(

好吧,这看起来不错。190

编辑:这是颠倒和倒退。立即修复。

(1101101)
{neg 49 add 255 mul
1 string dup 0 4 3 roll put}forall
(\377){@/g/f/e/d/c/b/a}{exch def}forall
@ a a @
b @ @ f
b @ @ f
@ g g @
c @ @ e
c @ @ e
@ d d @
4 7 8[.01 0 0 .01 0 0]{}image showpage

这显示了一些有趣的模式。某个地方还有错误吗?
Thomas W.

嗯。是的 (1111110)看起来不像零。这只是一个放大的字节图。我想盒子太简单了。:(
luser droog 2012年

我认为这有点像这种位图方法。我不确定如何使其不难看。
luser droog 2012年

这里有一些简短的评论。
luser droog

2

Mathematica 264

使输出看起来正确需要许多字节,因此这次没有雪茄。但是无论如何,这是冗长的代码(264个字符)。

{a, b, c, d, e, g} = {{-1, 5}, {1, 5}, {1, 3}, {1, 1}, {-1, 1}, {-1, 3}};
f@n_ := Graphics[{Yellow, Thickness[.1], CapForm["Round"],
   Line /@ {{g, c}, {g, a}, {g, e}, {e, d}, {d, c}, {c, b}, {b, a}}[[Flatten@
   Position[IntegerDigits[n, 2, 7], 1]]]}, 
   Background -> Blue, PlotRange -> {{-1, 1}, {1, 5}}, PlotRangePadding -> 1]

完整的字符集:

GraphicsGrid[Partition[Table[f[p], {p, 0, 128}], 16]]

characteris

数字:

{f[63], f[6], f[91], f[79], f[102], f[109], f[125], f[7], f[127], f[111]}

enter image description here


2

PHP-155个字符

<?php
$y=array("   \n"," - \n","   \n","  |\n","|  \n","| |\n"); $x = $argv[1]; echo $y[$x[0]].$y[2*$x[6]+$x[2]+2].$y[$x[7]].$y[2*$x[5]+$x[3]+2].$y[$x[4]];

如果我们使用php 5.4类型数组声明,它将是150个字符,但是我没有在笔记本电脑上安装该声明,因此无法对其进行测试。

采样输出。

enter image description here

说明:

首先,我将7段显示分为五行和三列。在中间的第一行中有第一行,第三行和第五行havimg'-',否则为空格。

第二行和第四行具有管道“ |” 第一列和最后一列中的字符。现在,这些字符的存在应该由输入值来指导。

我创建了一个查找表,它基本上是两个查找表。第一个用于计算第一行,第三行和第五行的值。另一个偏移量为2(第三项),用于计算第二行和第四行。


2

Java-204个字符

class A{public static void main(String[]a){char[]c=new char[7];for(int i=0;i<7;i++)c[i]=a[0].charAt(i)==49?i%3==0?95:'|'):32;System.out.printf(" %c %n%c%c%c%n%c%c%c",c[0],c[5],c[6],c[1],c[4],c[3],c[2]);}}

样本输出:

 _ 
 _|
|_ 

格式正确:

class A {
    public static void main(String[] a) {
        char[] c = new char[7];
        for (int i = 0; i < 7; i++)
            c[i] = a[0].charAt(i) == 49 ? (i % 3 == 0 ? 95 : '|') : 32;
        System.out.printf(" %c %n%c%c%c%n%c%c%c", c[0], c[5], c[6], c[1], c[4], c[3], c[2]);
    }
}

真希望我能避免for循环,但是我尝试了其他一些事情,而且它们都更长了。可能有更好的方法,但这是我第一次尝试打高尔夫球。(而且Java就像最糟糕的语言一样,这就是为什么我认为它会很有趣。)即使Brainfuck也击败了我,但至少我的输出看起来更好。

编辑:可以摆脱“公开”上课,为我节省7个字符!

感谢daniero,向我展示了printf!(已保存18个字符)

重新编写输出格式,将字符文字更改为十进制,保存12个字符。


欢迎来到codegolf.se!爪哇介绍了printf方法的几个版本返回,这基本上是printlnformat在一个(如C函数); 这将为您节省一些字符,
daniero

这是另一个技巧:您可以将for循环的“主体” 和更新部分组合为一个,从而保存一个字符:for(int i=7;i>0;c[--i]=a[0].charAt(i)==49?(i%3==0?95:'|'):32);
daniero

1

VBA-263

我认为这很丑陋,但有效。我在查看正确的位顺序时遇到麻烦,因此我要从其他人的答案中推断出来。即使该段是错误的,代码长度也应保持相同。

Sub d(b)
Dim c(1 To 7)
For a=1 To 7
c(a)=Mid(b,a,1)
Next
x=" - "
y="|"
z=" "
w="   "
v=vbCr
MsgBox IIf(c(1)=1,x,w) & v & IIf(c(6)=1,y,z) & z & IIf(c(2)=1,y,z) & v & IIf(c(7)=1,x,w) & v & IIf(c(5)=1,y,z) & z & IIf(c(3)=1,y,z) & v & IIf(c(4)=1,x,w)End Sub

1

VBScript-178个字符

m=Split("2 7 11 10 9 5 6")
s=" _ "&vbCr&"|_|"&vbCr&"|_|"
For x=1 To 7
If Mid(WScript.Arguments.Item(0),x,1)=0 Then r=m(x-1):s=Left(s,r-1)&" "&Right(s,Len(s)-r)
Next
MsgBox s

谢谢!夫妇的骨头错误使我损失了6个字符。即使要获得函数行参数的时间太长,我也几乎可以将其减小到VBA的大小。
Comintern

除非您的代码没有换行符,否则您也必须计算它们。根据我的数量,这有178个字符。
manatwork 2013年

1

果酱-29

l0N]s7078571876784728737Ab\f=

CJam是我正在开发的一种新语言,类似于GolfScript- http: //sf.net/p/cjam 。这里是解释:

l从输入读取一行
0是数字0,
N是一个预初始化到换行符字符串的变量
],将堆栈中的元素收集到一个数组中,
s将一个值(数组)转换为字符串,从而在给定的输入后附加一个零和一个换行符
7078571876784728737是数字(与python中使用的数字相同,但是在十六进制中)
A是一个预初始化为10的变量,
b它执行基本转换,生成数组[7 0 7 8 ... 3 7]
\交换堆栈上的最后两个值在输入字符串(加上零和换行符)和每个数字7、0、7 ...上
f=应用=运算符(此处为索引数组访问)
。索引7对应于附加的零,而索引8对应于附加的换行。

我的python解决方案做的完全一样(除了数字分隔是通过字符串转换完成的)


我在这里看什么 愿意提供代码的简要说明吗?
daniero

@daniero我添加了一个解释
aditsu 2014年

1

VBA,188个字符

请注意,如果仅包含必需的空格,则必须键入 188个字符-当您将其复制到VBA编辑器中时,IDE会将其展开。

Sub f(i)
Dim c() As Byte
m=Split("1 6 10 9 8 4 5")
c=StrConv(" _  |_| |_|",128)
c(3)=10
c(7)=10
For x=1 To 7
If Mid(i,x,1) = 0 Then c(m(x-1))=32
Next
MsgBox StrConv(c,64)
End Sub

可悲的是,VBScript没有强类型的Byte数组,或者使用此方法可能会短得多。


1

Javascript(ECMAScript 2016)-108字节

console.log(([a,b,c,d,e,f,g]=[...prompt()].map((x,i)=>+x?'_||'[i%3]:' '),` ${a}
${f}${g}${b}
${e}${d}${c}`))

可能可以打得更远,但是我什么也没想。


欢迎光临本站!那是一个不错的第一篇文章:)
daniero

1

JavaScript,148个字节

e=>(e[0]==1?" #\n":"\n")+(e[5]==1?"#":" ")+(e[1]==1?" #\n":"\n")+(e[6]==1?" #\n":"\n")+(e[4]==1?"#":" ")+(e[2]==1?" #\n":"\n")+(e[3]==1?" #\n":"\n")

在线尝试! (脚是要阅读的Node.js.input.tio

接受二进制标志中ABCDEFG的输入并返回:

 #
# #
 #
# #
 #

0

SmileBASIC,136个字节

DIM A[7,2]COPY A,@L@L?DATA.,1,1,3,4,3,6,1,4,0,1,0,3,1INPUT X$FOR I=0TO 6M=I MOD 3GBOX A[I,1],A[I,0],A[I,1]+!M,A[I,0]+!!M,-VAL(X$[I])NEXT

输出是图形的。


0

05AB1E,4 个字节

C₄+ç

在线尝试验证所有可能的输入

上方验证所有可能的输入”链接,以查看用于每个输入的映射。

说明:

这会滥用其规定的规则:

显示的方式取决于您- 单个Unicode或ASCII符号,ASCII艺术作品,粗体字或其他您想出的东西。但是,每个输入必须具有自己的不同输出。

C       # Convert the (implicit) input from binary to integer
 ₄+     # Increase it by 1000
   ç    # Convert it to a unicode character with this value (and output implicitly)

本着挑战的精神,使用输出格式进行更多选择:

 -
| |
 -
| |
 -

38 个字节

Σ•L7וNè}εi" -| | "14∍2ôNèëðº]J24S5∍£»

绝对可以打高尔夫球。

在线尝试验证所有可能的输入

说明:

Σ       }          # Sort the (implicit) input-digits by:
 L7וNè           #  The digit at the same index in the compressed integer 1367524
                   #   i.e. "1101101" → ["1","0","1","1","1","0","1"]
ε                  # Then map each digit to:
 i                 #  If it's a 1:
  " -| | "         #   Push string " -| | "
          14      #   Lengthen it to size 14: " -| |  -| |  -"
             2ô    #   Split it into parts of 2: [" -","| ","| "," -","| ","| "," -"]
               Nè  #   Index into it
 ë                 #  Else (it's a 0):
  ðº               #   Push "  " (two spaces) instead
    ]              # Close both the if-else and map
                   #  i.e. ["1","0","1","1","1","0","1"]
                   #   → [" -","  ","| "," -","| ","  "," -"]
J                  # Join everything together to a single string
                   #  i.e. [" -","  ","| "," -","| ","  "," -"] → " -  |  -|    -"
 24S               # Push [2,4]
    5             # Lengthened to size 5: [2,4,2,4,2]
      £            # Split the string into parts of that size
                   #  i.e. " -  |  -|    -" → [" -","  | "," -","|   "," -"]
       »           # Join by newlines (and output implicitly)
                   #  i.e. [" -","  | "," -","|   "," -"] → " -\n  | \n -\n|   \n -"

看到这个05AB1E尖矿(部分如何压缩大整数?理解为什么•L7ו1367524


0

PHP 5.6,65字节纯ASCII

for(;$p++<9;)echo$argn[_707561432[$p]]?"||_"[$p%3]:" ","\n"[$p%3];

或者,没有结尾的换行符,但有一点点乐趣:

for(;$p++<11;)echo$argn[_70785618432[$p]]?L|Sx[$p&1]:a^kAAA[$p&3];

与管道一起运行-nR在线尝试它们

细目1

for(;$p++<9;)echo           # loop through positions
    $argn[_707561432[$p]]   # map position to input bit
        ?"||_"[$p%3]            # if set: underscore in 2nd column, pipe symbol else
        :" "                    # else space
    ,"\n"[$p%3]             # add newline every 3 columns
;

故障2

for(;$p++<11;)echo          # loop through positions
    $argn[_70785618432[$p]] # map position to input bit (bit 8 for EOL, never set)
        ?L|Sx[$p&1]             # if set: underscore in the middle, pipe symbol else
        :a^kAAA[$p&3]           # else: newline in 4th column, space else

1
自2017年夏天以来,语言是新语言还是旧语言都不再重要。因此,您不必提及不竞争。
凯文·克鲁伊森

@KevinCruijssen谢谢,我错过了。但是,要恢复旧的PHP版本也是一个很好的挑战。有时,对于最新的功能也有不同的看法:我发现,“旧的”方法有时比使用后来添加到PHP的方法更有效(在大小,性能,可读性以及所有这三个方面)。但是,在这种情况下,没有打高尔夫球的优势:第一种方法需要8个额外的字节,第二种方法需要5个字节
Titus
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.