次の文字列を見てください。パターンに気づく?
ABEFNOPEFGH DC G Q I M H R J LKJI S K D T L C U M BAZYXWV N E O D P C Q BAZYXWVUTSR
ある人は目にしたように、基本的にアルファベットのスパイラルであり、行/列間の距離は1スペース/改行で徐々に増加しています。
厳密な定義
- Let’s have a counter c, which is initially
0. - We write out the first c + 1 letters of the
alphabet from left to right:A
. -
Then, from top to bottom the next (c + 1)(c +
2)/2 letters (addB
):AB
. -
From left to right, the next (c + 1)(c + 2)/2
(addC
):AB C
-
And from bottom to top, the next c + 1 letters
(addD
):AB DC
-
Reached the end of the cycle. Hence, let’s increment
c (which becomes 1). Then, it starts back from the
first step, the only difference being that instead of using the
first c + 1 letters of the alphabet, we
use the next c + 1 letters, starting from
the last element of this cycle (D
in this case, so we
continue withEFG...
). WhenZ
is reached,
it cycles back fromA
.
仕事
整数 N
(1インデックスの場合は正、0インデックスの場合は非負)を指定すると、スパイラルの最初の N
サイクルを出力します。
ルール
-
You can either use the lowercase or the uppercase alphabet, but
your choice must be consistent (only use one of them, mixing is not
allowed). -
You can take input and provide output through any of
the standard methods, in any
programming language, while noting that
these loopholes are forbidden by default. -
Acceptable output formats: multiline string, a list of strings
representing lines, a list containing multiple lists of characters,
each representing one line, or anything else you find suitable. In
case you don’t choose the first format, it would be nice to include
a pretty-print version of your code. -
This is code-golf,
so the shortest code in bytes (in each language) which fulfils the
requirements wins!
テストケース
入力された整数は改行を介して対応する出力で区切られ、テストはダッシュで区切られます。これらは1-indexedであることに注意してください。
1 AB DC -------- 2 ABEF DC G M H LKJI -------- 3 ABEFNOP DC G Q M H R LKJI S D T C U BAZYXWV ------- 4 ABEFNOPEFGH DC G Q I M H R J LKJI S K D T L C U M BAZYXWV N E O D P C Q BAZYXWVUTSR ------- 5 ABEFNOPEFGHFGHIJ DC G Q I K M H R J L LKJI S K M D T L N C U M O BAZYXWV N P E O Q D P R C Q S BAZYXWVUTSR T R U Q V P W O X NMLKJIHGFEDCBAZY ------ 6 ABEFNOPEFGHFGHIJSTUVWX DC G Q I K Y M H R J L Z LKJI S K M A D T L N B C U M O C BAZYXWV N P D E O Q E D P R F C Q S G BAZYXWVUTSR T H R U I Q V J P W K O X L NMLKJIHGFEDCBAZY M S N R O Q P P Q O R NMLKJIHGFEDCBAZYXWVUTS
Charcoal, 31 bytes
F⮌…⁰NB⁺²⊘×ι⁺³ι⭆α§α⁺λ÷×ι⊕×ι⁺⁹⊗ι⁶
Try it
online! Link is to verbose version of code. Note: The
deverbosifier outputs a trailing separator for some reason.
Explanation:
F⮌…⁰NB
サイズの逆順にボックスを描画します(最大から最小)。
⁺²⊘×ι⁺³ι
ボックスのサイズを計算します。
⭆α§α⁺λ
回転したアルファベットを使用してボックスの枠線を描画します。
÷×ι⊕×ι⁺⁹⊗ι⁶
ボックスの左上に表示される文字を計算します(0インデックス付き)。