7
\$\begingroup\$

Use any programming language to display "AWSALILAND" in such a way, so that each letter is in a new line and repeated as many times as its position in the English alphabet. For example letter, (A) should be displayed just once because it is the first letter of the alphabet. Letter D should be displayed 4 times because it is the 4th letter of the alphabet.

So, the output should be this:

A
WWWWWWWWWWWWWWWWWWWWWWW
SSSSSSSSSSSSSSSSSSS
A
LLLLLLLLLLLL
IIIIIIIII
LLLLLLLLLLLL
A
NNNNNNNNNNNNNN
DDDD
\$\endgroup\$
8
  • 7
    \$\begingroup\$ Are lower-case letters OK? \$\endgroup\$
    – Emigna
    Oct 17, 2018 at 12:05
  • 35
    \$\begingroup\$ IMHO, this challenge would have been more interesting if the text was given as input/argument. \$\endgroup\$
    – Adám
    Oct 17, 2018 at 12:48
  • 6
    \$\begingroup\$ @Adám IMHO that wouldn't even be a very interesting challenge anyway. \$\endgroup\$
    – Wheat Wizard
    Oct 17, 2018 at 13:27
  • 2
    \$\begingroup\$ @PostLeftGhostHunter At least it would omit the unrelated challenge of compressing AWSALILAND. \$\endgroup\$
    – Adám
    Oct 17, 2018 at 13:29
  • 1
    \$\begingroup\$ is a list of lines an acceptable output format? \$\endgroup\$
    – Brian H.
    Oct 18, 2018 at 13:31

61 Answers 61

1 2
3
0
\$\begingroup\$

CSASM v2.2.1.2, 162 bytes

func main:
lda 0
sta $1
lda "AWSALILAND"
.lbl a
push $a
conv ~arr:char
ldelem $1
dup
conv i32
push 64
sub
pop $2
conv str
push $2
mul
print.n
inc $1
push $1
push 10
sub
brtrue a
ret
end

Commented and ungolfed:

func main:
    ; Initialize $1 to zero and $a to the string "AWSALILAND"
    lda 0
    sta $1
    lda "AWSALILAND"
    
    .lbl loop
        ; Get the iteration char in the string
        push $a
        conv ~arr:char
        ldelem $1

        ; Duplicate it.  The first will be used as the string to print and the
        ;   second will be used for the string repetitions with "mul"
        dup

        ; Get the index in the alphabet (1..26) and put it in $2
        conv i32
        push 64
        sub
        pop $2

        ; Convert the character to a string, then perform the built-in string
        ;   repetitions with "mul"
        conv str
        push $2
        mul

        ; Print it with a newline appended
        print.n

        ; Truthy is non-zero, so the loop ends when ($1 + 1) - 10 == 0
        inc $1
        push $1
        push 10
        sub
        brtrue loop
    ret
end
\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.