令人困惑的字母楼梯


25

在没有输入的情况下,通过一种可接受的输出方法在任何一种情况下(必须保持大小写)输出此有趣的字母模式:

一种
AB
ACBC
光盘
阿比西德
AFBFCFDFEF
AGBGCGDGEGFG
AHBHCHDHEHFHGH
艾比西迪菲菲
AJBJCJDJEJFJGJHJIJ
AKBKCKDKEKFKGKHKIKJK
ALBLCLDLELFLGLHLILJLKL
AMBMCMDMEMFMGMHMIMJMKMLM
ANBNCNDNENFNGNHNINJNKNLNMN
AOBOCODOEOFOGOHOIOJOKOLOMONO
APBPCPDPEPFPGPHPIPJPKPLPMPNPOP
AQBQCQDQEQFQGQHQIQJQKQLQMQNQOQPQ
ARBRCRDRERFRGRHRIRJRKRLRMRNRORPRQR
ASBSCSDSESFSGSHSISJSKSLSMSNSOSPSQSRS
ATBTCTDTETFTGTHTITJTKTLTMTNTOTPTQTRTST
AUBUCUDUEUFUGUHUIUJUKULUMUNUOUPUQURUSUTU
AVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUV
AWBWCWDWEWFWGWHWIWJWKWLWMWNWOWPWQWRWSWTWUWVW
AXBXCXDXEXFXGXHXIXJXKXLXMXNXOXPXQXRXSXTXUXVXWX
AYBYCYDYEYFYGYHYIYJYKYLYMYNYOYPYQYRYSYTYUYVYWYXY
AZBZCZDZEZFZGZHZIZJZKZLZMZNZOZPZQZRZSZTZUZVZWZXZYZ

尾随空格和换行符是可以接受的,不允许出现标准漏洞,并且这恰好是,因此以字节为单位的最短答案为胜!



顺便说一句,如果我看到一个了不起的答案,我将悬赏50 rep
FantaC

13
领导A真的为我
搞砸

2
我认为有些人根本不喜欢这些挑战。
乔纳森·艾伦

1
@ETHproductions它为我简化了事情!
尼尔

Answers:


5

画布,7 个字节

Z[K*¹+]

在这里尝试!

说明:

Z[     ] for each prefix of the uppercase alphabet
    K        pop off the last letter
     *       and join the rest of the string with that character
      ¹+     and append the current iterated character to it

您为什么不编辑以前的答案?
尼尔

@尼尔很好的问题。不确定
dzaima

公认!您击败了果冻和木炭两个字节!
FantaC

8

果冻,9个字节

ØAjṪ$Ƥż¹Y

在线尝试!

怎么运行的

ØAjṪ$Ƥż¹Y  Main link. No arguments.

ØA         Yield "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
     Ƥ     Map the link to the left over all prefixes, i.e., ["A", "AB", ...].
    $        Combine the two links to the left into a chain.
   Ṫ           Tail; yield and remove the last letter of each prefix.
  j            Join the remainder, using that letter as separator.
      ż¹   Zip the resulting strings and the letters of the alphabet.
        Y  Separate the results by linefeeds.

2
哦,哈哈,我正要发布ØAjṪ$ƤżØAY:D
Jonathan Allan '18


6

R,50个字节

