| Bytes | Lang | Time | Link |
|---|---|---|---|
| 049 | Wolfram Language Mathematica | 190909T221201Z | att |
| 014 | Jelly | 210312T180620Z | caird co |
| 019 | Japt | 190909T140422Z | Shaggy |
| 015 | Husk | 201015T061729Z | Razetime |
| 115 | JavaScript | 190909T231405Z | Naruyoko |
| 060 | Haskell | 190909T184557Z | nimi |
| 017 | Jelly | 190909T201805Z | Erik the |
| 070 | JavaScript V8 | 190909T142246Z | Arnauld |
| 013 | 05AB1E | 190909T135143Z | Grimmy |
| 014 | 05AB1E | 190909T133558Z | Kevin Cr |
Wolfram Language (Mathematica), 78 76 ... 51 49 bytes
1∣##&�[##,]~Do~{,2,-#/-##2/. 1:>Print@{##2}}&
Prints the list of decompositions.
Jelly, 14 bytes
ḊœċRẎḍƝẠ×P=¥ʋƇ
How it works
ḊœċRẎḍƝẠ×P=¥ʋƇ - Main link. Takes n on the left
Ḋ - Dequeue; Yield [2, 3, ..., n]
R - Range, Yield [1, 2, ..., n]
œċ - For each integer, 1 ≤ i ≤ n, yield combinations with
replacement of length i from the dequeued range
Ẏ - Tighten into a single list of lists
ʋƇ - Keep those for which the following is true:
× ¥ - Both of the following are true:
Ɲ - Over overlapping pairs:
ḍ - Is the left divisible by the right?
Ạ - Is all true?
× - And:
P - The product
= - Equals n?
Japt, 22 19 bytes
ÆâÃcÅà â f@¶XcXäv)×
ÆâÃcÅà â f@¶XcXäv)× :Implicit input of integer U
Æ :Map the range [0,U)
â : Divisors of U
à :End map
c :Flatten after
Å : Slicing the first element off each
à :Combinations
â :Deduplicate
f :Filter by
@ :Passing each X through the following function
¶ : Test U for equality with
Xc : Concatenate to X
Xä : Consecutive pairs of X
v : Reduced by testing divisibility
) : End concat
× : Reduce by multiplication
JavaScript, 115 bytes
f=(n,a=[],i=1)=>{for(;i++<n;)n%i||(a=a.concat(f(n/i).filter(e=>!(e[0]%i)).map(e=>[i].concat(e))));return n>1?a:[a]}
I will write an explanation later
JavaScript (V8), 73 70 bytes
Prints the tuples in descending order \$(k_m,k_{m-1},...,k_1)\$.
f=(n,d=2,a=[])=>n>1?d>n||f(n,d+1,a,d%a[0]||f(n/d,d,[d,...a])):print(a)
Commented
f = ( // f is a recursive function taking:
n, // n = input
d = 2, // d = current divisor
a = [] // a[] = list of divisors
) => //
n > 1 ? // if n is greater than 1:
d > n || // unless d is greater than n,
f( // do a recursive call with:
n, // -> n unchanged
d + 1, // -> d + 1
a, // -> a[] unchanged
d % a[0] || // unless the previous divisor does not divide the current one,
f( // do another recursive call with:
n / d, // -> n / d
d, // -> d unchanged
[d, ...a] // -> d preprended to a[]
) // end of inner recursive call
) // end of outer recursive call
: // else:
print(a) // this is a valid list of divisors: print it
05AB1E, 13 bytes
Òœ€.œP€`êʒüÖP
Ò # prime factorization of the input
œ€.œ # all partitions
P # product of each sublist
€` # flatten
ê # sorted uniquified
ʒ # filter by:
üÖ # pairwise divisible-by (yields list of 0s or 1s)
P # product (will be 1 iff the list is all 1s)
05AB1E, 17 15 14 bytes
ѦIиæʒPQ}êʒüÖP
Very slow for larger test cases.
-1 byte thanks to @Grimy.
Explanation:
Ñ # Get all divisors of the (implicit) input-integer
¦ # Remove the first value (the 1)
Iи # Repeat this list (flattened) the input amount of times
# i.e. with input 4 we now have [2,4,2,4,2,4,2,4]
æ # Take the powerset of this list
ʒ } # Filter it by:
PQ # Where the product is equal to the (implicit) input
ê # Then sort and uniquify the filtered lists
ʒ # And filter it further by:
ü # Loop over each overlapping pair of values
Ö # And check if the first value is divisible by the second value
P # Check if this is truthy for all pairs
# (after which the result is output implicitly)