বর্ণমালা সিঁড়ি


30

চ্যালেঞ্জ

আপনার টাস্কটি এমন একটি প্রোগ্রাম বা ফাংশন তৈরি করা যা কোনও ইনপুট ছাড়াই নিম্নলিখিতগুলিকে ছাড়িয়ে যায়:

a
bb
ccc
dddd
eeeee
ffffff
ggggggg
hhhhhhhh
iiiiiiiii
jjjjjjjjjj
kkkkkkkkkkk
llllllllllll
mmmmmmmmmmmmm
nnnnnnnnnnnnnn
ooooooooooooooo
pppppppppppppppp
qqqqqqqqqqqqqqqqq
rrrrrrrrrrrrrrrrrr
sssssssssssssssssss
tttttttttttttttttttt
uuuuuuuuuuuuuuuuuuuuu
vvvvvvvvvvvvvvvvvvvvvv
wwwwwwwwwwwwwwwwwwwwwww
xxxxxxxxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzzzz

স্কোরিং

এটি , তাই প্রতিটি ভাষার সংক্ষিপ্ত উত্তর জিততে পারে।


4
লাইন তালিকা হিসাবে আউটপুট?
সম্পূর্ণরূপে

5
পরিবর্তে আমরা কি বড় হাতের বর্ণমালা ব্যবহার করতে পারি?
ঊরীয়েল

9
আমি বর্ণমালার চ্যালেঞ্জ মিস করছি! (তবে লিকি নুনকে জানাবে না)
লুইস মেন্ডো

9
I worked very hard checking if it was a dupe and apparently it isn't
Blue

4
@totallyhuman that's up to you.
SpookyGengar

উত্তর:


14

05AB1E, 2 bytes

Try it online!

Note that this outputs as a list of lines, as the OP explicitly allowed. The link uses a version with pretty-print (joined by newlines).

How it works

  • A yields the lowercase alphabet.
  • ƶ lifts the alphabet (multiplies each element by its index).
  • » joins by newlines.


9

APL (Dyalog), 12 8 5 bytes SBCS

3 bytes saved thanks to @ngn

4 bytes saved thanks to @Adám

⍴⍨⌸⎕A

OP clarified uppercase letters are valid, as well as output as an array of strings.

Try it online!

How?

gives us every letter in the ⎕A lphabet with its indexes in it, handed into the function ⍴⍨ with the letter as left argument and the indexes as right argument.

⍴⍨ resha es its right argument to the length supplied by its left one. switches the left and right (therefore the symbol of it, looking like the face of someone reading this explanation).


819⌶↑⎕A⍴¨⍨⍳26
Adám

@Adám thanks! I tried all variations of / and \, completely ignored shape ⍨
Uriel

You can remove the too.
Adám

@Adám but it would look uglier ⍨
Uriel

Turn boxing on!
Adám

8

Haskell, 27 bytes

[c<$['a'..c]|c<-['a'..'z']]

Try it online! Returns a list of lines. (Thanks to @totallyhuman for pointing out that this is now allowed)

Explanation:

             c<-['a'..'z']  -- for each character c from 'a' to 'z'
[           |c<-['a'..'z']] -- build the list of
[   ['a'..c]|c<-['a'..'z']] -- the lists from 'a' to c, e.g. "abcd" for c='d'
[c<$['a'..c]|c<-['a'..'z']] -- with each element replaced by c itself, e.g. "dddd"

*bows* Explanation for a noob? Does <$ repeat its first argument n times, where n is the length of its second argument?
totallyhuman

@totallyhuman There you go. Feel free to ask in Of Monads and Men if you have further questions.
Laikoni

There are some very interesting operators in Prelude... Thanks for the explanation!
totallyhuman

7

brainfuck, 74 bytes

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

Try it online!

Explanation

++++++++[>+>+++>++++++++++++<<<-]>++>++>+>+
TAPE:
  000
  010   C_NEWLINE
  026   V_ITERCOUNT
  097   V_ALPHA
 >001<  V_PRINTCOUNT
  000   T_PRINTCOUNT

V_ITERCOUNT TIMES:      <<[-   

  V_PRINTCOUNT TIMES:     >>[-
    INC T_PRINTCOUNT        >+
    OUTPUT V_ALPHA          <<.
                          >]

  RESTORE V_PRINTCOUNT    >[-<+>]
  INC V_PRINTCOUNT        <+
  INC V_ALPHA             <+
  OUTPUT C_NEWLINE        <<.
                        >]

Try it online!


7

Befunge-98 (FBBI), 27 bytes

1+:0\::'`j'@+\k:$$>:#,_$a,

where is a substitution character (ASCII 26)

Try it online!

Uses uppercase letters, and has a trailing newline.

Explanation

