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
  • 7
    Are lower-case letters OK? – Emigna Oct 17 at 12:05
  • 27
    IMHO, this challenge would have been more interesting if the text was given as input/argument. – Adám Oct 17 at 12:48
  • 5
    @Adám IMHO that wouldn't even be a very interesting challenge anyway. – Post Left Ghost Hunter Oct 17 at 13:27
  • 2
    @PostLeftGhostHunter At least it would omit the unrelated challenge of compressing AWSALILAND. – Adám Oct 17 at 13:29
  • 1
    is a list of lines an acceptable output format? – Brian H. Oct 18 at 13:31

46 Answers 46

Japt, 18 17 bytes

-1 byte from @Shaggy

`awÑ¢Ó€`u ¬®pIaZc

`awÑ¢Ó€`u ¬®pIaZc   Full program
`awѢӀ`            Compressed "awasiland"
        u           uppercase
          ¨        split and map each letter
            p         repeat the letter this many times:
              a         absolute difference of   
               Zc         get charcode
             I            and 64

Try it online!

  • 1
    Zc uH -> IaZc to save a byte. – Shaggy Oct 17 at 13:21

C# (Visual C# Interactive Compiler), 61 59 bytes

foreach(var s in"AWSALILAND")WriteLine(new string(s,s-64));

Try it online!

@Kevin Cruijssen Thanks, 2 bytes saved by removing { }

  • 4
    You can remove the brackets ({}) – Kevin Cruijssen Oct 17 at 12:44
  • 1
    Linq version is 63 bytes – aloisdg Oct 18 at 8:46
  • @aloisdg Thanks, I tried this before also, but it got also more bytes – pocki_c Oct 18 at 12:21

PowerShell, 34 bytes

"AWSALILAND"|% t*y|%{"$_"*($_-64)}

Try it online!

Takes the string toCharArray, then multiplies each letter out the corresponding number of times. Implicit Write-Output gives us newlines for free.

Ho-hum.

Pyth, 20 bytes

jm*d-Cd64"AWSALILAND

Try it online here.

jm*d-Cd64"AWSALILAND   
         "AWSALILAND   String literal "AWSALILAND"
 m                     Map each character of the above, as d, using:
     Cd                  Get character code of d
    -  64                Subtract 64
  *d                     Repeat d that many times
j                      Join on newlines, implicit print

19 byte alternative, which outputs lower case: jm*dhxGd"awsaliland - link

brainfuck, 112 bytes

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

Try it online!

The actual word generation can probably be optimised further.

Python 3,41 bytes

for i in'AWSALILAND':print(i*(ord(i)-64))

Python 2,40 bytes

for i in'AWSALILAND':print i*(ord(i)-64)

05AB1E, 17 bytes

.•DθîRI§•ʒAyk>×u,

Try it online!

Explanation

.•DθîRI§•           # push compressed string "awsaliland"
         ʒ          # filter
          Ayk       # get the index of the current letter in the alphabet
             >      # increment
              ×     # repeat it that many times
               u    # upper-case
                ,   # print

We only use filter here to save a byte over other loops due to ac implicit copy of the element on the stack. Filter works here since we print in the loop and don't care about the result of the filter.

Stax, 16 15 bytes

êôM▄╬æ♠ª+ç█○==.

Run and debug it

Explanation

`'YHu~{YX#`m64-_]*      #Full program, unpacked,
`'YHu~{YX#`             #Compressed "AWSALILAND"
           m            #Use the rest of the program as the block. Print each mapped element with a new-line.
            64          #Put 64 on stack
              -         #Subtract current element by 64
               _        #Get current index
                ]       #Make a 1 element array
                 *      #Duplicate that many times

Saved one byte by figuring out that the "*" command works with [arr int] and [int arr].

  • 2
    Impressive that Stax can compress a string and then compress the entire program again... – ETHproductions Oct 17 at 17:03
  • Thanks. String literal compression works with huffman tree-type stuff, but the output alphabet is 94 printable ascii characters. The whole-program packing doesn't attempt to use character frequency or order, and (approximately) just converts from base-95 (printable ascii) to base-256 (stax encoding) – recursive Oct 17 at 18:47
  • @ETHproductions Which is probably not shorter than directly compressing it once to base 256. Anyway the disadvantage with Stax's packed mode is that it's hard to put restrictions on the source code. – user202729 Oct 19 at 1:18

