27
4
We had a prime factorization challenge a while ago, but that challenge is nearly six years old and barely meets our current requirements, so I believe it's time for a new one.
Challenge
Write a program or function that takes as input an integer greater than 1 and outputs or returns a list of its prime factors.
Rules
- Input and output may be given by any standard method and in any standard format.
- Duplicate factors must be included in the output.
- The output may be in any order.
- The input will not be less than 2 or more than 231 - 1.
- Built-ins are allowed, but including a non-builtin solution is encouraged.
Test cases
2 -> 2
3 -> 3
4 -> 2, 2
6 -> 2, 3
8 -> 2, 2, 2
12 -> 2, 2, 3
255 -> 3, 5, 17
256 -> 2, 2, 2, 2, 2, 2, 2, 2
1001 -> 7, 11, 13
223092870 -> 2, 3, 5, 7, 11, 13, 17, 19, 23
2147483646 -> 2, 3, 3, 7, 11, 31, 151, 331
2147483647 -> 2147483647
Scoring
This is code-golf, so the shortest code in bytes wins.
2Would've been much better if you disallowed built-ins. – Buffer Over Read – 2016-12-27T00:25:50.803
2
@TheBitByte Challenges that disallow built-ins are generally looked down upon as Do X without Y challenges, especially since it's sometimes hard to tell whether a solution is technically a built-in.
– ETHproductions – 2016-12-27T00:29:49.9101Well then, enjoy the influx of <5 byte solutions! As I write this, Pyth already does it in 1 byte. – Buffer Over Read – 2016-12-27T00:30:59.137
2@TheBitByte Think of it as a language-by-language challenge, primarily. Try to beat Python's solution, or some other language without a builtin. – isaacg – 2016-12-27T02:30:10.343
1@isaacg Well, language-by-language is a better way of looking at it, I agree. – Buffer Over Read – 2016-12-27T02:47:46.570
I can't seem to find the "standard format" meta post. Are trailing separators allowed? i.e. Input
4
, Output2,2,
? – Brian J – 2016-12-27T14:31:49.297@BrianJ I don't know that we have one. I'll allow that for this challenge. – ETHproductions – 2016-12-27T20:31:27.720
1Why do you mark my question as a duplicate of yours when your question is clearly the duplicate as it has been posted later? Please rectify this decision. – FUZxxl – 2016-12-28T18:24:48.700
1
@FUZxxl It's the community consensus that old questions should be closed as duplicates of newer ones if the newer one has a very clear spec. The main reasons for this are that old challenges tend not to be up-to-date with today's challenge specs, and newer languages can participate in newer challenges. However, as the output format is quite different for your challenge, I've reopened it.
– ETHproductions – 2016-12-28T19:15:05.3971@ETHproductions So is my spec not very clear? Can you explain where it is unclear? You should avoid conflicts-of-interest like these where you use your permissions to close another users question over yours. – FUZxxl – 2016-12-28T20:51:02.230
@FUZxxl After talking with other users, I've decided that closing your question was not the action I should have taken. It would have been better to let the community decide whether your spec is clear enough, and thus whether or not to close it. I apologize for the ruckus I've caused. – ETHproductions – 2016-12-29T00:51:51.867