Given an integer n as input, return a list containing n, repeated n times. For example, the program would take 5 and turn it into [5,5,5,5,5]. The elements need to be integers, not strings. No built-in functions that accomplish the task are allowed.

This is , so standard rules apply.

  • 43
    \$\begingroup\$ @BrunoE That still doesn’t answer the why. Do you have an actual reason to ban built-ins? To quote xnor: In general, if your challenge is too simple to be interesting, it won't be saved by banning things. \$\endgroup\$ – Lynn Aug 21 '17 at 10:52
  • 13
    \$\begingroup\$ @BrunoE while I agree with the sentiment, we prefer objectivity here at ppcg. Either something is or is not valid, opinions shouldn't come into the equation. \$\endgroup\$ – Skidsdev Aug 21 '17 at 11:57
  • 5
    \$\begingroup\$ @BrunoE The specs must be made such that one can indisputably decide whether an entry is valid or not. Please share your thoughts on the existing answers and make the specs more objective when it comes to built-in. \$\endgroup\$ – Mr. Xcoder Aug 21 '17 at 12:42
  • 6
    \$\begingroup\$ I'm still confused what counts as a "built-in" for this task. Is Python's * operator ok? What's an example of a built-in that isn't ok? \$\endgroup\$ – Steve Bennett Aug 22 '17 at 7:14
  • 8
    \$\begingroup\$ I am suprised nobody has mentioned this yet, but we have a sandbox for challenges where you can post them to get feedback on them, before they go live. This way you might've prevented discussing the rules of the challenge while others already submitted their answers. \$\endgroup\$ – JAD Aug 23 '17 at 6:34

97 Answers 97


K (oK), 4 bytes



Try it online!


5#5 means take from 5, 5 times. But doesn't appear we can do the same trick as APL/J to reduce this one down.

x#x: / the solution
  x: / save input as x
x#   / take from it x times

Stax, 3 bytes


Run and debug it

Internally it actually converts an integer to the array required but the implicit output changes it to codepoints. By default, output by codepoint is allowed though.


]      Convert input to singleton
 x*    Repeat input times
  • 1
    \$\begingroup\$ y* does it without using the codepoint exemption. y is the first line of standard input by default. \$\endgroup\$ – recursive Mar 26 '18 at 23:06
  • \$\begingroup\$ True, but "The elements need to be integers, not strings". \$\endgroup\$ – Weijun Zhou Mar 27 '18 at 1:21

12-basic, 17 14 bytes




Excel VBA, 26 Bytes

Anonymous VBE immediate window function that takes input, n from range [A1] and returns an array object X with n stuffed into it n times.

x=Split([Rept(A1&" ",A1)])

Japt -m, 1 byte


Try it online!

-m is a flag that runs the program on each item in the input. Because the input is a number, it gets turned into a range first. N is the input.


Gol><>, 7 bytes


This uses the convenient 'D' - Debug operator, which outputs the stack!

I       //Get integer input
 :R:    //Repeat input, double the number
    ~D; //Delete the last item in the stack(to get the right number) and output the entire stack with debug

Try it online!

  • \$\begingroup\$ lol, there's already a 5 byte one \$\endgroup\$ – ASCII-only Feb 22 '19 at 11:25
  • \$\begingroup\$ @ASCII-only I didn't see that... Well, at the very least mine doesn't use a header, it does it on its own \$\endgroup\$ – KrystosTheOverlord Feb 22 '19 at 22:06
  • \$\begingroup\$ Yeah well that's just the difference between a function and a program :P \$\endgroup\$ – ASCII-only Feb 22 '19 at 22:53

Kotlin, 20 19 15 bytes

Shorter Kotlin answer using the List constructor.


Try it online!


// lambda function
{ n ->
    List(n) { n }  // create a List of n Ints where each item is n

Because List is actually an interface, List() is actually a function that creates a List of the specified type (here figured out through inference) and a fixed size, using the given lambda to initialize the value of each item. { n } means the lambda will always return the value of n.

  • \$\begingroup\$ 15 \$\endgroup\$ – ASCII-only Feb 22 '19 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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