Charcoal, 17 bytes

EAWSALILAND×ι⊕⌕αι

Try it online! Link is to verbose version of code. Explanation:

 AWSALILAND         Literal string
E                   Map over characters
                ι   Current character
               α    Uppercase alphabet
              ⌕     Find
             ⊕      Increment
            ι       Current character
           ×        Repeat
                    Implicitly print each entry on its own line

Scala (51 bytes):

"AWSALILAND"map(c=>s"$c"*(c-64)mkString)map println

Scala (41 bytes):

for(c<-"AWSALILAND")println(s"$c"*(c-64))

Try it online

  • This is a code golf question. So you should include your score. – Post Left Ghost Hunter Oct 17 at 12:28
  • Very good answer, welcome to PPCG! – ETHproductions Oct 17 at 17:35

APL (Dyalog Classic), 22 bytes

A more elegant, tacit solution thanks to Adám!

(↑⎕A∘⍳⍴¨⊢)'AWSALILAND'

Try it online!

Initial solution:

↑a⍴¨⍨⎕A⍳a←'AWSALILAND'

Try it online!

Perl 5, 35 bytes

say$_ x(31&ord)for AWSALILAND=~/./g

Try it online!

  • Why do you add the command line option? would it work if it is removed? What is its purpose? – Monolica Oct 23 at 20:09
  • @Monolica The option sets the Perl version to 5.10 to make say work. – nwellnhof Oct 24 at 9:41
  • what is the exact version of Perl you used? What version will run this code exactly without any declaration of what version should be used? – Monolica Oct 24 at 15:57

R, 64 61 bytes

R's clunky string handling characteristics on full display...

-3 thanks to @Giuseppe, who noticed it's actually shorter to convert a string from utf8 to int and back again than using R's native string splitting function...

write(strrep(intToUtf8(s<-utf8ToInt("AWSALILAND"),T),s-64),1)

Try it online!

  • 1
    Before looking at your answer, I would have used match against LETTERS or utf8ToInt, so strtoi is a neat trick! – Giuseppe Oct 17 at 16:46
  • 1
    oh, wait utf8ToInt is shorter! Try it online – Giuseppe Oct 17 at 16:47

K (ngn/k), 23 22 bytes

(32!r)#'r:"AWSALILAND"

Try it online!

         r:"AWSALILAND"  // set variable r to the string
(32!r)                   // mod 32 each string in r, the operation will use ASCII number
       #'                // for each value in the array, take that amount of the corresponding character in the string 

Julia, 41 bytes

[println(l^(l-'@')) for l∈"AWSALILAND"]

Try it online!

Java 11, 89 83 82 81 bytes

v->"AWSALILAND".chars().forEach(c->System.out.println(((char)c+"").repeat(c-64)))

-1 byte thanks to @OlivierGrégoire.

Try it online.

Explanation:

v->                      // Method with empty unused parameter and no return-type
  "AWSALILAND".chars().forEach(c->
                         //  Loop over the characters as integer unicode values
    System.out.println(  //   Print with trailing newline:
      ((char)c+"")       //    The current character converted to char and then String
       .repeat(c-64)))   //    repeated the unicode value minus 64 amount of times
  • 1
    81 bytes – Olivier Grégoire Oct 18 at 16:16
  • @OlivierGrégoire Ah, didn't realize it was shorter that way. I think tried chars().mapToObj(c->((char)c)+"").repeat(c-64).forEach(System.out::prinln) initially somewhere, but obviously it made it longer.. EDIT: Actually, I think I created a tip once about s.chars().forEach(c-> being shorter than a regular for(int c:s.getBytes()) once.. If only I would follow my own tips.. ;) – Kevin Cruijssen Oct 18 at 17:49

J, 31 bytes