The code works by storing a counter (0 initially), and on every loop:

  • 1+ - Increments it by 1
  • :0\:: - Pushes things so that the stack looks like this: bottom [N, 0, N, N, N] top
  • '`j'@ - Checks if the counter is greater than 26
    • j'@ - If it is, we jump over the ' and exit using @
    • j'@ - If it isn't, we execute the ', which pushes the ASCII value of @ to the stack

Now the stack looks like this: bottom [N, 0, N, N, 64] top

  • +\ - Adds, then switches the top 2: bottom [N, 0, (N+64), N] top The first time through, this is ASCII 65, or A
  • k: - Duplicates the second from the top (N+1) times - now there are (N+2) values of (N+64) on the stack (plus the N and 0 from earlier)
  • $$ - Throw away the top 2 values - now there are only N values of (N+64)
  • >:#,_ - Prints each top value until it gets to a 0 - this means N copies of (N+64) get printed
  • $ - Throws away the 0 - Now the stack is just N
  • a, - Prints an enter

And it repeats


I like how I used the @ both for ending the program and for adding to the counter.


@JamesHolderness Yep. Thanks for catching that!
MildlyMilquetoast

7

Ruby, 32 30 bytes

-2 bytes thanks to @EricDuminil.

27.times{|n|puts (n+96).chr*n}

Try it online!


1
Excellent. According to a comment by OP, trailing/leading newlines are allowed. In that case 27.times{|n|puts (n+96).chr*n} would be correct with 30 bytes
Eric Duminil

6

JavaScript (ES6), 54 bytes

f=(n=9)=>++n<36?n.toString(36).repeat(n-9)+`
`+f(n):''

O.innerText = f()
<pre id=O></pre>


6

Excel VBA, 38 bytes

Using Immediate Window. :)

[A1:A26]="=REPT(CHAR(96+ROW()),ROW())"

Ah. My bad. I thought it's Excel because I used Excel Functions using Immediate Window.
remoel

You can drop a byte by removing the terminal "
Taylor Scott


5

Ruby, 38 bytes

Returns an Array of strings

->{(a=*?a..?z).map{|x|x*-~a.index(x)}}

-5 bytes thanks to totallyhuman

*-11 bytes thanks to some excellent golfing by Jordan.


This is only 48 bytes by my count.
Jordan

1
You don’t need "\n" at all; puts does that for you (though for future reference $/ is 2 bytes shorter)—but you can get rid of puts entirely if you make this a lambda that just returns an array of lines. You can also change a=[*?a..?z];puts a.map to puts (a=*?a..?z).map and x*(a.index(x)+1) to x*-~a.index(x). All together that’s 38 bytes.
Jordan

The 38-byte version works fine on TiO (see link in previous comment). Note that the (a=*?a..?z) is inside the block, not the arguments part of the lambda.
Jordan


4

MATL, 9 bytes

2Y2"@X@Y"

Try it online!

Explanation

2Y2     % Push string 'abc...z'
"       % For char in that string each
  @     %   Push current char
  X@    %   Push iteration index (1-based)
  Y"    %   Run-length decoding: repeat char that many times
        % Implicit end. Implicit display

Do you know why & can't be used to duplicate and transpose 2Y2?
Stewie Griffin

@StewieGriffin & doesn't actually duplicate and transpose, although it sometimes produces the same result as that. What it does is modify the number of inputs/outputs of the next function. For example, if you use &+, the + function now takes one input instead of two, and outputs the sum of the input with itself transposed. But that's only because that's how + work with 1 input (same for =, > and some others)
Luis Mendo


4

Jelly,  5  4 bytes

sneaky Python implementation abuse

-1 byte thanks to Adám (outputting a list of lines has been allowed; as, now, has writing a function rather than a program)

Øa×J

A niladic link that returns a list of strings, the lines
(to print it with the newlines as a full program just add Y back in).

Try it online! (the footer calls the link as a nilad (¢) and gets the Python representation of the result (ŒṘ) for clarity as the default full-program behaviour would smash the result together like abbccc...)

How?

Øa×J - main link: no arguments
Øa   - yield the alphabet = ['a','b','c',...,'z']
   J - range of length    = [1,2,3,...,26]
  ×  - multiplication     = ["a","bb","ccc",...,"zzzzzzzzzzzzzzzzzzzzzzzzzz"]
     - (Python multiplication lengthens chars to strings - not usually a Jelly thing)

1
Adám

hmm, maybe - we may "output" a list of lines, but we must "create a program" - when running as a program the output of the four byter is smashed to have no indication of it's list nature.
Jonathan Allan

program or function
Adám

4

MATL, 11 bytes

2Y2t!g*!YRc

Try it online!

Uses broadcast multiplication with ones to get a big square 26x26 matrix of the desired letters. Next, the lower triangular part is taken, and implicitly printed.

Also 11 bytes:

2Y2!t~!+YRc  % Using broadcast addition with zeroes
2Y2!l26X"YR  % Using 'repmat'

@StewieGriffin I was actually halfway commenting on your Octave answer on the coincidence of coming up with the same solution.
Sanchises

