5
\$\begingroup\$

This question already has an answer here:

The challenge

Given positive integer input n (n>1), calculate the array of unique factorizations of n, not including 1. Order does not matter.

Test cases

2 => [[2]]
3 => [[3]]
4 => [[4],[2,2]]
5 => [[5]]
6 => [[6],[2,3]]
7 => [[7]]
8 => [[8],[2,2,2],[2,4]]
9 => [[9],[3,3]]
10 => [[10],[2,5]]
11 => [[11]]
12 => [[12],[3,4],[3,2,2],[2,6]]

Scoring

This is code-golf, so lowest byte count wins!

\$\endgroup\$

marked as duplicate by nimi code-golf Aug 20 '17 at 5:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Shouldn't 8 have [2, 4]? \$\endgroup\$ – notjagan Aug 20 '17 at 1:04
  • \$\begingroup\$ Yeah, I was dumb. It should also have [2,2,2] \$\endgroup\$ – Zacharý Aug 20 '17 at 1:04
  • \$\begingroup\$ Oddly enough this is quite useful for solving a kenken puzzle \$\endgroup\$ – Conor O'Brien Aug 20 '17 at 3:15
  • \$\begingroup\$ I never saw the problem this was a duplicate of, but it still isn't an exact duplicate: this doesn't require 1, but it IS close enough to be a dupe, now that I see it. \$\endgroup\$ – Zacharý Aug 20 '17 at 12:09
1
\$\begingroup\$

Jelly, 10 bytes

ÆfŒṖP€€Ṣ€Q

Try it online!

ÆfŒṖP€€Ṣ€Q
Æf          - prime factorization
  ŒṖ        - all partitions
    P€€     - Product of each sub-partition
       Ṣ€   - Sort each
         Q  - Remove duplicates
\$\endgroup\$
  • \$\begingroup\$ Accepted, since the post is closed anyways. \$\endgroup\$ – Zacharý Aug 23 '17 at 21:06
2
\$\begingroup\$

Pyth, 9 14 bytes

{mS*Mds./M.pP

Try it online!

How it works

{mS*Mds./M.pP
            P    Prime factorization of [the input]
          .p     All permutations of the prime factorization
       ./M       All partitions of each permutation
      s          Flattened by one level
 m               For each partition:
   *Md               Take the product of each piece
  S                  Sort the products
{                De-duplicate.
\$\endgroup\$
  • \$\begingroup\$ I don't grok Pyth, could you provide an explanation? \$\endgroup\$ – Zacharý Aug 20 '17 at 1:07
  • \$\begingroup\$ @Zacharý Added. \$\endgroup\$ – notjagan Aug 20 '17 at 1:10
  • \$\begingroup\$ This fails on the input 30, since Pyth's ./ only gives sequential partitions. ([3, 10] is absent). I should add something that works like this. \$\endgroup\$ – isaacg Aug 20 '17 at 2:34
  • \$\begingroup\$ @isaacg Aw, that's unfortunate. Fixed for 5 bytes. \$\endgroup\$ – notjagan Aug 20 '17 at 2:45

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