echo(#&>~_64+a.i.])'AWSALILAND'

Try it online!

Explanation:

echo(#&>~_64+a.i.])'AWSALILAND' - print
     #  ~                       - copy (arguments reversed)
      &>                        - each character (can be "0)
               i.               - the index of
                 ]              - the characters in
             a.                 - the alphabet  
         _64+                   - minus 64 (times)

SNOBOL4 (CSNOBOL4), 88 bytes

	S ='AWSALILAND'
L	S LEN(1) . X REM . S :F(END)
	&UCASE X @Y
	OUTPUT =DUPL(X,Y)	:(L)
END

Try it online!

MATL, 20 bytes

'AWSALILAND'"@@64-Y"

Try it online!

Explanation

'AWSALILAND'   % Push this string
"              % For each character in this string
  @            %   Push current character
  @            %   Push current character
  64-          %   Implicitly convert to codepoint and subtract 64
  Y"           %   Repeat that many times. Gives a string with the repeated character
               % Implicit end
               % Implicit display

Red, 59 bytes

foreach c"AWSALILAND"[print pad/with c to-integer c - 64 c]

Try it online!

Haskell, 43 bytes

mapM(putStrLn. \c->c<$['A'..c])"AWSALILAND"

Try it online!

SOGL V0.12, 16 bytes

i|╚┌ž′ø¹‘U{Z⁴W*P

Try it Here!

T-SQL, 83 bytes

SELECT REPLICATE(value,ASCII(value)-64)FROM STRING_SPLIT('A-W-S-A-L-I-L-A-N-D','-')

STRING_SPLIT is supported by SQL 2016 and later.

Pip -l, 21 bytes

_X A_-64M"AWSALILAND"

Try it online!

         "AWSALILAND"  Literal string
        M              to the characters of which we map this function:
   A_                   ASCII value of character
     -64                minus 64 (= 1-based index in alphabet)
_X                      String-repeat character that many times
                       Autoprint, with each item on its own line (-l flag)

Python 2, 38 bytes

for c in'AWSALILAND':print ord(c)%64*c

Try it online!

  • I like that str_repeat operator. I sometimes wish that PHP had it - but with another character, so we can go on using strings as numbers. And for <char> in <string> ... I just love it! – Titus Oct 18 at 12:44

C (clang), 96 95 77 73 bytes

*s=L" AWSALILAND";main(i){for(;*++s;puts(""))for(i=*s-63;--i;printf(s));}

Try it online!

-18 bytes thanks to @ErikF

-5 bytes thanks to @ceilingcat

  • @ceilingcat So wide characters are good for something! ;-) – ErikF Oct 18 at 4:59
  • good use of wide chars – Keyu Gan Oct 26 at 17:23

Ruby, 39 bytes

"AWSALILAND".chars{|x|x.*x.ord-64}

Try it offline!

Swift, 95 bytes

"AWSALILAND".unicodeScalars.forEach{print(String(repeating:String($0),count:Int($0.value)-64))}

Try it online!

How?

"AWSALILAND"                             // Starting string
    .unicodeScalars                      // Convert into a list of unicode values
    .forEach {                           // Loop over each number
        print(String(                    // Create a string
            repeating: String($0),       //   that repeats each character
            count: Int($0.value) - 64))  //   the unicode value minus 64 (the offset)
}

Z80Golf, 30 bytes

00000000: 2114 007e d640 477e ff10 fd23 3e0a ff7e  !..~.@G~...#>..~
00000010: b720 f076 4157 5341 4c49 4c41 4e44       . .vAWSALILAND

Try it online!

Assembly:

ld hl,str			;load address of str
start:
	ld a,(hl)		;get current char
	sub 64 		;get letter num in alphabet
	ld b,a			;store in b
	ld a,(hl)		;get current char
	print_char:
		rst 38h 	;print letter
		djnz print_char	;repeat print loop b times
	inc hl			;increment index of str, to get next char
	ld a,10
	rst 38h 		;print newline
	ld a,(hl)		;get current char
	or a
	jr nz, start		;if current char!=0, keep looping
end:
	halt			;end program (if current char==0)
str:
	db 'AWSALILAND'

Try it online!

Jelly, 20 bytes

“AWSALILAND”ẋ"O_64ƊY

Try it online!

  • I'd suggest “µɗỊ²ẋ_’ṃØA to save a byte on the string, but that seems to throw an error when placed in the program... – ETHproductions Oct 17 at 17:17
  • @ETHproductions You need to append a ¤ to that, therefore no bytes are saved. Same luck with compressed strings... :-( – Erik the Outgolfer Oct 17 at 17:40

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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