ASCII Meme箭头生成器


13

技术指标

给定一个数字n,输出大小为的ASCII“模因箭头”(大于符号,>n

n 始终是一个大于0的正整数。

例子

n = 2

\
 \
 /
/

n = 5

\
 \
  \
   \
    \
    /
   /
  /
 /
/

样例代码

这是一个用Crystal编写的示例程序,可以返回正确的结果。以方式运行./arrow 10

arrow.cr

def f(i)
        i.times { |j|
                j.times { print ' ' }
                puts "\\"
        }
        i.times { |j|
                (i-j-1).times { print ' ' }
                puts '/'
        }
end

f(ARGV[0].to_i)

规则

  • 这是。最短的答案将获胜。但是,我不会选择答案,因为最短的答案可能会随着时间而变化。
  • 不允许出现标准漏洞。

1
您确定这不是重复项(也就是说,您是否对此进行了沙箱处理)?我认为这可能是可能的,但几乎没有可能进行搜索。
我的代词是monicareinstate '19

1
可以n为零吗?
xnor19

6
我认为将此通用符号称为“模因箭头”是很愚蠢的。他们显然是喜剧人字形。

4
@Christian他们实际上是在逗角
dkudriavtsev

1
@ArtemisFowl我认为这是有趣的增长
dkudriavtsev

Answers:



8

C(gcc),56个字节

f(n,i){for(i=-n;n;printf("%*c\n",i?++i+n:n--,i?92:47));}

在线尝试!

f(n,i){for(i=-n;i;printf("%*c\n",  ++i+n    ,  92   ));     //first print descending '\'s
       for(    ;n;printf("%*c\n",        n--,     47));}    // then print returning  '/'s




4

C64Mini / C64 BASIC(和其他CBM BASIC变体),使用了52个标记化的BASIC字节

 0INPUTN:N=N-1:FORI=0TON:PRINTTAB(I)"\":NEXT:FORI=NTO0STEP-1:PRINTTAB(I)"/":NEXT

这是用于移植的非混淆版本:

 0 INPUT N
 1 LET N=N-1
 2 FOR I=0 TO N
 3  PRINT TAB(I);"\"
 4 NEXT I
 5 FOR I=N TO 0 STEP -1
 6  PRINT TAB(I);"/"
 7 NEXT I

N由于TAB命令是零索引的,因此在第零行中输入的数字都会减少一。FOR/NEXT如果meme箭头分别在第二行至第四行和第五行至七行中的循环输出上部和下部(由图形模式源中的Shifted M和Shifted 表示)N

准将C64 meme arrow


1
您是否知道在Commodore Basic中所有关键字都可以缩写?这是链接:c64-wiki.com/wiki/BASIC_keyword_abbreviation 例如,for可以是fOf-shoft o),printis ?
。– gaborsch

1
52个字节在Code Golf中具有误导性,二进制文件不算在内,只是源代码。应该这样:0inputn:n=n-1:fOi=0ton:?tA(i)"\":nE:fOi=0ton:?tA(i)"/":nE-占用57个字节。
gaborsch

1
正如这里讨论的-> codegolf.meta.stackexchange.com/questions/11553/…我计算使用的令牌,因为这更能代表正在使用多少内存。
Shaun Bebbers

1
哦,我不知道。对此有决定吗?甚至答案都没有被接受。
gaborsch

1
我的第一台计算机是C16,我也为此进行了很多组装,所以没有犯错,我爱Commodore。C16有Basic 3,5,每行80个字符,我也有一本书,上面有ROM清单的说明,所以我完全知道
令牌

4

MarioLANG719个 677字节

