#๐ maximum function
15 messages ยท Page 1 of 1 (latest)
@shadow cedar
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
def divisor(n):
t=0
i=1
while i < n+1:
if n%i == 0:
t += 1
i += 1
return (t)
def highly_composite(m):
q=1
a=1
while q < m:
next = a + 1
if divisor(next) > divisor(a):
q+=1
a+=1
else:
a+=1
return(a)
L = highly_composite(5)
print(L)
you would have to store all previous terms then yes?
well i didnt know if there was an easier way yk
like to do smth like max( divisor(a), divisor(a-1) all the way to 1)
u sir are out mathing me.. there maybe a way for sure..
like
divisor(next) > max([divisor(i + 1) for i in range(a)]) or something like that?
You need to remember the value of t, the largest divisor(n) seen so far. Comapre to that. So keep a max_t value, initially 0. Compare a to max_t, not divisor(a). I think - it isn't totally clear to me what your highly_composite function is doing.
When you see divisor(next) > max_t, set max_t to divisor(next).
Even just max_t = max(max_t, divisor(next)). No if. Unless you also need to bump the counters.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ maximum function