# Turn an integer n into a list containing it n times

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.

• @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. – Lynn Aug 21 '17 at 10:52
• @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. – Skidsdev Aug 21 '17 at 11:57
• @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. – Mr. Xcoder Aug 21 '17 at 12:42
• 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? – Steve Bennett Aug 22 '17 at 7:14
• 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. – JAD Aug 23 '17 at 6:34

# K (oK), 4 bytes

Solution:

x#x:


Try it online!

Explanation:

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

]x*


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.

## Explanation

]      Convert input to singleton
x*    Repeat input times

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

# 12-basic, 17 14 bytes

?[X=INPUT()]*X


Try

# 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

N


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

I:R:~D;


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!

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

# Kotlin, 2019 15 bytes

Shorter Kotlin answer using the List constructor.

{n->List(n){n}}


Try it online!

Ungolfed:

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

• 15 – ASCII-only Feb 22 '19 at 11:19