+
+
+
+
+
+         ((((+)+++++)))<
+>======================"
+)++++++)+++++++++++((-[!)
========================#=-
) ![-    <+;)+++)---)++++)<
)=#======"=================
) >)+)+((!
+ "======#
         <))))).(((((((<
 ========">============"
>)+)+((-[!+))        -[!((((((((.)).))))+(-[!)
"========#=============#====================#<
!)                                          <
#==========================================="
                  >(((((.)))>
                  "========<"========
 ![-)).))).(((((((![-    ))+![-((+)+)<((![<
 #================#=========#========"==#="===
 >                                   !  >-!
 "===================================#  "=#

在线尝试!

这比预期的要难...


4

brainfuck,125个字节

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

在线尝试!

++++++++++[->+>+++++++++>+++<<<]>>++>++>    ; Initialize with " \"
,                                           ; Get input
[->                                         ; loop and decrement n 
    [->+<<<.>>]                             ; output number of spaces, copy n
    <<<.                                    ; output \
    <.                                      ; output newline
    >>>>                                    
    >[-<+>]<+                               ; copy copy of n back to original place 
<]
<<[--<<+>>]<<+>>                            ; change "\" to "/"
>>>                             
[                                           ; second loop for bottom half
 -                                          ; decrement n
 [-<+<.>>]                                  ; output n spaces
 <<<<<.>.                                   ; output \ and newline
 >>>[->+<]>                                 ; copy n back
]

4

Ruby111 99 77 73 68 64 57 56字节

-12个字节要感谢Benjamin Urquhart,-43个要感谢manatwork,-2个字节要感谢Value Ink

->i{s=[];puts (0...i).map{|j|s=(p=' '*j)+?/,*s;p+?\\},s}

在线尝试!

说明:

f=->i{                      # instead of a function, use a lambda
  s=[]                      # needs a helper variable *now*, for scope
  puts(                     # puts takes arbitrary num of args; \n after each
    (0...i).map{|j|         # not from 0 to i but from 0 to i-1 (*three* dots)
      s=(
        p=' '*j             # p will remain in scope inside of .map,
      )
      +?/                   # character literal instead of string
      ,*s                   # essentially appending to the array

      p+?\\                 # p is what's returned by .map, not s!

    },                      # up until here, 1st arg to display
    s                       # NOW, as the *2nd* arg, s is displayed
  )
}

替代(但更长)的解决方案

一个朋友读了这个答案,然后尝试提出另外两种方法。也将它们放在此处,以免它们被庞大的互连网所迷失。

注入和取消移位,72字节

->n{puts (0...n).inject([]){|s,i|i=' '*(n-1-i);s.unshift i+?\\;s<<i+?/}}

在线尝试!

向下,注入和取消移位,80字节

->n{puts n.downto(1).map{|i|' '*(i-1)}.inject([]){|s,i|s<<i+?/;s.unshift i+?\\}}

在线尝试!

有趣的两个非嵌套循环,127个字节

->n{
r=->s,c{s[0..-(c+1)],s[-c..-1]=s[c..-1],s[0..c-1];s};
n.times{|i|puts r[' '*n+?\\,n-i]}
n.times{|i|puts r[' '*n+?/,i+1]}
}

在线尝试!


不能删除很多空白吗?
本杰明·厄克特

1
是的,总共12个字节,谢谢!这是我第一次向代码高尔夫球比赛提交任何内容……
六十五周年(

然后,您可能会发现有趣的Ruby高尔夫技巧,甚至是<all language>高尔夫技巧
manatwork

您可以将内部循环替换为String#rjust在线尝试!)。
manatwork

在这里,我应用了上述2个集合中的一些技巧,将其减少到57个字符:在线尝试!
manatwork


3

T-SQL代码,80字节

DECLARE @ INT=3

,@z INT=0
x:PRINT
space(@-abs(@-@z-.5))+char(92-@z/@*45)SET
@z+=1IF @z<@*2GOTO x

在线尝试

T-SQL查询,96字节

为了使这项工作能够在线进行,我不得不进行一些小的改动。在线摘要中不会显示行开头的空格。所以我改用ascii 160。在Management Studio中运行时,可以更改设置以将结果显示为文本,这将在此发布的脚本中产生正确的空格。

DECLARE @ INT=3
SELECT space(@-abs(@-number-.5))+char(92-number/@*45)FROM
spt_values WHERE number<@*2and'p'=type

在线尝试



2

木炭,5字节

↘N‖M↓

在线尝试!链接是详细版本的代码。说明:

↘N

输入数字并打印\该长度的s的对角线。

‖M↓

垂直反射线。


2

APL(NARS),40个字符,80个字节

{f←{⍺,⍨⍵⍴' '}⋄⊃('\'f¨k),('/'f¨⌽k←¯1+⍳⍵)}

测试:

  h←{f←{⍺,⍨⍵⍴' '}⋄⊃('\'f¨k),('/'f¨⌽k←¯1+⍳⍵)}
  h 2
\ 
 \
 /
/ 
  h 5
\    
 \   
  \  
   \ 
    \
    /
   / 
  /  
 /   
/    





1

小枝,115字节

向后构建字符串,最后将其“返回”。

使用宏生成所有结果。

{%macro a(N,s="")%}{%for i in N..1%}{%set s=('%'~i~'s
'~s~'%'~i~'s
')|format('\\','/')%}{%endfor%}{{s}}{%endmacro%}

此宏必须在文件中,并按以下方式导入:

{% import 'macro.twig' as a %}

{{ a.a(<value>) }}

您可以在https://twigfiddle.com/5hzlpz上尝试(单击“显示原始结果”)。



1

MATL,14 13 12字节

Xy92*t45-Pvc

@LuisMendo节省了1个字节

说明

        % Implicitly grab the input as an integer
Xy      % Create an identity matrix this size
92*     % Multiply by 92 (ASCII for '\')
t       % Duplicate the matrix
45-     % Subtract 45 from every element yielding 47 (ASCII for '/') on the diagonal
        % and -45 everywhere else
P       % Vertically flip this matrix
v       % Vertically concatenate the two matrices
c       % Convert to characters (negative numbers are replaced with a space)
        % Implicitly display the result

MATL Online上试用


@LuisMendo更新!谢谢!
Suever


1

Rockstar,133个字节

在这里在线尝试!

F takes N,S
If N is 0
Give back N

Say S+"\"
Let T be S+" "
Let M be N-1
F taking M,T
Say S+"/"

Listen to X
F taking X,""

由于Rockstar在字符串操作方面并不出名,因此需要花费大量的代码(递归时间甚至更长)。

箭头的大小用作输入。



1

\ / \ />,74个字节

jp100o
-84*}!o:?!x1
@+:q:p=?x:o~$:0(pa"\/"q?$~}}:
x2-:p$1-y$:0(?
.{suh?!;2

说明:(基于起点旋转的线)

jp100o                        //setup
:?!x1-84*}!                   //add leading spaces, loop and decrement until 0
~$:0(pa"\/"q?$~}}:@+:q:p=?x:o //add correct slash, go back to loop or switch sides
$:0(?x2-:p$1-y                //flip direction state or continue to print
{suh?!;2.                     //remove extra data and print stack

1
\/\/> (pronounced wɜrm)谢谢,我讨厌。(jk,我很想尝试一下)
Jo King

@JoKing哈哈哈,得把我的灵感戴在袖子上。(感谢!)
torcado




0

SimpleTemplate,100字节

这是一个非常有趣的挑战,但是语言中的一些错误使优化变得困难。

{@set_ argv.0}{@while_}{@callstr_repeat intoS" ",_}{@setO S,"\\\n",O,S,"/\n"}{@incby-1_}{@/}{@echoO}

基本上,将这些值向后循环,从中间开始处理字符串。


答案应该如何

由于这些错误,该代码未正确解释。

如果编译器没有任何错误(86字节),则代码将是这样:

{@forfrom argv.0to0step-1}{@callrepeat intoS" ",_}{@setO S,"\\
",O,S,"/
"}{@/}{@echoO}

哦,好吧,至少该解决方案可行:x


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.