A factorization gameList all multiplicative partitions of nPalindromic Prime FactorsSimplify a square rootList all multiplicative partitions of nComposite FactorizationFill in an increasing sequence with as many numbers as possibleCollapse consecutive integersArray FactorizationNon-overlapping Matrix Sum
Does a reincarnated Draconic Bloodline Sorcerer save his class abilities?
How did Ron get five hundred Chocolate Frog cards?
SuperTuxKart 0.9.3-2 has no online multiplayer?
What is the type of this light bulb?
Why exactly is the answer 50 Ohms?
'The Kukhtarev's model' or 'Kukhtarev's model' ('John's car' or 'The John's car')?
Why "come" instead of "go"?
Is it possible to cross Arctic Ocean on ski/kayak undetectable now?
What does "なかなか" mean here?
Legality of creating a SE replica using SE's content
How can I cut a metal pipe while preserving the wires inside?
'Pound' meaning in this context
Is there any restriction in entering the South American countries multiple times in one year?
Where is the 'zone of reversed commands...'?
What is the German word for: "It only works when I try to show you how it does not work"?
How can demon technology be prevented from surpassing humans?
A fast aquatic predator with multiple eyes and pupils. Would these eyes be possible?
Was Hakhel performed in separation of men and women?
Is Having my Players Control Two Parties a Good Idea?
Dynamics m, r, s, and z. What do they mean?
Can you take an Immortal Phoenix out of the game?
Is the value of a probability density function for a given input a point, a range, or both?
How honest to be with US immigration about uncertainty about travel plans?
'provocative' vs 'sexy'
A factorization game
List all multiplicative partitions of nPalindromic Prime FactorsSimplify a square rootList all multiplicative partitions of nComposite FactorizationFill in an increasing sequence with as many numbers as possibleCollapse consecutive integersArray FactorizationNon-overlapping Matrix Sum
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
$begingroup$
Input
A single integer $1 leq x leq 10^15$.
Output
The maximum number of distinct positive integers that have the product $x$.
Examples
Input: 1099511627776. Output: 9. One possible optimal list of factors is: (1, 2, 4, 8, 16, 32, 64, 128, 4096).
Input: 127381. Output 4. One possible optimal list of factors is: (1, 17, 59, 127).
Related to this old question.
code-golf math
$endgroup$
|
show 2 more comments
$begingroup$
Input
A single integer $1 leq x leq 10^15$.
Output
The maximum number of distinct positive integers that have the product $x$.
Examples
Input: 1099511627776. Output: 9. One possible optimal list of factors is: (1, 2, 4, 8, 16, 32, 64, 128, 4096).
Input: 127381. Output 4. One possible optimal list of factors is: (1, 17, 59, 127).
Related to this old question.
code-golf math
$endgroup$
9
$begingroup$
Could you add a few more test cases? (Preferably of reasonable size.)
$endgroup$
– Arnauld
May 2 at 14:31
8
$begingroup$
Given your comments on most answers: if you're looking for efficient code instead, this should definitely not be tagged ascode-golf
. You may consider eitherfastest-code
orfastest-algorithm
for an upcoming challenge. If you really wanted all answers to work in a limited time within the specified range, it should have been explicitly mentioned. (And I would have recommended a smaller range so that it does not conflict withcode-golf
entirely.)
$endgroup$
– Arnauld
May 2 at 15:00
$begingroup$
@Arnauld No I am careful to make it code-golf and no one is judged for that. It would just be cool if the code could run for the input ranges specfied.
$endgroup$
– Anush
May 2 at 15:01
5
$begingroup$
Quoting xnor: If it's not mandatory, answers won't do it.
$endgroup$
– Arnauld
May 2 at 15:09
1
$begingroup$
Forx=1, 2, ...
I getf(x)=1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 3, 4, 2, 3
which I do not find in OEIS. It is clear enough that records will appear for factorial numbersx
. For example the smallestx
such thatf(x)=13
will be13!
. I guessf
depends only on the exponents of the prime factorization. So to findf(13^4*19^7*29^2)
we might simplify tof(2^7*3^4*5^2)
.
$endgroup$
– Jeppe Stig Nielsen
May 8 at 1:30
|
show 2 more comments
$begingroup$
Input
A single integer $1 leq x leq 10^15$.
Output
The maximum number of distinct positive integers that have the product $x$.
Examples
Input: 1099511627776. Output: 9. One possible optimal list of factors is: (1, 2, 4, 8, 16, 32, 64, 128, 4096).
Input: 127381. Output 4. One possible optimal list of factors is: (1, 17, 59, 127).
Related to this old question.
code-golf math
$endgroup$
Input
A single integer $1 leq x leq 10^15$.
Output
The maximum number of distinct positive integers that have the product $x$.
Examples
Input: 1099511627776. Output: 9. One possible optimal list of factors is: (1, 2, 4, 8, 16, 32, 64, 128, 4096).
Input: 127381. Output 4. One possible optimal list of factors is: (1, 17, 59, 127).
Related to this old question.
code-golf math
code-golf math
edited May 2 at 14:30
Anush
asked May 2 at 13:47
AnushAnush
1,09410 silver badges37 bronze badges
1,09410 silver badges37 bronze badges
9
$begingroup$
Could you add a few more test cases? (Preferably of reasonable size.)
$endgroup$
– Arnauld
May 2 at 14:31
8
$begingroup$
Given your comments on most answers: if you're looking for efficient code instead, this should definitely not be tagged ascode-golf
. You may consider eitherfastest-code
orfastest-algorithm
for an upcoming challenge. If you really wanted all answers to work in a limited time within the specified range, it should have been explicitly mentioned. (And I would have recommended a smaller range so that it does not conflict withcode-golf
entirely.)
$endgroup$
– Arnauld
May 2 at 15:00
$begingroup$
@Arnauld No I am careful to make it code-golf and no one is judged for that. It would just be cool if the code could run for the input ranges specfied.
$endgroup$
– Anush
May 2 at 15:01
5
$begingroup$
Quoting xnor: If it's not mandatory, answers won't do it.
$endgroup$
– Arnauld
May 2 at 15:09
1
$begingroup$
Forx=1, 2, ...
I getf(x)=1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 3, 4, 2, 3
which I do not find in OEIS. It is clear enough that records will appear for factorial numbersx
. For example the smallestx
such thatf(x)=13
will be13!
. I guessf
depends only on the exponents of the prime factorization. So to findf(13^4*19^7*29^2)
we might simplify tof(2^7*3^4*5^2)
.
$endgroup$
– Jeppe Stig Nielsen
May 8 at 1:30
|
show 2 more comments
9
$begingroup$
Could you add a few more test cases? (Preferably of reasonable size.)
$endgroup$
– Arnauld
May 2 at 14:31
8
$begingroup$
Given your comments on most answers: if you're looking for efficient code instead, this should definitely not be tagged ascode-golf
. You may consider eitherfastest-code
orfastest-algorithm
for an upcoming challenge. If you really wanted all answers to work in a limited time within the specified range, it should have been explicitly mentioned. (And I would have recommended a smaller range so that it does not conflict withcode-golf
entirely.)
$endgroup$
– Arnauld
May 2 at 15:00
$begingroup$
@Arnauld No I am careful to make it code-golf and no one is judged for that. It would just be cool if the code could run for the input ranges specfied.
$endgroup$
– Anush
May 2 at 15:01
5
$begingroup$
Quoting xnor: If it's not mandatory, answers won't do it.
$endgroup$
– Arnauld
May 2 at 15:09
1
$begingroup$
Forx=1, 2, ...
I getf(x)=1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 3, 4, 2, 3
which I do not find in OEIS. It is clear enough that records will appear for factorial numbersx
. For example the smallestx
such thatf(x)=13
will be13!
. I guessf
depends only on the exponents of the prime factorization. So to findf(13^4*19^7*29^2)
we might simplify tof(2^7*3^4*5^2)
.
$endgroup$
– Jeppe Stig Nielsen
May 8 at 1:30
9
9
$begingroup$
Could you add a few more test cases? (Preferably of reasonable size.)
$endgroup$
– Arnauld
May 2 at 14:31
$begingroup$
Could you add a few more test cases? (Preferably of reasonable size.)
$endgroup$
– Arnauld
May 2 at 14:31
8
8
$begingroup$
Given your comments on most answers: if you're looking for efficient code instead, this should definitely not be tagged as
code-golf
. You may consider either fastest-code
or fastest-algorithm
for an upcoming challenge. If you really wanted all answers to work in a limited time within the specified range, it should have been explicitly mentioned. (And I would have recommended a smaller range so that it does not conflict with code-golf
entirely.)$endgroup$
– Arnauld
May 2 at 15:00
$begingroup$
Given your comments on most answers: if you're looking for efficient code instead, this should definitely not be tagged as
code-golf
. You may consider either fastest-code
or fastest-algorithm
for an upcoming challenge. If you really wanted all answers to work in a limited time within the specified range, it should have been explicitly mentioned. (And I would have recommended a smaller range so that it does not conflict with code-golf
entirely.)$endgroup$
– Arnauld
May 2 at 15:00
$begingroup$
@Arnauld No I am careful to make it code-golf and no one is judged for that. It would just be cool if the code could run for the input ranges specfied.
$endgroup$
– Anush
May 2 at 15:01
$begingroup$
@Arnauld No I am careful to make it code-golf and no one is judged for that. It would just be cool if the code could run for the input ranges specfied.
$endgroup$
– Anush
May 2 at 15:01
5
5
$begingroup$
Quoting xnor: If it's not mandatory, answers won't do it.
$endgroup$
– Arnauld
May 2 at 15:09
$begingroup$
Quoting xnor: If it's not mandatory, answers won't do it.
$endgroup$
– Arnauld
May 2 at 15:09
1
1
$begingroup$
For
x=1, 2, ...
I get f(x)=1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 3, 4, 2, 3
which I do not find in OEIS. It is clear enough that records will appear for factorial numbers x
. For example the smallest x
such that f(x)=13
will be 13!
. I guess f
depends only on the exponents of the prime factorization. So to find f(13^4*19^7*29^2)
we might simplify to f(2^7*3^4*5^2)
.$endgroup$
– Jeppe Stig Nielsen
May 8 at 1:30
$begingroup$
For
x=1, 2, ...
I get f(x)=1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 3, 4, 2, 3
which I do not find in OEIS. It is clear enough that records will appear for factorial numbers x
. For example the smallest x
such that f(x)=13
will be 13!
. I guess f
depends only on the exponents of the prime factorization. So to find f(13^4*19^7*29^2)
we might simplify to f(2^7*3^4*5^2)
.$endgroup$
– Jeppe Stig Nielsen
May 8 at 1:30
|
show 2 more comments
13 Answers
13
active
oldest
votes
$begingroup$
Wolfram Language (Mathematica), 52 bytes
Max[Length/@Cases[Subsets@Divisors@#,a__/;1a==#]]&
Try it online!
4-bytes saved thanks to @attinat
Here is also a 153 bytes version that calculates 1099511627776
and 10^15
Max[Length/@Table[s=RandomSample@Flatten[Table@@@FactorInteger[#]];Last@Select[Times@@@TakeList[s,#]&/@IntegerPartitions@Length@s,DuplicateFreeQ],5!]]+1&
Try it online!
The result for 10^15
is 12
1, 2, 4, 5, 10, 16, 25, 40, 50, 100, 125, 250
$endgroup$
$begingroup$
Crashes with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
7
$begingroup$
@Anush It doesn't crash. Just needs memory. You didn't say anything about memory limitations. This is code golf
$endgroup$
– J42161217
May 2 at 14:46
$begingroup$
Yes I realise. It just would be nice if you could actually run the code the input ranges specified in the question.
$endgroup$
– Anush
May 2 at 14:49
6
$begingroup$
@Anush This is code-golf. Not nice answers. Please specify your criteria. An answer is either valid or not. I think the problem here is the question... Maybe you should change it to "most sufficient algorithm"
$endgroup$
– J42161217
May 2 at 14:54
3
$begingroup$
@Anush I made an edit in my answer and added one more version which is really fast and efficient in case you want to check it
$endgroup$
– J42161217
May 2 at 22:36
|
show 5 more comments
$begingroup$
Wolfram Language (Mathematica), 38 bytes
(c=n=#;If[i∣n,n/=i,--c]~Do~i,n;c)&
Try it online!
Greedy algorithm. Times out on TIO on larger inputs such as 1099511627776
.
$endgroup$
add a comment
|
$begingroup$
05AB1E, 9 bytes
Very inefficient. Will time out on TIO for numbers with a large amount of divisors.
ÑæʒPQ}€gZ
Try it online!
Explanation
Ñ # push a list of divisors of the input
æ # push the powerset of that list
ʒPQ} # filter, keep only the lists whose product is the input
€g # get the length of each
Z # take the maximum
$endgroup$
$begingroup$
Your TIO code seems to output 3 instead of 9.
$endgroup$
– Anush
May 2 at 14:00
$begingroup$
@Anush: It is a different number than your example (since that one times out due to to many factors). I probably should use a more distinct example.
$endgroup$
– Emigna
May 2 at 14:01
$begingroup$
€gZ
is a bit more efficient thanéθg
for the same bytecount.
$endgroup$
– Grimy
May 3 at 11:04
$begingroup$
@Grimy: True. It won't do much difference as it's the filter that is the big bad guy here, but it doesn't hurt being a bit more efficient :)
$endgroup$
– Emigna
May 3 at 11:20
add a comment
|
$begingroup$
Perl 6, 38 bytes
$!=$_;+grep $!%%$_&&($!/=$_),1..$_
Try it online!
Takes the greedy approach to selecting divisors.
$endgroup$
$begingroup$
Doesn't terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:42
6
$begingroup$
@Anush Well, it terminates eventually. Generally, the answer is valid if the program's algorithm would work with any input, if it were given as much memory and time as it wanted. Since this is code-golf, I optimised it for code length, not algorithmic complexity
$endgroup$
– Jo King
May 2 at 14:49
add a comment
|
$begingroup$
Javascript (ES6), 39 bytes
f=(n,i=0)=>n%++i?n>i&&f(n,i):1+f(n/i,i)
There's probably a few bytes that can be saved here and there. Just uses the greedy algorithm for the factors.
$endgroup$
add a comment
|
$begingroup$
Jelly, 9 bytes
ŒPP=³ƊƇẈṀ
Try it online!
-1 byte thanks to someone
-2 bytes thanks to ErikTheOutgolfer
$endgroup$
$begingroup$
While preparing a input for the OEIS superseeker, I created a 11-byte likely golfable Jelly program (that uses a different approach), and am unlikely to post a Jelly answer so I'll pretend I golfed a byte from your solution:ÆE×8‘½’:2S‘
(it works with the power of the OEIS "formula" section for A003056). Disclaimer: it might be wrong, but it works on the test cases.
$endgroup$
– someone
May 2 at 14:17
$begingroup$
It doesn't seem to terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
@someone doesn't work for 36 but thanks
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@Anush yeah, it's really slow because i code-golfed it, not optimized for efficiency
$endgroup$
– HyperNeutrino
May 2 at 14:46
1
$begingroup$
You can removeÆD
, it's not like there are more partitions that are going to be created like this, it's just going to take a lot more time (times out for $xge21$).
$endgroup$
– Erik the Outgolfer
May 2 at 15:29
|
show 3 more comments
$begingroup$
Japt -h
, 13 bytes
â à f_׶UÃmÊn
Try it
$endgroup$
add a comment
|
$begingroup$
Brachylog, 8 bytes
f;?⟨⊇×⟩l
Try it online!
(The naive approach, ~×≠lᶠ⌉
, generates an infinite number of solutions with extra 1s before eliminating them with ≠
, and thus fails to actually terminate. It's not a problem, though, since it's for the same byte count!)
Takes input through the input variable and output through the output variable. The header on TIO contains a copy of most of the code for the sake of showing you what the factor list is, but this works perfectly fine without it. Since ⊇
gives larger sublists first, this predicate essentially does the same thing as most other answers, but without explicitly generating and filtering the complete powerset of the factors, thanks to backtracking.
The output
l is the length of
⊇ a sublist (the largest satisfying these constraints)
f of the factors of
the input
; ⟨ ⟩ which
× with its elements multiplied together
? is the input.
$endgroup$
add a comment
|
$begingroup$
Scala, 77 bytes
def f(n:Long)=var(m,c,i)=(n,1,2L);while(i<=m)if(m%i==0)m/=i;c+=1;i+=1;c
Try it online!
$endgroup$
add a comment
|
$begingroup$
Gaia, 10 9 bytes
Π=
dz↑⁇(l
Try it online!
Follows the same "algorithm" as seen elsewhere -- filter the divisor powerset for the longest with product equal to the number and return its length.
| helper function
Π= | is prod(list)==n (implicit)?
|
| main function; implicitly takes n
dz | divisor powerset (in decreasing order of size)
↑⁇ | filter by helper function
(l | take the first element and take the length (implicitly output)
$endgroup$
add a comment
|
$begingroup$
Clam, 15 bytes
p}_`nq#:;qQ@s~Q
TIO link coming soon (when dennis pulls)
Basically a port of @Emigna's 05AB1E solution.
Explanation
- Implicit Q = first input
p - Print...
} - The last element of...
_ - Sorted...
`nq - Lengths of... (map q => q.len)
@s - Items in powerset of
~Q - Proper divisors of Q
# - Where... (filter)
;q - Product of subset
: - Equals...
Q - Q
$endgroup$
add a comment
|
$begingroup$
C# (Visual C# Interactive Compiler), 54 bytes
int f(int n,int i=0)=>n%++i<1?1+f(n/i,i):n>i?f(n,i):0;
Uses the same approach as @vrugtehagel's and @JoKing's answers.
Try it online!
$endgroup$
$begingroup$
Assuming I implemented your logic correctly, a 53-byte solution (that I couldn't rid of the "return" keyword): Try it online!
$endgroup$
– someone
May 3 at 2:23
1
$begingroup$
@someone Thanks, but according to meta, functions have to be reusable. Also, I'm don't know if it is acceptable to have declarations outside of the function leave out a trailing semicolon, may make a meta post on that.
$endgroup$
– Embodiment of Ignorance
May 3 at 2:37
add a comment
|
$begingroup$
Ruby, 34 bytes
Obviously times out on that massive number, but will eventually time out if given enough time on another machine.
->n(1..n).countn%e<1?n/=e:p
Try it online!
$endgroup$
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f185062%2fa-factorization-game%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Wolfram Language (Mathematica), 52 bytes
Max[Length/@Cases[Subsets@Divisors@#,a__/;1a==#]]&
Try it online!
4-bytes saved thanks to @attinat
Here is also a 153 bytes version that calculates 1099511627776
and 10^15
Max[Length/@Table[s=RandomSample@Flatten[Table@@@FactorInteger[#]];Last@Select[Times@@@TakeList[s,#]&/@IntegerPartitions@Length@s,DuplicateFreeQ],5!]]+1&
Try it online!
The result for 10^15
is 12
1, 2, 4, 5, 10, 16, 25, 40, 50, 100, 125, 250
$endgroup$
$begingroup$
Crashes with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
7
$begingroup$
@Anush It doesn't crash. Just needs memory. You didn't say anything about memory limitations. This is code golf
$endgroup$
– J42161217
May 2 at 14:46
$begingroup$
Yes I realise. It just would be nice if you could actually run the code the input ranges specified in the question.
$endgroup$
– Anush
May 2 at 14:49
6
$begingroup$
@Anush This is code-golf. Not nice answers. Please specify your criteria. An answer is either valid or not. I think the problem here is the question... Maybe you should change it to "most sufficient algorithm"
$endgroup$
– J42161217
May 2 at 14:54
3
$begingroup$
@Anush I made an edit in my answer and added one more version which is really fast and efficient in case you want to check it
$endgroup$
– J42161217
May 2 at 22:36
|
show 5 more comments
$begingroup$
Wolfram Language (Mathematica), 52 bytes
Max[Length/@Cases[Subsets@Divisors@#,a__/;1a==#]]&
Try it online!
4-bytes saved thanks to @attinat
Here is also a 153 bytes version that calculates 1099511627776
and 10^15
Max[Length/@Table[s=RandomSample@Flatten[Table@@@FactorInteger[#]];Last@Select[Times@@@TakeList[s,#]&/@IntegerPartitions@Length@s,DuplicateFreeQ],5!]]+1&
Try it online!
The result for 10^15
is 12
1, 2, 4, 5, 10, 16, 25, 40, 50, 100, 125, 250
$endgroup$
$begingroup$
Crashes with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
7
$begingroup$
@Anush It doesn't crash. Just needs memory. You didn't say anything about memory limitations. This is code golf
$endgroup$
– J42161217
May 2 at 14:46
$begingroup$
Yes I realise. It just would be nice if you could actually run the code the input ranges specified in the question.
$endgroup$
– Anush
May 2 at 14:49
6
$begingroup$
@Anush This is code-golf. Not nice answers. Please specify your criteria. An answer is either valid or not. I think the problem here is the question... Maybe you should change it to "most sufficient algorithm"
$endgroup$
– J42161217
May 2 at 14:54
3
$begingroup$
@Anush I made an edit in my answer and added one more version which is really fast and efficient in case you want to check it
$endgroup$
– J42161217
May 2 at 22:36
|
show 5 more comments
$begingroup$
Wolfram Language (Mathematica), 52 bytes
Max[Length/@Cases[Subsets@Divisors@#,a__/;1a==#]]&
Try it online!
4-bytes saved thanks to @attinat
Here is also a 153 bytes version that calculates 1099511627776
and 10^15
Max[Length/@Table[s=RandomSample@Flatten[Table@@@FactorInteger[#]];Last@Select[Times@@@TakeList[s,#]&/@IntegerPartitions@Length@s,DuplicateFreeQ],5!]]+1&
Try it online!
The result for 10^15
is 12
1, 2, 4, 5, 10, 16, 25, 40, 50, 100, 125, 250
$endgroup$
Wolfram Language (Mathematica), 52 bytes
Max[Length/@Cases[Subsets@Divisors@#,a__/;1a==#]]&
Try it online!
4-bytes saved thanks to @attinat
Here is also a 153 bytes version that calculates 1099511627776
and 10^15
Max[Length/@Table[s=RandomSample@Flatten[Table@@@FactorInteger[#]];Last@Select[Times@@@TakeList[s,#]&/@IntegerPartitions@Length@s,DuplicateFreeQ],5!]]+1&
Try it online!
The result for 10^15
is 12
1, 2, 4, 5, 10, 16, 25, 40, 50, 100, 125, 250
edited May 3 at 13:50
answered May 2 at 14:05
J42161217J42161217
15.2k2 gold badges15 silver badges56 bronze badges
15.2k2 gold badges15 silver badges56 bronze badges
$begingroup$
Crashes with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
7
$begingroup$
@Anush It doesn't crash. Just needs memory. You didn't say anything about memory limitations. This is code golf
$endgroup$
– J42161217
May 2 at 14:46
$begingroup$
Yes I realise. It just would be nice if you could actually run the code the input ranges specified in the question.
$endgroup$
– Anush
May 2 at 14:49
6
$begingroup$
@Anush This is code-golf. Not nice answers. Please specify your criteria. An answer is either valid or not. I think the problem here is the question... Maybe you should change it to "most sufficient algorithm"
$endgroup$
– J42161217
May 2 at 14:54
3
$begingroup$
@Anush I made an edit in my answer and added one more version which is really fast and efficient in case you want to check it
$endgroup$
– J42161217
May 2 at 22:36
|
show 5 more comments
$begingroup$
Crashes with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
7
$begingroup$
@Anush It doesn't crash. Just needs memory. You didn't say anything about memory limitations. This is code golf
$endgroup$
– J42161217
May 2 at 14:46
$begingroup$
Yes I realise. It just would be nice if you could actually run the code the input ranges specified in the question.
$endgroup$
– Anush
May 2 at 14:49
6
$begingroup$
@Anush This is code-golf. Not nice answers. Please specify your criteria. An answer is either valid or not. I think the problem here is the question... Maybe you should change it to "most sufficient algorithm"
$endgroup$
– J42161217
May 2 at 14:54
3
$begingroup$
@Anush I made an edit in my answer and added one more version which is really fast and efficient in case you want to check it
$endgroup$
– J42161217
May 2 at 22:36
$begingroup$
Crashes with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
Crashes with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
7
7
$begingroup$
@Anush It doesn't crash. Just needs memory. You didn't say anything about memory limitations. This is code golf
$endgroup$
– J42161217
May 2 at 14:46
$begingroup$
@Anush It doesn't crash. Just needs memory. You didn't say anything about memory limitations. This is code golf
$endgroup$
– J42161217
May 2 at 14:46
$begingroup$
Yes I realise. It just would be nice if you could actually run the code the input ranges specified in the question.
$endgroup$
– Anush
May 2 at 14:49
$begingroup$
Yes I realise. It just would be nice if you could actually run the code the input ranges specified in the question.
$endgroup$
– Anush
May 2 at 14:49
6
6
$begingroup$
@Anush This is code-golf. Not nice answers. Please specify your criteria. An answer is either valid or not. I think the problem here is the question... Maybe you should change it to "most sufficient algorithm"
$endgroup$
– J42161217
May 2 at 14:54
$begingroup$
@Anush This is code-golf. Not nice answers. Please specify your criteria. An answer is either valid or not. I think the problem here is the question... Maybe you should change it to "most sufficient algorithm"
$endgroup$
– J42161217
May 2 at 14:54
3
3
$begingroup$
@Anush I made an edit in my answer and added one more version which is really fast and efficient in case you want to check it
$endgroup$
– J42161217
May 2 at 22:36
$begingroup$
@Anush I made an edit in my answer and added one more version which is really fast and efficient in case you want to check it
$endgroup$
– J42161217
May 2 at 22:36
|
show 5 more comments
$begingroup$
Wolfram Language (Mathematica), 38 bytes
(c=n=#;If[i∣n,n/=i,--c]~Do~i,n;c)&
Try it online!
Greedy algorithm. Times out on TIO on larger inputs such as 1099511627776
.
$endgroup$
add a comment
|
$begingroup$
Wolfram Language (Mathematica), 38 bytes
(c=n=#;If[i∣n,n/=i,--c]~Do~i,n;c)&
Try it online!
Greedy algorithm. Times out on TIO on larger inputs such as 1099511627776
.
$endgroup$
add a comment
|
$begingroup$
Wolfram Language (Mathematica), 38 bytes
(c=n=#;If[i∣n,n/=i,--c]~Do~i,n;c)&
Try it online!
Greedy algorithm. Times out on TIO on larger inputs such as 1099511627776
.
$endgroup$
Wolfram Language (Mathematica), 38 bytes
(c=n=#;If[i∣n,n/=i,--c]~Do~i,n;c)&
Try it online!
Greedy algorithm. Times out on TIO on larger inputs such as 1099511627776
.
answered May 3 at 4:38
attinatattinat
3,0763 silver badges11 bronze badges
3,0763 silver badges11 bronze badges
add a comment
|
add a comment
|
$begingroup$
05AB1E, 9 bytes
Very inefficient. Will time out on TIO for numbers with a large amount of divisors.
ÑæʒPQ}€gZ
Try it online!
Explanation
Ñ # push a list of divisors of the input
æ # push the powerset of that list
ʒPQ} # filter, keep only the lists whose product is the input
€g # get the length of each
Z # take the maximum
$endgroup$
$begingroup$
Your TIO code seems to output 3 instead of 9.
$endgroup$
– Anush
May 2 at 14:00
$begingroup$
@Anush: It is a different number than your example (since that one times out due to to many factors). I probably should use a more distinct example.
$endgroup$
– Emigna
May 2 at 14:01
$begingroup$
€gZ
is a bit more efficient thanéθg
for the same bytecount.
$endgroup$
– Grimy
May 3 at 11:04
$begingroup$
@Grimy: True. It won't do much difference as it's the filter that is the big bad guy here, but it doesn't hurt being a bit more efficient :)
$endgroup$
– Emigna
May 3 at 11:20
add a comment
|
$begingroup$
05AB1E, 9 bytes
Very inefficient. Will time out on TIO for numbers with a large amount of divisors.
ÑæʒPQ}€gZ
Try it online!
Explanation
Ñ # push a list of divisors of the input
æ # push the powerset of that list
ʒPQ} # filter, keep only the lists whose product is the input
€g # get the length of each
Z # take the maximum
$endgroup$
$begingroup$
Your TIO code seems to output 3 instead of 9.
$endgroup$
– Anush
May 2 at 14:00
$begingroup$
@Anush: It is a different number than your example (since that one times out due to to many factors). I probably should use a more distinct example.
$endgroup$
– Emigna
May 2 at 14:01
$begingroup$
€gZ
is a bit more efficient thanéθg
for the same bytecount.
$endgroup$
– Grimy
May 3 at 11:04
$begingroup$
@Grimy: True. It won't do much difference as it's the filter that is the big bad guy here, but it doesn't hurt being a bit more efficient :)
$endgroup$
– Emigna
May 3 at 11:20
add a comment
|
$begingroup$
05AB1E, 9 bytes
Very inefficient. Will time out on TIO for numbers with a large amount of divisors.
ÑæʒPQ}€gZ
Try it online!
Explanation
Ñ # push a list of divisors of the input
æ # push the powerset of that list
ʒPQ} # filter, keep only the lists whose product is the input
€g # get the length of each
Z # take the maximum
$endgroup$
05AB1E, 9 bytes
Very inefficient. Will time out on TIO for numbers with a large amount of divisors.
ÑæʒPQ}€gZ
Try it online!
Explanation
Ñ # push a list of divisors of the input
æ # push the powerset of that list
ʒPQ} # filter, keep only the lists whose product is the input
€g # get the length of each
Z # take the maximum
edited May 3 at 11:21
answered May 2 at 13:58
EmignaEmigna
50.5k5 gold badges37 silver badges153 bronze badges
50.5k5 gold badges37 silver badges153 bronze badges
$begingroup$
Your TIO code seems to output 3 instead of 9.
$endgroup$
– Anush
May 2 at 14:00
$begingroup$
@Anush: It is a different number than your example (since that one times out due to to many factors). I probably should use a more distinct example.
$endgroup$
– Emigna
May 2 at 14:01
$begingroup$
€gZ
is a bit more efficient thanéθg
for the same bytecount.
$endgroup$
– Grimy
May 3 at 11:04
$begingroup$
@Grimy: True. It won't do much difference as it's the filter that is the big bad guy here, but it doesn't hurt being a bit more efficient :)
$endgroup$
– Emigna
May 3 at 11:20
add a comment
|
$begingroup$
Your TIO code seems to output 3 instead of 9.
$endgroup$
– Anush
May 2 at 14:00
$begingroup$
@Anush: It is a different number than your example (since that one times out due to to many factors). I probably should use a more distinct example.
$endgroup$
– Emigna
May 2 at 14:01
$begingroup$
€gZ
is a bit more efficient thanéθg
for the same bytecount.
$endgroup$
– Grimy
May 3 at 11:04
$begingroup$
@Grimy: True. It won't do much difference as it's the filter that is the big bad guy here, but it doesn't hurt being a bit more efficient :)
$endgroup$
– Emigna
May 3 at 11:20
$begingroup$
Your TIO code seems to output 3 instead of 9.
$endgroup$
– Anush
May 2 at 14:00
$begingroup$
Your TIO code seems to output 3 instead of 9.
$endgroup$
– Anush
May 2 at 14:00
$begingroup$
@Anush: It is a different number than your example (since that one times out due to to many factors). I probably should use a more distinct example.
$endgroup$
– Emigna
May 2 at 14:01
$begingroup$
@Anush: It is a different number than your example (since that one times out due to to many factors). I probably should use a more distinct example.
$endgroup$
– Emigna
May 2 at 14:01
$begingroup$
€gZ
is a bit more efficient than éθg
for the same bytecount.$endgroup$
– Grimy
May 3 at 11:04
$begingroup$
€gZ
is a bit more efficient than éθg
for the same bytecount.$endgroup$
– Grimy
May 3 at 11:04
$begingroup$
@Grimy: True. It won't do much difference as it's the filter that is the big bad guy here, but it doesn't hurt being a bit more efficient :)
$endgroup$
– Emigna
May 3 at 11:20
$begingroup$
@Grimy: True. It won't do much difference as it's the filter that is the big bad guy here, but it doesn't hurt being a bit more efficient :)
$endgroup$
– Emigna
May 3 at 11:20
add a comment
|
$begingroup$
Perl 6, 38 bytes
$!=$_;+grep $!%%$_&&($!/=$_),1..$_
Try it online!
Takes the greedy approach to selecting divisors.
$endgroup$
$begingroup$
Doesn't terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:42
6
$begingroup$
@Anush Well, it terminates eventually. Generally, the answer is valid if the program's algorithm would work with any input, if it were given as much memory and time as it wanted. Since this is code-golf, I optimised it for code length, not algorithmic complexity
$endgroup$
– Jo King
May 2 at 14:49
add a comment
|
$begingroup$
Perl 6, 38 bytes
$!=$_;+grep $!%%$_&&($!/=$_),1..$_
Try it online!
Takes the greedy approach to selecting divisors.
$endgroup$
$begingroup$
Doesn't terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:42
6
$begingroup$
@Anush Well, it terminates eventually. Generally, the answer is valid if the program's algorithm would work with any input, if it were given as much memory and time as it wanted. Since this is code-golf, I optimised it for code length, not algorithmic complexity
$endgroup$
– Jo King
May 2 at 14:49
add a comment
|
$begingroup$
Perl 6, 38 bytes
$!=$_;+grep $!%%$_&&($!/=$_),1..$_
Try it online!
Takes the greedy approach to selecting divisors.
$endgroup$
Perl 6, 38 bytes
$!=$_;+grep $!%%$_&&($!/=$_),1..$_
Try it online!
Takes the greedy approach to selecting divisors.
answered May 2 at 14:35
Jo KingJo King
32.6k4 gold badges73 silver badges142 bronze badges
32.6k4 gold badges73 silver badges142 bronze badges
$begingroup$
Doesn't terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:42
6
$begingroup$
@Anush Well, it terminates eventually. Generally, the answer is valid if the program's algorithm would work with any input, if it were given as much memory and time as it wanted. Since this is code-golf, I optimised it for code length, not algorithmic complexity
$endgroup$
– Jo King
May 2 at 14:49
add a comment
|
$begingroup$
Doesn't terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:42
6
$begingroup$
@Anush Well, it terminates eventually. Generally, the answer is valid if the program's algorithm would work with any input, if it were given as much memory and time as it wanted. Since this is code-golf, I optimised it for code length, not algorithmic complexity
$endgroup$
– Jo King
May 2 at 14:49
$begingroup$
Doesn't terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:42
$begingroup$
Doesn't terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:42
6
6
$begingroup$
@Anush Well, it terminates eventually. Generally, the answer is valid if the program's algorithm would work with any input, if it were given as much memory and time as it wanted. Since this is code-golf, I optimised it for code length, not algorithmic complexity
$endgroup$
– Jo King
May 2 at 14:49
$begingroup$
@Anush Well, it terminates eventually. Generally, the answer is valid if the program's algorithm would work with any input, if it were given as much memory and time as it wanted. Since this is code-golf, I optimised it for code length, not algorithmic complexity
$endgroup$
– Jo King
May 2 at 14:49
add a comment
|
$begingroup$
Javascript (ES6), 39 bytes
f=(n,i=0)=>n%++i?n>i&&f(n,i):1+f(n/i,i)
There's probably a few bytes that can be saved here and there. Just uses the greedy algorithm for the factors.
$endgroup$
add a comment
|
$begingroup$
Javascript (ES6), 39 bytes
f=(n,i=0)=>n%++i?n>i&&f(n,i):1+f(n/i,i)
There's probably a few bytes that can be saved here and there. Just uses the greedy algorithm for the factors.
$endgroup$
add a comment
|
$begingroup$
Javascript (ES6), 39 bytes
f=(n,i=0)=>n%++i?n>i&&f(n,i):1+f(n/i,i)
There's probably a few bytes that can be saved here and there. Just uses the greedy algorithm for the factors.
$endgroup$
Javascript (ES6), 39 bytes
f=(n,i=0)=>n%++i?n>i&&f(n,i):1+f(n/i,i)
There's probably a few bytes that can be saved here and there. Just uses the greedy algorithm for the factors.
edited May 2 at 15:14
answered May 2 at 14:56
vrugtehagelvrugtehagel
1918 bronze badges
1918 bronze badges
add a comment
|
add a comment
|
$begingroup$
Jelly, 9 bytes
ŒPP=³ƊƇẈṀ
Try it online!
-1 byte thanks to someone
-2 bytes thanks to ErikTheOutgolfer
$endgroup$
$begingroup$
While preparing a input for the OEIS superseeker, I created a 11-byte likely golfable Jelly program (that uses a different approach), and am unlikely to post a Jelly answer so I'll pretend I golfed a byte from your solution:ÆE×8‘½’:2S‘
(it works with the power of the OEIS "formula" section for A003056). Disclaimer: it might be wrong, but it works on the test cases.
$endgroup$
– someone
May 2 at 14:17
$begingroup$
It doesn't seem to terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
@someone doesn't work for 36 but thanks
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@Anush yeah, it's really slow because i code-golfed it, not optimized for efficiency
$endgroup$
– HyperNeutrino
May 2 at 14:46
1
$begingroup$
You can removeÆD
, it's not like there are more partitions that are going to be created like this, it's just going to take a lot more time (times out for $xge21$).
$endgroup$
– Erik the Outgolfer
May 2 at 15:29
|
show 3 more comments
$begingroup$
Jelly, 9 bytes
ŒPP=³ƊƇẈṀ
Try it online!
-1 byte thanks to someone
-2 bytes thanks to ErikTheOutgolfer
$endgroup$
$begingroup$
While preparing a input for the OEIS superseeker, I created a 11-byte likely golfable Jelly program (that uses a different approach), and am unlikely to post a Jelly answer so I'll pretend I golfed a byte from your solution:ÆE×8‘½’:2S‘
(it works with the power of the OEIS "formula" section for A003056). Disclaimer: it might be wrong, but it works on the test cases.
$endgroup$
– someone
May 2 at 14:17
$begingroup$
It doesn't seem to terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
@someone doesn't work for 36 but thanks
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@Anush yeah, it's really slow because i code-golfed it, not optimized for efficiency
$endgroup$
– HyperNeutrino
May 2 at 14:46
1
$begingroup$
You can removeÆD
, it's not like there are more partitions that are going to be created like this, it's just going to take a lot more time (times out for $xge21$).
$endgroup$
– Erik the Outgolfer
May 2 at 15:29
|
show 3 more comments
$begingroup$
Jelly, 9 bytes
ŒPP=³ƊƇẈṀ
Try it online!
-1 byte thanks to someone
-2 bytes thanks to ErikTheOutgolfer
$endgroup$
Jelly, 9 bytes
ŒPP=³ƊƇẈṀ
Try it online!
-1 byte thanks to someone
-2 bytes thanks to ErikTheOutgolfer
edited May 2 at 15:33
answered May 2 at 14:13
HyperNeutrinoHyperNeutrino
20.6k4 gold badges41 silver badges155 bronze badges
20.6k4 gold badges41 silver badges155 bronze badges
$begingroup$
While preparing a input for the OEIS superseeker, I created a 11-byte likely golfable Jelly program (that uses a different approach), and am unlikely to post a Jelly answer so I'll pretend I golfed a byte from your solution:ÆE×8‘½’:2S‘
(it works with the power of the OEIS "formula" section for A003056). Disclaimer: it might be wrong, but it works on the test cases.
$endgroup$
– someone
May 2 at 14:17
$begingroup$
It doesn't seem to terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
@someone doesn't work for 36 but thanks
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@Anush yeah, it's really slow because i code-golfed it, not optimized for efficiency
$endgroup$
– HyperNeutrino
May 2 at 14:46
1
$begingroup$
You can removeÆD
, it's not like there are more partitions that are going to be created like this, it's just going to take a lot more time (times out for $xge21$).
$endgroup$
– Erik the Outgolfer
May 2 at 15:29
|
show 3 more comments
$begingroup$
While preparing a input for the OEIS superseeker, I created a 11-byte likely golfable Jelly program (that uses a different approach), and am unlikely to post a Jelly answer so I'll pretend I golfed a byte from your solution:ÆE×8‘½’:2S‘
(it works with the power of the OEIS "formula" section for A003056). Disclaimer: it might be wrong, but it works on the test cases.
$endgroup$
– someone
May 2 at 14:17
$begingroup$
It doesn't seem to terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
@someone doesn't work for 36 but thanks
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@Anush yeah, it's really slow because i code-golfed it, not optimized for efficiency
$endgroup$
– HyperNeutrino
May 2 at 14:46
1
$begingroup$
You can removeÆD
, it's not like there are more partitions that are going to be created like this, it's just going to take a lot more time (times out for $xge21$).
$endgroup$
– Erik the Outgolfer
May 2 at 15:29
$begingroup$
While preparing a input for the OEIS superseeker, I created a 11-byte likely golfable Jelly program (that uses a different approach), and am unlikely to post a Jelly answer so I'll pretend I golfed a byte from your solution:
ÆE×8‘½’:2S‘
(it works with the power of the OEIS "formula" section for A003056). Disclaimer: it might be wrong, but it works on the test cases.$endgroup$
– someone
May 2 at 14:17
$begingroup$
While preparing a input for the OEIS superseeker, I created a 11-byte likely golfable Jelly program (that uses a different approach), and am unlikely to post a Jelly answer so I'll pretend I golfed a byte from your solution:
ÆE×8‘½’:2S‘
(it works with the power of the OEIS "formula" section for A003056). Disclaimer: it might be wrong, but it works on the test cases.$endgroup$
– someone
May 2 at 14:17
$begingroup$
It doesn't seem to terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
It doesn't seem to terminate with 1099511627776
$endgroup$
– Anush
May 2 at 14:43
$begingroup$
@someone doesn't work for 36 but thanks
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@someone doesn't work for 36 but thanks
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@Anush yeah, it's really slow because i code-golfed it, not optimized for efficiency
$endgroup$
– HyperNeutrino
May 2 at 14:46
$begingroup$
@Anush yeah, it's really slow because i code-golfed it, not optimized for efficiency
$endgroup$
– HyperNeutrino
May 2 at 14:46
1
1
$begingroup$
You can remove
ÆD
, it's not like there are more partitions that are going to be created like this, it's just going to take a lot more time (times out for $xge21$).$endgroup$
– Erik the Outgolfer
May 2 at 15:29
$begingroup$
You can remove
ÆD
, it's not like there are more partitions that are going to be created like this, it's just going to take a lot more time (times out for $xge21$).$endgroup$
– Erik the Outgolfer
May 2 at 15:29
|
show 3 more comments
$begingroup$
Japt -h
, 13 bytes
â à f_׶UÃmÊn
Try it
$endgroup$
add a comment
|
$begingroup$
Japt -h
, 13 bytes
â à f_׶UÃmÊn
Try it
$endgroup$
add a comment
|
$begingroup$
Japt -h
, 13 bytes
â à f_׶UÃmÊn
Try it
$endgroup$
Japt -h
, 13 bytes
â à f_׶UÃmÊn
Try it
answered May 2 at 16:39
Embodiment of IgnoranceEmbodiment of Ignorance
5,6543 silver badges31 bronze badges
5,6543 silver badges31 bronze badges
add a comment
|
add a comment
|
$begingroup$
Brachylog, 8 bytes
f;?⟨⊇×⟩l
Try it online!
(The naive approach, ~×≠lᶠ⌉
, generates an infinite number of solutions with extra 1s before eliminating them with ≠
, and thus fails to actually terminate. It's not a problem, though, since it's for the same byte count!)
Takes input through the input variable and output through the output variable. The header on TIO contains a copy of most of the code for the sake of showing you what the factor list is, but this works perfectly fine without it. Since ⊇
gives larger sublists first, this predicate essentially does the same thing as most other answers, but without explicitly generating and filtering the complete powerset of the factors, thanks to backtracking.
The output
l is the length of
⊇ a sublist (the largest satisfying these constraints)
f of the factors of
the input
; ⟨ ⟩ which
× with its elements multiplied together
? is the input.
$endgroup$
add a comment
|
$begingroup$
Brachylog, 8 bytes
f;?⟨⊇×⟩l
Try it online!
(The naive approach, ~×≠lᶠ⌉
, generates an infinite number of solutions with extra 1s before eliminating them with ≠
, and thus fails to actually terminate. It's not a problem, though, since it's for the same byte count!)
Takes input through the input variable and output through the output variable. The header on TIO contains a copy of most of the code for the sake of showing you what the factor list is, but this works perfectly fine without it. Since ⊇
gives larger sublists first, this predicate essentially does the same thing as most other answers, but without explicitly generating and filtering the complete powerset of the factors, thanks to backtracking.
The output
l is the length of
⊇ a sublist (the largest satisfying these constraints)
f of the factors of
the input
; ⟨ ⟩ which
× with its elements multiplied together
? is the input.
$endgroup$
add a comment
|
$begingroup$
Brachylog, 8 bytes
f;?⟨⊇×⟩l
Try it online!
(The naive approach, ~×≠lᶠ⌉
, generates an infinite number of solutions with extra 1s before eliminating them with ≠
, and thus fails to actually terminate. It's not a problem, though, since it's for the same byte count!)
Takes input through the input variable and output through the output variable. The header on TIO contains a copy of most of the code for the sake of showing you what the factor list is, but this works perfectly fine without it. Since ⊇
gives larger sublists first, this predicate essentially does the same thing as most other answers, but without explicitly generating and filtering the complete powerset of the factors, thanks to backtracking.
The output
l is the length of
⊇ a sublist (the largest satisfying these constraints)
f of the factors of
the input
; ⟨ ⟩ which
× with its elements multiplied together
? is the input.
$endgroup$
Brachylog, 8 bytes
f;?⟨⊇×⟩l
Try it online!
(The naive approach, ~×≠lᶠ⌉
, generates an infinite number of solutions with extra 1s before eliminating them with ≠
, and thus fails to actually terminate. It's not a problem, though, since it's for the same byte count!)
Takes input through the input variable and output through the output variable. The header on TIO contains a copy of most of the code for the sake of showing you what the factor list is, but this works perfectly fine without it. Since ⊇
gives larger sublists first, this predicate essentially does the same thing as most other answers, but without explicitly generating and filtering the complete powerset of the factors, thanks to backtracking.
The output
l is the length of
⊇ a sublist (the largest satisfying these constraints)
f of the factors of
the input
; ⟨ ⟩ which
× with its elements multiplied together
? is the input.
answered May 3 at 0:06
Unrelated StringUnrelated String
3,9262 gold badges3 silver badges21 bronze badges
3,9262 gold badges3 silver badges21 bronze badges
add a comment
|
add a comment
|
$begingroup$
Scala, 77 bytes
def f(n:Long)=var(m,c,i)=(n,1,2L);while(i<=m)if(m%i==0)m/=i;c+=1;i+=1;c
Try it online!
$endgroup$
add a comment
|
$begingroup$
Scala, 77 bytes
def f(n:Long)=var(m,c,i)=(n,1,2L);while(i<=m)if(m%i==0)m/=i;c+=1;i+=1;c
Try it online!
$endgroup$
add a comment
|
$begingroup$
Scala, 77 bytes
def f(n:Long)=var(m,c,i)=(n,1,2L);while(i<=m)if(m%i==0)m/=i;c+=1;i+=1;c
Try it online!
$endgroup$
Scala, 77 bytes
def f(n:Long)=var(m,c,i)=(n,1,2L);while(i<=m)if(m%i==0)m/=i;c+=1;i+=1;c
Try it online!
answered May 3 at 9:24
PeterPeter
273 bronze badges
273 bronze badges
add a comment
|
add a comment
|
$begingroup$
Gaia, 10 9 bytes
Π=
dz↑⁇(l
Try it online!
Follows the same "algorithm" as seen elsewhere -- filter the divisor powerset for the longest with product equal to the number and return its length.
| helper function
Π= | is prod(list)==n (implicit)?
|
| main function; implicitly takes n
dz | divisor powerset (in decreasing order of size)
↑⁇ | filter by helper function
(l | take the first element and take the length (implicitly output)
$endgroup$
add a comment
|
$begingroup$
Gaia, 10 9 bytes
Π=
dz↑⁇(l
Try it online!
Follows the same "algorithm" as seen elsewhere -- filter the divisor powerset for the longest with product equal to the number and return its length.
| helper function
Π= | is prod(list)==n (implicit)?
|
| main function; implicitly takes n
dz | divisor powerset (in decreasing order of size)
↑⁇ | filter by helper function
(l | take the first element and take the length (implicitly output)
$endgroup$
add a comment
|
$begingroup$
Gaia, 10 9 bytes
Π=
dz↑⁇(l
Try it online!
Follows the same "algorithm" as seen elsewhere -- filter the divisor powerset for the longest with product equal to the number and return its length.
| helper function
Π= | is prod(list)==n (implicit)?
|
| main function; implicitly takes n
dz | divisor powerset (in decreasing order of size)
↑⁇ | filter by helper function
(l | take the first element and take the length (implicitly output)
$endgroup$
Gaia, 10 9 bytes
Π=
dz↑⁇(l
Try it online!
Follows the same "algorithm" as seen elsewhere -- filter the divisor powerset for the longest with product equal to the number and return its length.
| helper function
Π= | is prod(list)==n (implicit)?
|
| main function; implicitly takes n
dz | divisor powerset (in decreasing order of size)
↑⁇ | filter by helper function
(l | take the first element and take the length (implicitly output)
edited May 3 at 17:34
answered May 2 at 15:12
GiuseppeGiuseppe
19.4k3 gold badges16 silver badges71 bronze badges
19.4k3 gold badges16 silver badges71 bronze badges
add a comment
|
add a comment
|
$begingroup$
Clam, 15 bytes
p}_`nq#:;qQ@s~Q
TIO link coming soon (when dennis pulls)
Basically a port of @Emigna's 05AB1E solution.
Explanation
- Implicit Q = first input
p - Print...
} - The last element of...
_ - Sorted...
`nq - Lengths of... (map q => q.len)
@s - Items in powerset of
~Q - Proper divisors of Q
# - Where... (filter)
;q - Product of subset
: - Equals...
Q - Q
$endgroup$
add a comment
|
$begingroup$
Clam, 15 bytes
p}_`nq#:;qQ@s~Q
TIO link coming soon (when dennis pulls)
Basically a port of @Emigna's 05AB1E solution.
Explanation
- Implicit Q = first input
p - Print...
} - The last element of...
_ - Sorted...
`nq - Lengths of... (map q => q.len)
@s - Items in powerset of
~Q - Proper divisors of Q
# - Where... (filter)
;q - Product of subset
: - Equals...
Q - Q
$endgroup$
add a comment
|
$begingroup$
Clam, 15 bytes
p}_`nq#:;qQ@s~Q
TIO link coming soon (when dennis pulls)
Basically a port of @Emigna's 05AB1E solution.
Explanation
- Implicit Q = first input
p - Print...
} - The last element of...
_ - Sorted...
`nq - Lengths of... (map q => q.len)
@s - Items in powerset of
~Q - Proper divisors of Q
# - Where... (filter)
;q - Product of subset
: - Equals...
Q - Q
$endgroup$
Clam, 15 bytes
p}_`nq#:;qQ@s~Q
TIO link coming soon (when dennis pulls)
Basically a port of @Emigna's 05AB1E solution.
Explanation
- Implicit Q = first input
p - Print...
} - The last element of...
_ - Sorted...
`nq - Lengths of... (map q => q.len)
@s - Items in powerset of
~Q - Proper divisors of Q
# - Where... (filter)
;q - Product of subset
: - Equals...
Q - Q
answered May 2 at 17:25
SkidsdevSkidsdev
7,09831 silver badges79 bronze badges
7,09831 silver badges79 bronze badges
add a comment
|
add a comment
|
$begingroup$
C# (Visual C# Interactive Compiler), 54 bytes
int f(int n,int i=0)=>n%++i<1?1+f(n/i,i):n>i?f(n,i):0;
Uses the same approach as @vrugtehagel's and @JoKing's answers.
Try it online!
$endgroup$
$begingroup$
Assuming I implemented your logic correctly, a 53-byte solution (that I couldn't rid of the "return" keyword): Try it online!
$endgroup$
– someone
May 3 at 2:23
1
$begingroup$
@someone Thanks, but according to meta, functions have to be reusable. Also, I'm don't know if it is acceptable to have declarations outside of the function leave out a trailing semicolon, may make a meta post on that.
$endgroup$
– Embodiment of Ignorance
May 3 at 2:37
add a comment
|
$begingroup$
C# (Visual C# Interactive Compiler), 54 bytes
int f(int n,int i=0)=>n%++i<1?1+f(n/i,i):n>i?f(n,i):0;
Uses the same approach as @vrugtehagel's and @JoKing's answers.
Try it online!
$endgroup$
$begingroup$
Assuming I implemented your logic correctly, a 53-byte solution (that I couldn't rid of the "return" keyword): Try it online!
$endgroup$
– someone
May 3 at 2:23
1
$begingroup$
@someone Thanks, but according to meta, functions have to be reusable. Also, I'm don't know if it is acceptable to have declarations outside of the function leave out a trailing semicolon, may make a meta post on that.
$endgroup$
– Embodiment of Ignorance
May 3 at 2:37
add a comment
|
$begingroup$
C# (Visual C# Interactive Compiler), 54 bytes
int f(int n,int i=0)=>n%++i<1?1+f(n/i,i):n>i?f(n,i):0;
Uses the same approach as @vrugtehagel's and @JoKing's answers.
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 54 bytes
int f(int n,int i=0)=>n%++i<1?1+f(n/i,i):n>i?f(n,i):0;
Uses the same approach as @vrugtehagel's and @JoKing's answers.
Try it online!
answered May 2 at 18:19
Embodiment of IgnoranceEmbodiment of Ignorance
5,6543 silver badges31 bronze badges
5,6543 silver badges31 bronze badges
$begingroup$
Assuming I implemented your logic correctly, a 53-byte solution (that I couldn't rid of the "return" keyword): Try it online!
$endgroup$
– someone
May 3 at 2:23
1
$begingroup$
@someone Thanks, but according to meta, functions have to be reusable. Also, I'm don't know if it is acceptable to have declarations outside of the function leave out a trailing semicolon, may make a meta post on that.
$endgroup$
– Embodiment of Ignorance
May 3 at 2:37
add a comment
|
$begingroup$
Assuming I implemented your logic correctly, a 53-byte solution (that I couldn't rid of the "return" keyword): Try it online!
$endgroup$
– someone
May 3 at 2:23
1
$begingroup$
@someone Thanks, but according to meta, functions have to be reusable. Also, I'm don't know if it is acceptable to have declarations outside of the function leave out a trailing semicolon, may make a meta post on that.
$endgroup$
– Embodiment of Ignorance
May 3 at 2:37
$begingroup$
Assuming I implemented your logic correctly, a 53-byte solution (that I couldn't rid of the "return" keyword): Try it online!
$endgroup$
– someone
May 3 at 2:23
$begingroup$
Assuming I implemented your logic correctly, a 53-byte solution (that I couldn't rid of the "return" keyword): Try it online!
$endgroup$
– someone
May 3 at 2:23
1
1
$begingroup$
@someone Thanks, but according to meta, functions have to be reusable. Also, I'm don't know if it is acceptable to have declarations outside of the function leave out a trailing semicolon, may make a meta post on that.
$endgroup$
– Embodiment of Ignorance
May 3 at 2:37
$begingroup$
@someone Thanks, but according to meta, functions have to be reusable. Also, I'm don't know if it is acceptable to have declarations outside of the function leave out a trailing semicolon, may make a meta post on that.
$endgroup$
– Embodiment of Ignorance
May 3 at 2:37
add a comment
|
$begingroup$
Ruby, 34 bytes
Obviously times out on that massive number, but will eventually time out if given enough time on another machine.
->n(1..n).countn%e<1?n/=e:p
Try it online!
$endgroup$
add a comment
|
$begingroup$
Ruby, 34 bytes
Obviously times out on that massive number, but will eventually time out if given enough time on another machine.
->n(1..n).countn%e<1?n/=e:p
Try it online!
$endgroup$
add a comment
|
$begingroup$
Ruby, 34 bytes
Obviously times out on that massive number, but will eventually time out if given enough time on another machine.
->n(1..n).countn%e<1?n/=e:p
Try it online!
$endgroup$
Ruby, 34 bytes
Obviously times out on that massive number, but will eventually time out if given enough time on another machine.
->n(1..n).countn%e<1?n/=e:p
Try it online!
answered May 2 at 22:16
Value InkValue Ink
9,2888 silver badges37 bronze badges
9,2888 silver badges37 bronze badges
add a comment
|
add a comment
|
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f185062%2fa-factorization-game%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
9
$begingroup$
Could you add a few more test cases? (Preferably of reasonable size.)
$endgroup$
– Arnauld
May 2 at 14:31
8
$begingroup$
Given your comments on most answers: if you're looking for efficient code instead, this should definitely not be tagged as
code-golf
. You may consider eitherfastest-code
orfastest-algorithm
for an upcoming challenge. If you really wanted all answers to work in a limited time within the specified range, it should have been explicitly mentioned. (And I would have recommended a smaller range so that it does not conflict withcode-golf
entirely.)$endgroup$
– Arnauld
May 2 at 15:00
$begingroup$
@Arnauld No I am careful to make it code-golf and no one is judged for that. It would just be cool if the code could run for the input ranges specfied.
$endgroup$
– Anush
May 2 at 15:01
5
$begingroup$
Quoting xnor: If it's not mandatory, answers won't do it.
$endgroup$
– Arnauld
May 2 at 15:09
1
$begingroup$
For
x=1, 2, ...
I getf(x)=1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 2, 4, 2, 3, 3, 3, 3, 4, 2, 3
which I do not find in OEIS. It is clear enough that records will appear for factorial numbersx
. For example the smallestx
such thatf(x)=13
will be13!
. I guessf
depends only on the exponents of the prime factorization. So to findf(13^4*19^7*29^2)
we might simplify tof(2^7*3^4*5^2)
.$endgroup$
– Jeppe Stig Nielsen
May 8 at 1:30