4

Javascript, 87 bytes, 72 bytes (A lot of thank to @steenbergh)

My first answer too:

for(i=1,j=97;j<123;){console.log(String.fromCharCode(j++).repeat(i++))};

Welcome! Looks like you can shorten it a bit by removing the spaces around ind=1at the start, the semicolon after i<123 and the final semicolon. also, please make your header slightly more clear by stating language - bytecount, prefixed with a #.
steenbergh

You can save six bytes by dropping j altogether: for(i=1;i<27;){console.log(String.fromCharCode(i+96).repeat(i++))}
steenbergh

@steenbergh thank you once again, your how kind you are to help me.
NTCG

4

Japt, 9 7 bytes

Outputs an array of lines

;C¬Ëp°E

Try it


Explanation

Split (¬) the lowercase alphabet (;C) to an array of characters, map over the array (Ë) and repeat (p) the current element by the current index (E) incremented (°) times.


Exactly what I had, except I used ®p°Y
ETHproductions

3

Pip, 9 bytes

FczPcX++i

Try it online!

In pseudocode, this is

For-each c in z
    Print (c string-multiply ++i)

where z is preset to the lowercase alphabet and i is preset to 0.


Map-based solutions take one extra byte because they need the -n flag to display on multiple lines:

{aX++i}Mz
B X_+1MEz

3

Acc!!, 66 bytes

Count i while 26-i {
Count j while i+1-j {
Write 97+i
}
Write 10
}

Try it online!

With comments

# Loop i from 0 to 25
Count i while 26-i {
    # Loop j from 0 to i (inclusive)
    Count j while i+1-j {
        # Print a letter
        Write 97+i
    }
    # Print a newline
    Write 10
}


3

R, 38 bytes

A relatively uninteresting answer. Iterate for i from 1 to 26, print the ith letter of the alphabet i times (with an implicit line break).

for(i in 1:26)print(rep(letters[i],i))

Try it online!

A more interesting approach might be to use something like the following:

cat(letters[(1:351*2)^.5+.5])

This gives us all the letters in the right amount, but no linebreaks. Perhaps someone smarter than me can figure out a way to use that to make a golfier answer.


2
I'm not sure how to use your second approach, either, but I know that rep(letters, 1:26) is much shorter...
Giuseppe

@Giuseppe Hah! Like I said, "someone smarter than me" is definitely needed.
rturnbull




3

J, 18 17 bytes

a.{~(#"0+&96)i.27

Explanation:

              i.27      - list of integers 0 - 26
     (   +&96)          - adds 96 to the above list (starting offset of 'a')
      #"0               - copies the right argument left argument times  
  {~                    - select items from a list (arguments reversed)
a.                      - the whole alphabet


#"0 +&96 is a hook, which means that at first +96 is applied to the list i.27,
resulting in a list 96, 97, 98... 122, then #"0 is applied to this result. 
So it is evaluated as ((i.27)#"0(96+i.27)){a:

Try it online!



3

Octave, 25 24 bytes

['',tril((x=65:90)'+~x)]

Try it online!

Saved one byte thanks to Giuseppe who informed me that OP allows upper case letters.

Explanation:

Create a vector x with the ASCII-values of the upper case alphabet, and transpose it. Add the negated x (thus 26 zeros, in a row vector, in order to create a grid with (the ASCII-values of):

AAAA
BBBB
CCCC

Take the lower triangular matrix and convert to characters by concatenating with the empty string.


3

C (gcc), 48 bytes 50 bytes

Re-runnable version, as per cleblanc and Steadybox in the comments below.

s[9];main(i){for(;i<27;)puts(memset(s,i+95,i++));}

Try it online!


1
Nice answer. I think your function will fail the next time it's called and according to this link it should be re-useable; codegolf.meta.stackexchange.com/questions/4939/…
cleblanc

Here's a fixed version in 50 bytes: s[9];main(i){for(;i<27;)puts(memset(s,i+95,i++));} Still beats my answer by a few bytes :)
Steadybox


3

Japt, 17 16 11 bytes

-5 bytes thanks to Oliver

In ISO-8859-1

;26ÆCgX pXÄ

Not the best score, but I'm still a novice. Any suggestions are very welcome.

Outputs list of lines, as OP allowed. Link contains 3 bytes more for newlines.

Try it online!

;                      - Use string variables
 26                    - Literal 26
   Æ                   - For range 0..26
    C                  - Alphabet
     gX                -         . character at index X
        pXÄ            - Duplicate X+1 times
                       - End function (implicit)

1
Nice! 1oBÊÄ can be replaced by 26õ. You can save a couple more bytes by doing something like ;26ÆCgX pXÄ
Oliver

@Oliver How the heck I didn't see that 26 is shorter than alphabet length?! Thanks. Also, my bad I didn't found that o takes the f argument...
RedClover
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.