アルファベットの三角形が再び打つ


24

仕事

あなたの仕事はこの正確なテキストを印刷することです:

A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ

スペック

  • すべて大文字ではなく、すべて小文字で行うことができます。
  • 三角形の末尾の末尾の改行は許可されます。
  • 各行の後のスペースは許可されます。
  • 文字列の配列を出力する代わりに、STDOUTに出力する必要があります。

得点

これはです。最も少ないバイト数のプログラムが勝ちます。


1
「またストライク」とはどういう意味ですか?このような挑戦をしましたか?
-haykam


1
(別の)アルファベットチャレンジが本当に必要なのはかなり簡単なようです。
ローハンジュンジュンワラ

2
それは良い挑戦ですが、私たちはこれらのアルファベットの挑戦の飽和を追い越したと思います、個人的なものは何もありません。
ローハンジュンジュンワラ

実際にアルファベットの課題を探しているのは、ある位置にある文字を、mod関数に関係する座標からの単純な式では計算できないということです。時間があれば自分で作るかもしれません。
周jun順

回答:


39

Vim、29バイト

:h<_↵↵↵y$ZZ26P0qqa↵♥βjllq25@q

where は、Returnキー、Escapeキー、およびβBackspaceキーを表します。

enter image description here


3
これらについてのvimの答えにいつもどのように私を打ち負かしますか?とにかくAargh +1、私はvimに賛成できない!:)
DJMcMayhem

7
私はまだあなたが代わりに使うべきだと思います。そして、代わりにβ。それが、これらのUnicode文字が作成された理由です。utf8icons.com/subsets/control-pictures
mbomb007

9

Python 2、65バイト

i=1
a=bytearray(range(65,91))*26
while a:print a[:i];a=a[i:];i+=2

1
Python 3ではコードが機能しないため、ヘッダーをPython 2に変更しました。
Leaky Nun

7

ゼリー、10 バイト

26RḤ’RØAṁY

オンラインでお試しください!

使い方

26RḤ’RØAṁY  Main link. No Arguments.

26          Set the return value to 26.
  R         Range; yield [1, 2, ..., 25, 26].
   Ḥ        Unhalve; yield [2, 4, ..., 50, 52].
    ’       Decrement; yield [1, 3, ..., 49, 51].
     R      Range; yield [[1], [1, 2, 3], ..., [1, ..., 49], [1, ..., 51]].
      ØA    Yield the uppercase alphabet.
        ṁ   Mold the alphabet as the array of ranges. This repeats the uppercase
            letters over an over again, until all integers in the range arrays
            have been replaced with letters.
         Y  Join, separating by linefeeds.

当時、「ダブル」は「アンハルブ」と呼ばれていましたか?また、素晴らしいです!! [100kの担当者におめでとうございます]
エリック・ザ・アウトゴルファー

それは単なるニーモニックです。H半分でその逆(unhalve)です。
デニス

/2または*2について考えるだけなので、「Halve」または「Double」です。それが私が混乱した理由です。
エリックアウトゴルファー

また10バイト:27Ḷ²IRØAṁY
リーキー修道女

また10バイト:51Rm2RØAṁY
HyperNeutrino

7

VBA Excel(80バイト、1742バイト)


Excel、1742バイト

ウゴレンの創造的な答えに触発され、私はOPに示されているパターンを作成するためのExcel式を見つけることができました。

=MID(REPT("ABCDEFGHIJKLMNOPQRSTUVWXYZ",26),(ROW()-1)^2+1,2*ROW()-1)

この数式をセルA1に貼り付け、範囲A1:A26全体にドラッグします。

数式の長さは67バイトですが、26回複製する必要があるため、67 * 26 = 1742バイトに等しくなります。出力は次のとおりです。

enter image description here


Excel VBA、80バイト

VBAはExcelを含むほとんどのMicrosoft Officeアプリケーションに組み込まれているため、ExcelをVBAと統合してプロセスを自動化し、多くのバイトを節約することが可能になりました。イミディエイトウィンドウで次のコードを記述して実行します(Visual Basic Editorで表示するには、コンビネーションキーCTRL+ Gを使用します)。

[A1:A26]="=MID(REPT(""ABCDEFGHIJKLMNOPQRSTUVWXYZ"",26),(ROW()-1)^2+1,2*ROW()-1)"

プログラムは、上記のExcel式をA1:A26の範囲に印刷することで機能します。残念ながら、ExcelとVBAの両方には組み込みのアルファベットがありません。