l=LETTERS
for(i in 0:25)cat(l[0:i],"
",sep=l[i+1])

在线尝试!

也许这里最聪明的部分是使用letters[0]空字符串cat(character(0),'\n',sep="A")来打印第一行。


6

木炭,9字节

Eα⁺⪫…ακιι

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

 α          Predefined uppercase alphabet
E           Map over each character
    …ακ     Get current prefix of alphabet
   ⪫   ι    Join with current character
  ⁺     ι   Append current character
            Implicitly print on separate lines


4

6502机器代码例程(C64),39字节

A9 41 20 D2 FF AA A8 84 FB E4 FB B0 0B 8A 20 D2 FF 98 20 D2 FF E8 D0 F1 A9 0D
20 D2 FF A2 41 C0 5A F0 03 C8 D0 E1 60

与位置无关的机器代码子例程,即A,X和Y。

在线演示

该演示程序在加载$C000,因此可SYS49152用于调用例程。


拆解评论:

A9 41       LDA #$41            ; 'A'
20 D2 FF    JSR $FFD2           ; Kernal CHROUT (output character)
AA          TAX                 ; copy to X (current pos)
A8          TAY                 ; copy to Y (current endpos)
  .outerloop:
84 FB       STY $FB             ; endpos to temporary
  .innerloop:
E4 FB       CPX $FB             ; compare pos with endpos
B0 0B       BCS .eol            ; reached -> do end of line
8A          TXA                 ; current pos to accu
20 D2 FF    JSR $FFD2           ; and output
98          TYA                 ; endpos to accu
20 D2 FF    JSR $FFD2           ; and output
E8          INX                 ; next character
D0 F1       BNE .innerloop      ; (repeat)
  .eol:
A9 0D       LDA #$0D            ; load newline
20 D2 FF    JSR $FFD2           ; and output
A2 41       LDX #$41            ; re-init current pos to 'A'
C0 5A       CPY #$5A            ; test endpos to 'Z'
F0 03       BEQ .done           ; done when 'Z' reached
C8          INY                 ; next endpos
D0 E1       BNE .outerloop      ; (repeat)
  .done:
60          RTS

3

Java 8,93 91 90字节

v->{String t="";for(char c=64;++c<91;t+=c)System.out.println(t.join(c+"",t.split(""))+c);}

-1字节感谢@OlivierGrégoire直接打印而不是返回

说明:

在线尝试。

v->{                     // Method with empty unused parameter and String return-type
  String t="";           //  Temp-String, starting empty
  for(char c=64;++c<91;  //  Loop over the letters of the alphabet:
      t+=c)              //    After every iteration: append the letter to the temp-String
    System.out.println(  //   Print with trailing new-line:
       r.join(c+"",t.split(""))
                         //    The temp-String with the current letter as delimiter
       +c);}             //    + the current letter as trailing character 

2
90个字节(仅使用stdout而不是返回)。
奥利维尔·格雷戈尔

好答案!我移植到C#来查看它是否更短,我得到了91(如果包括在内,则更多了System.:)
aloisdg说,莫妮卡

3

SNOBOL4(CSNOBOL4) 169个 143字节

i &ucase len(x) . r len(1) . s
 o =
 i =
t r len(i) len(1) . k :f(o)
 o =o s k
 i =i + 1 :(t)
o o s =
 output =o s
 x =lt(x,25) x + 1 :s(i)
end

在线尝试!

i &ucase len(x) . r len(1) . s	;* set r to the first x characters and s to the x+1th.
 o =				;* set o,i to empty string
 i =
t r len(i) len(1) . k :f(o)	;* set k to the ith letter of r. on failure (no match), go to o.
 o =o s k			;* concatenate o,s,k
 i =i + 1 :(t)			;* increment i, goto t
o o s =				;* remove the first occurrence of s (the first character for x>1, and nothing otherwise)
 output =o s			;* output o concatenated with s
 x =lt(x,25) x + 1 :s(i)	;* increment x, goto i if x<25.
end

这里的问题是第一行

使用o s ks在每行的开头添加一个额外的分隔符,并且s在末尾也没有。之所以可以,是因为t当时,行将跳过以下两行x=0。这意味着o将仍然是空白。因此,o s =将从中删除第一个s字符o,然后我们可以简单地进行打印o s以具有适当的last s


2

JavaScript(ES6),81个字节

f=
_=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"].map((c,i,a)=>a.slice(0,i).join(c)+c).join`
`
;document.write('<pre>'+f());

如果字符串数组的返回值可接受,则节省9个字节。


2

Japt-R标志),14 12字节

-2个字节,感谢@Shaggy

;B¬
ËiU¯E qD

在线测试!


如果只有的快捷方式s0,!; p
Shaggy

12个字节。但是为什么不在这里数-R呢?
粗野的

@Shaggy哦,哇,我知道我漏了一些东西:P这个i技巧很棒,谢谢!至于标志,似乎有一个新的共识,即程序的每个唯一调用都应被视为一种单独的语言。(这使Japt的国旗系统看起来像是个骗子...)
ETHproductions '18


2

Powershell,56字节

"A";65..89|%{([char[]](65..$_)-join[char]++$_)+[char]$_}

在线尝试!

循环6589,每次迭代构建char的阵列65到的当前数量$_,则-joins表示阵列一起与下一个字符的字符串,然后在该字符在端钉。

将更89改为其他ASCII数字以更好地查看行为。


2

> <>44 34字节

"BA"oao"ZA"\=?;1+40.
o1+:{::o}=?\:

在线尝试!

> <>,44字节

"A"o10ao\55*=?;1+40.
1+:{:}=?\:"A"+o{:}"A"+o

在线尝试!

当我使用不同的途径来产生输出时,我发布了自己的> <>答案;另一个> <>答案可以在这里找到

非常感谢Jo king的发现,如果我只是将“ A”与“ Z”而不是26进行比较的话,我就不需要一直将“ A”放到堆栈中。(-10个字节)

说明

解释将遵循代码流程。

"BA"                 : Push "BA" onto the stack;
                       [] -> [66, 65]
    oao              : Print the stack top then print a new line;
                       [66, 65] -> [66]
       "ZA"\         : Push "ZA" onto the stack then move down to line 2;
                       [66, 90, 65]
o          \:        : Duplicate the stack top then print
 1+:                 : Add one to the stack top then duplicate;
                       [66, 90, 65, 65]
    {::              : Shift the stack right 1 place then duplicate the stack top twice;
                       [90, 65, 65, 66, 66]
       o}            : Print the stack top then shift the stack left 1 place;
                       [66, 90, 65, 65, 66]
         =?\         : Comparison for equality on the top 2 stack items then move to line 1 if equal otherwise continue on line 2;
                       [66, 90, 65]
           \=?;      : Comparison for equality on the top 2 stack items then quit if equal else continue on line 1;
                       [66]
               1+    : Add 1 to the stack top;
                       [67]
                 40. : Move the code pointer to column 4 row 0 of the code box and continue execution of code. 

36个字节。您的方法比我的方法好得多
Jo King

inb4“划掉44仍然是44;(”
Jo King

@JoKing与Z相比,这是个极好的地方,我所做的唯一改进就是移动了行逻辑,并将Z放在堆栈项目的中间,以再次使用那些引号保存。
蓝绿色鹈鹕



1

果冻,13个字节

ØA¹Ƥ+"¹Ṗ€Yṭ”A

在线尝试!

说明

ØA¹Ƥ+"¹Ṗ€Yṭ”A  Main Link
ØA              Uppercase Alphabet
  ¹Ƥ            Prefixes
    +"¹         Doubly-vectorized addition to identity (uppercase alphabet) (gives lists of lists of strings)
       Ṗ€      a[:-1] of each (get rid of the double letters at the end)
         Y     Join on newlines
          ṭ”A  "A" + the result

部分滥用字符串和字符列表在Jelly中的区别方式


那很快!
FantaC

@tfbninja ehhh,果冻可以11分钟。谢谢虽然:P
HyperNeutrino 18'1

您可以将第二个替换ØA¹(例如Dennis的)
Jonathan Allan

@JonathanAllan哦,太好了,谢谢!
HyperNeutrino


1

APL + WIN,51个字节

⍎∊'a←⎕av[65+⍳26]⋄a[n←1]',25⍴⊂'⋄,⊃a[⍳n-1],¨a[n←n+1]'

说明:

a←⎕av[65+⍳26] create a vector of upper case letters

a[n←1] first A

25⍴⊂'⋄,⊃a[⍳n-1],¨a[n←n+1]' create an implicit loop to concatenate subsequent letters

1

> <>,47个字节

d2*:1-v
-&$:?!\$:&$:1
1-:?!v\69*-$1-:
+*88~< 1o

在线尝试!

怎么运行的:

d2*:1-v Initialise the stack with 26 (outer loop counter) and 26-1 (inner loop counter)
....
....
....

....
-&$:?!\$:&$:1 Repeatedly make copies of both counters
....          And decrement the inner loop counter
....          Go to third line when inner loop counter is 0

....            Add -54 to the stack (for the newline) and decrement the outer loop counter
....            Initialise the inner loop counter as outer-1
1-:?!v\69*-$1-: If the inner counter is 0, go to the fourth line, else back to the second.
....

....
....      
....      Transform numbers and -54s into letters and newlines by adding 64
+*88~< 1o Output each character until it runs out of stack and errors



1

GNU M4,119个字节

到目前为止最糟糕的。好吧,时间已经花完了……

define(f,`ifelse($1,$2,,`format(%c%c,$1,$2)`'f(incr($1),$2)')')define(g,`f(65,$1)ifelse($1,90,,`
g(incr($1))')')A
g(66)

