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

7
\$\begingroup\$

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 { }

\$\endgroup\$
4
  • 4
    \$\begingroup\$ You can remove the brackets ({}) \$\endgroup\$ Oct 17, 2018 at 12:44
  • 1
    \$\begingroup\$ Linq version is 63 bytes \$\endgroup\$
    – aloisdg
    Oct 18, 2018 at 8:46
  • \$\begingroup\$ @aloisdg Thanks, I tried this before also, but it got also more bytes \$\endgroup\$
    – pocki_c
    Oct 18, 2018 at 12:21
  • \$\begingroup\$ Abuse LINQ and is (this optimization seems to be almost always applicable to foreach loops) for 57 bytes. Try it online! (I guess being slightly late is okay?) \$\endgroup\$ Apr 17, 2019 at 4:35
6
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Zc uH -> IaZc to save a byte. \$\endgroup\$
    – Shaggy
    Oct 17, 2018 at 13:21
4
\$\begingroup\$

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

\$\endgroup\$
4
\$\begingroup\$

brainfuck, 112 bytes

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

Try it online!

The actual word generation can probably be optimised further.

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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)
\$\endgroup\$
1
  • 2
    \$\begingroup\$ 39 bytes \$\endgroup\$
    – tsh
    Oct 17, 2018 at 12:39
3
\$\begingroup\$

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.

\$\endgroup\$
0
3
\$\begingroup\$

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].

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Impressive that Stax can compress a string and then compress the entire program again... \$\endgroup\$ Oct 17, 2018 at 17:03
  • \$\begingroup\$ 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) \$\endgroup\$
    – recursive
    Oct 17, 2018 at 18:47
  • \$\begingroup\$ @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. \$\endgroup\$
    – DELETE_ME
    Oct 19, 2018 at 1:18
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

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!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Before looking at your answer, I would have used match against LETTERS or utf8ToInt, so strtoi is a neat trick! \$\endgroup\$
    – Giuseppe
    Oct 17, 2018 at 16:46
  • 1
    \$\begingroup\$ oh, wait utf8ToInt is shorter! Try it online \$\endgroup\$
    – Giuseppe
    Oct 17, 2018 at 16:47
  • 1
    \$\begingroup\$ 57 bytes using LETTERS. \$\endgroup\$ Apr 15, 2019 at 19:54
3
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ This is a code golf question. So you should include your score. \$\endgroup\$
    – Wheat Wizard
    Oct 17, 2018 at 12:28
  • \$\begingroup\$ Very good answer, welcome to PPCG! \$\endgroup\$ Oct 17, 2018 at 17:35
2
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You shouldn't count ⎕←. Btw, ↑⎕A∘⍳⍴¨⊢ is the generalised function — at no extra byte cost: (↑⎕A∘⍳⍴¨⊢)'AWSALILAND' \$\endgroup\$
    – Adám
    Oct 17, 2018 at 12:52
2
\$\begingroup\$

Perl 5, 35 bytes

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

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Why do you add the command line option? would it work if it is removed? What is its purpose? \$\endgroup\$
    – Monolica
    Oct 23, 2018 at 20:09
  • \$\begingroup\$ @Monolica The option sets the Perl version to 5.10 to make say work. \$\endgroup\$
    – nwellnhof
    Oct 24, 2018 at 9:41
  • \$\begingroup\$ 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? \$\endgroup\$
    – Monolica
    Oct 24, 2018 at 15:57
2
\$\begingroup\$

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 
\$\endgroup\$
1
2
\$\begingroup\$

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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 81 bytes \$\endgroup\$ Oct 18, 2018 at 16:16
  • 1
    \$\begingroup\$ @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.. ;) \$\endgroup\$ Oct 18, 2018 at 17:49
1
\$\begingroup\$

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)
\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

Red, 59 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Haskell, 43 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

SOGL V0.12, 16 bytes

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

Try it Here!

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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)
\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ @ceilingcat So wide characters are good for something! ;-) \$\endgroup\$
    – ErikF
    Oct 18, 2018 at 4:59
  • \$\begingroup\$ good use of wide chars \$\endgroup\$
    – Keyu Gan
    Oct 26, 2018 at 17:23
1
\$\begingroup\$

JavaScript (Node.js), 65 63 bytes

i=>[...'AWSALILAND'].map(c=>c.repeat(parseInt(c,36)-9)).join`
`

Try it online!

Explanation:

i=>                         // Prints the result of this function
  [...'AWSALILAND'].map(c=> // Loop over the characters
    c.repeat(               // Repeat the current character
      parseInt(c,36)-9)))   // Character to alphabetical position
        .join`
        `                   // Prints a newline after every new char

Edit: -2 bytes thanks to @BrianH.

\$\endgroup\$
1
  • \$\begingroup\$ by using an anonymous function you can save 2 bytes: i=>[...'AWSALILAND'].map(c=>c.repeat(parseInt(c,36)-9)).join` ` (there's a literal newline in the join argument) \$\endgroup\$
    – Brian H.
    Oct 18, 2018 at 8:07
1
\$\begingroup\$

Julia, 41 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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)
}
\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

><>, 40 bytes

"DNALILASWA"v
 oa~~<v-*88:<
-:0=?^>$:o$1

Try it online!

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 74 68 bytes

for(i in s="AWSALILAND")console.log(s[i].repeat(s.charCodeAt(i)-64))
  • 74->68, -6B for changing for loop to for...in, saving bytes on loop statement, removed increment, and removing statement to save the character.
\$\endgroup\$
1
  • \$\begingroup\$ for(i of"AWSALILAND")console.log(i.repeat(i.charCodeAt()-64)) \$\endgroup\$
    – emanresu A
    Oct 13, 2022 at 4:38

Your Answer

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

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