列名は、組み込みのアルファベットのように見えます。最初の26列の名前を使用します。
mbomb007

1
@ mbomb007だから何?文字列の代わりにそれらを使用するのは難しいと思います。
エリックアウトゴルファー

@EriktheGolferだから?私のポイント、組み込みのアルファベットあるということでした。
mbomb007

1
@ mbomb007「最初の26列の名前を使用してください」と言いましたが、「現在使用しているものの代わりに最初の26列の名前を使用してください」と感じたので、返信しました。
エリックアウトゴルファー

@EriktheGolfer提案です。Idkのバイト数。
mbomb007

5

Haskell、67バイト

_#53=[]
s#i=take i s:drop i s#(i+2)
mapM putStrLn$cycle['A'..'Z']#1

i線の長さにわたる単純な再帰。各ステップで、次のi文字はアルファベットの無限の繰り返しから取得されます。


4

Mathematica、90バイト

StringRiffle[Flatten[Alphabet[]&~Array~26]~Internal`PartitionRagged~Range[1,51,2],"
",""]&

匿名関数。入力を受け取らず、出力として文字列を返します。ゴルフの提案を歓迎します。実行例Internal`PartitionRagged

In[1]:= Internal`PartitionRagged[{2, 3, 5, 7, 11, 13}, {2, 3, 1}]               

Out[1]= {{2, 3}, {5, 7, 11}, {13}}

Mathematicaにはアルファベットの三角形が組み込まれていますか?
バッファーオーバーリード

4

C、79バイト

main(i,j){for(i=0,j=1;i<676;i++){putchar(i%26+65);if(j*j==i+1){puts("");j++;}}}

Cでの最初の回答\ o /

ゴルフの提案は大歓迎です。


62:i;main(j){while(i<676)printf("\n%c"+(j*j^i++||!j++),i%26+65);}
xsot

@xsotありがとうございますが、主要な改行は許可されていません。
リーキー修道女

1
しかし、主要な改行はありませんか?
-xsot

60:i;main(j){for(;j<27;j*j^++i||puts("",j++))putchar(i%26+65);}
xsot

@immibis私はそれを投稿すべきだと思う。
xsot

4

ブラキログ、37バイト

26~l<:1aLc~j[@A:I],L~@nw
=:2%1,.#@l?,

オンラインでお試しください!

説明

  • 主な述語:

    26~l         Let there be a list of 26 elements
    <            This list is an ascending list of integers
    :1aL         Apply predicate 1 to that list ; the resulting list of strings is L
    c            Concatenate the list of strings into one big string
    ~j[@A:I],    That big string is the result of juxataposing the alphabet I times to itself
    L~@n         Create a string which when splitted on line breaks results in L
    w            Write that string to STDOUT
    
  • 述語1:奇数の長さの可変文字列を生成するために使用されます。

    =            Assign a value to the Input
    :2%1,        That value must be odd
    .#@l?,       Output is a string of length Input
    

最後に、アスキー・アートチャレンジ行う
漏れ修道女

@LeakyNunは、ASCIIアート
imo

それをタグに追加する必要がありますか?
リーキー修道女

最後の行が最後の行であるという事実を上手く使用するのは、正方形Zがないため26です。
リーキー修道女


3

JavaScript(ES6)、77 82 88

EcmaScript 6では、改行用のテンプレート文字列リテラルを使用して1バイトを保存するだけで済みました。

for(i=r=l=o='';l+52;r++||(r=l-=2,o+=`
`))o+=(i++%26+10).toString(36);alert(o)

少ないゴルフ

for(i = r = l = o = '';
    l + 52;
    r++ || (r = l -= 2, o += `\n`))
  o += (i++ % 26 + 10).toString(36);
alert(o);

テスト

for(i=r=l=o='';l+52;r++||(r=l-=2,o+=`
`))o+=(i++%26+10).toString(36);alert(o)


\ o /ブラウザで実行できるES6回答
Downgoat

私はあなたの.toString(36)ロジックを盗みました...今、あなたは80バイトを破らなければなりません!!
applejacks01

ああ、私は認めます、私のライブラリでこれを打ち負かす方法は考えられません。挑戦してくれてありがとう!
applejacks01

3

Perl、42 41 39バイト

perl -E '@b=(A..Z)x26;say splice@b,0,$#a+=2for@b'

コードだけ:

@b=(A..Z)x26;say splice@b,0,$#a+=2for@b

明らかに短いバージョンは、残念ながら内部perlの問題を引き起こします(反復で解放された値を使用):

say splice@b,0,$#a+=2for@b=(A..Z)x26

2

JavaScript、129バイト

z=1,i=0,g=a=>{b=0,c="";while(a+a-1>b){c+='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split``[i>26?i=0:i++];b++}console.log(c)};while(z<26)g(z++)

1
スプレッド演算子を使用することで、あなたに救うことができる3つのバイトを[...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']代わりに'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split``
insertusernamehere


2

Go、133バイト

package main
import S "strings"
func main(){s:=S.Repeat("ABCDEFGHIJKLMNOPQRSTUVXXYZ",26)
for i:=1;s!="";i+=2{println(s[:i]);s=s[i:]}}

2

MATLAB、112 109 95 79 77バイト

これはOctaveでも動作しますここからオンラインで試すことができます

a=['' 65:90 65:90]';j=0;for i=1:2:52;b=circshift(a,j);j=j-i;disp(b(1:i)');end

いくつかの大きな変更の後、14 32バイトをさらに節約しました。これは、MATLABに期待していた長さにはるかに近づいています。古いバージョンは実質的に異なるため、以下に残しました。

a=['' 65:90 65:90]';        %Create 2 copies of the upper case alphabet
j=0;                        %Initialise cumulative sum
for i=1:2:52;               %For each line length
    b=circshift(a,j);       %Rotate the alphabet string by the cumulative offset
    j=j-i;                  %Update cumulative negative sum of offsets.
    disp(
         b(1:i)'            %Extract first 'line length' characters from rotated alphabet.
               );           %Display next line (disp adds newline automatically)
end

元のバージョン:

a=['' repmat(65:90,1,26)];c=cumsum(1:2:51);disp(cell2mat(arrayfun(@(s,f)[a(s:f) 10],[1,c(1:25)+1],c,'Un',0)))

うわー、思ったよりも長くなった。数バイトを削ることができないかどうかを確認します。

説明するための無料版:

a=['' repmat(65:90,1,26)]; %Create 26 copies of the upper case alphabet
c=cumsum(1:2:51);          %Calculate the end index of each row in the above array, by cumulatively summing the length of each line
disp(
     cell2mat(
              arrayfun(@(s,f)
                             [a(s:f) 10], %Extract the part of the alphabet and insert a new line.
                                         [1,c(1:25)+1],c, %start index is the previous end of line plus 1. End index is as calculated by cumsum.
                       'Un',0 %The returned values are not all the same length
                       )   %Do this for each line
              )            %Convert back to a matrix now new lines inserted
     )                     %And display it

謝辞

  • 3バイト保存-ありがとう@LuisMendo

2

XPath 3.0(およびXQuery 3.0)、84バイト

codepoints-to-string((0 to 25)!(subsequence(((1 to 26)!(65 to 90)),.*.+1,2*.+1),10))

説明:

(1 to 26)!(65 to 90) 26回アルファベットです

(0 to 25)!(subsequence(XX, start, len),10) これの26のサブシーケンスを取り、それぞれに改行が続きます

subsequence(X, .*.+1, 2*.+1) 開始位置と長さを持つ連続したサブシーケンスを取ります:(1、1)、(2、3)、(5、5)、(10、9)など。

codepoints-to-string() Unicodeコードポイントを文字に変換します


ブラボー。私はXQueryが何であるかを知っていたと思いました。わからないことがわかった。
ヨルダン

。私はここの記事の多くは、彼らがで書かれている言語について多くを教えてくれていることを疑う
マイケル・ケイ

2

ルビー、46バイト

26.times{|i|puts ([*?A..?Z]*26)[i*i,i*2+1]*""}

ideoneでご覧ください:http ://ideone.com/3hGLB0


2

05AB1E(代替)15バイト

A2×52µ¼D¾£,¾¼FÀ

オンラインでお試しください!

説明:

A2×              # push a string containing a-za-z
   52µ           # Loop the rest of the program until counter = 52
      ¼          # increment counter (it's 0 initially)
       D         # Duplicate the alpha string on the stack
        ¾£       # Replace alpha with alpha[0..counter]
          ,      # Pop the substring and print it
           ¾¼FÀ  # rotate the alpha string left counter++ times.

2

R、120の 115 111バイト

v=c();for(i in 1:26){v=c(v,c(rep(LETTERS,26)[(sum((b=seq(1,51,2))[1:i-1])+1):sum(b[1:i])],"\n"))};cat(v,sep="")

アンゴルフド:

a=rep(LETTERS,26)
b=seq(1,51,2)
v=vector()

for(i in 1:26)
    {
    v=c(v,c(a[(sum(b[1:i-1])+1):sum(b[1:i])],"\n"))
    }

cat(v,sep="")

基本的に、bはとの間の奇数のベクトルで1あり51、各行の長さを示します。明らかに、sum関数はこのベクトルの数を合計し、開始インデックスと終了インデックスを提供します。

@plannapusのおかげで-5バイト!@plannapusのおかげで
-4バイト


1
arf、申し訳ありませんが、以前は見ませんでしたが、a一度しか使用しないので、実際に定義する必要はありません。つまり、さらに数バイト削ることができますb=seq(1,51,2);v=c();for(i in 1:26){v=c(v,c(rep(LETTERS,26)[(sum(b[1:i-1])+1):sum(b[1:i])],"\n"))};cat(v,sep="")
プランナパス

@plannapusばかげた!再度、感謝します !またb=seq、本体にパーツを統合したため、さらに読みにくくなりました
フレデリック

2

R、81 73 65 63バイト

単純なforループアプローチ。アルファベットを26回繰り返し、を使用して計算されるスライドインデックス範囲をループし(i^2-2*i+2):i^2ます。

for(i in 1:26)cat(rep(LETTERS,26)[(i^2-2*i+2):i^2],"\n",sep="")


1

バッチ、123バイト

@set s=
@for /l %%i in (1,2,51)do @call set s=%%s%%ABCDEFGHIJKLMNOPQRSTUVWXYZ&call echo %%s:~0,%%i%%&call set s=%%s:~%%i%%


1

Rexx, 74 72 bytes

i=1;m=1;do 26;say substr(copies(xrange('A','Z'),26),i,m);i=i+m;m=m+2;end

Ungolfed:

i=1
m=1
do 26
  say substr(copies(xrange('A','Z'),26),i,m)
  i=i+m
  m=m+2
end

1

TSQL, 129 bytes

USE MASTER in the beginning of the script is to ensure that the query is run in the master database which is default for many users(not counting bytes for that).

Golfed:

USE MASTER

SELECT SUBSTRING(REPLICATE('ABCDEFGHIJKLMNOPQRSTUVWXYZ',26),number*number+1,number*2+1)FROM spt_values WHERE number<26and'P'=type

Ungolfed:

USE MASTER

SELECT SUBSTRING(REPLICATE('ABCDEFGHIJKLMNOPQRSTUVWXYZ',26),number*number+1,number*2+1)
FROM spt_values
WHERE number<26and'P'=type

Fiddle

Fiddle for older version using xml path


1

PowerShell, 68 bytes

$a=-join(65..90|%{[char]$_})*26;26..1|%{$a=$a.Insert($_*$_,"`n")};$a

The section before the first semicolon produces a string containing 26 copies of the uppercase alphabet. The next section injects linebreaks at the index of each square number (working backward so I don't have to account for the shifting). Finally, the $a at the end just shoves that string variable onto PowerShell's equivalent of STDOUT.



1

C, 60 bytes

i;main(j){for(;j<27;j*j^++i||puts("",j++))putchar(i%26+65);}

puts only takes one argument. (Some undefined behaviour is permitted in codegolf normally but this is a bit too far outside the usual lanes)
M.M

@M.M Undefined behaviour is exploited all the time. The rule is that a submission is valid as long as it works in some compiler, otherwise we would have to explicitly rule out a long list of exceptions. This code works in gcc so it's a valid submission.
xsot

1

C++, 111 bytes

void a(){int c=65,i,j;for(i=0;i<26;i++){for(j=0;j<=2*i;j++){std::cout<<(char)c;c++;if(c==91)c=65;}std::cout<<'\n';}}

First try at one of these. Uses an int "c" to record which letter it needs to print at any given time. Once "c" passes 90 ('Z') it gets reset to 65 ('A'). Prints the pyramid using for loops.


Nice answer! You could do if(c<92)c=65 to take one byte off, and you might also be able to do int a() instead of void a(), but I'm not positive if that works without the return. Other than that, I think you need to include #include <iostream> in your byte count.
DJMcMayhem

I believe you meant if(c>90)c=65, but thanks for the suggestion, it's a good idea. Also, I guess I'll include it, thanks.
limelier

1

PHP, 76 69 bytes

for(;$i<26&&$a.=join(range(A,Z));)echo substr($a,$i**2,1+2*$i++)."
";
  • Create 26 alphabet (more than enough) and contactenate them in $a
  • loop for i < 26
  • display $a substring start i^2, end 2*i+1
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.