#๐Ÿ”’ maximum function

15 messages ยท Page 1 of 1 (latest)

shadow cedar
#

okay so what i need help with is:
in line 21 im checking if the NEXT term is bigger than the previous, but what i actually NEED is to check if the NEXT term is bigger than ALL previous terms. I was thinking i would need to create a maximum function but im not sure how to.

late boneBOT
#

@shadow cedar

Python help channel opened

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.

shadow cedar
#
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)
quasi bolt
#

you would have to store all previous terms then yes?

shadow cedar
#

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)

quasi bolt
#

u sir are out mathing me.. there maybe a way for sure..

covert stirrup
#

like

#

divisor(next) > max([divisor(i + 1) for i in range(a)]) or something like that?

round rune
#

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.

late boneBOT
#
Python help channel closed

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