1

外壳,13个字节

Γ·:mhSzJḣ…"AZ

在线尝试!

说明

这个领导A真的搞砸了-.-

          "AZ  -- string literal: "AZ"
         …     -- fill gaps: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     S         -- with alphabet and
        ḣ      -- | alphabet rangified: ["A","AB","ABC",…,"AB……XYZ"]
      zJ       -- : zipWith join: ["A","ABB","ACBCC","ADBDCDD",…,"AZB……ZYZZ"]
Γ              -- pattern match (x:xs) with the following function (x is "A" and xs ["ABB","ACBCC",…,"A……ZYZZ"]
 · mh          -- | drop the last element of each element of xs: ["AB","ACBC",…,"A……ZYZ"]
  :            -- | cons (construct list): ["A","AB","ACBC",…,"A……ZYZ"]
               -- : strings are printed implicitly

1

C#(.NET Core)

凯文·克鲁伊森(Kevin Cruijssen)的回答

91 90字节

_=>{var t="";for(char c='@';++c<91;t+=c)Console.WriteLine(string.Join(c+"",t.Skip(0))+c);}

在线尝试!

132个 122 110 109 104 103字节

_=>"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Select((c,i)=>string.Join(""+c,"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Take(i))+c)

在线尝试!

  • 替换()_以表明我们声明了一个未使用的变量。谢谢凯文·克鲁伊森。

您也可以像我在Java答案中那样使用空的未使用参数将其减少到90个字节。所以o=>{...}代替()=>{...}在线尝试:90个字节
凯文·克鲁伊森

我不知道@KevinCruijssen!谢谢!
aloisdg说恢复莫妮卡

@KevinCruijssen我加了这个技巧,以提示在C#代码高尔夫
aloisdg恢复莫妮卡说,

1

果冻,22字节

ØAż€Ð€`F€µJ’Ḥ»1ż@¹ḣ/€Y

在线尝试!

怎么运行的:

                       take argument implicitly
ØA                     the uppercase alphabet
    Ѐ`                for C in the alphabet
  ż€                     appends C to every letter in the alphabet
       F€              flatten every sublist
          J            get indices
           ’           subtract 1
            Ḥ          and double
             »1        take max([n, 1])
         µ     ż@¹     interleave alphabet list and indices
                  ḣ/€  reduce on head() for each element
                     Y join on newline
                       implicitly output




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.