Python Forum
math problem using recursion?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
math problem using recursion?
#6
The numbers in your sample tree are correct, but the 000 separator looks sometimes like a decimal point , a bit confusing, but it is to show concatenation.
I'm not sure how to proceed in this homework section, because my approach is quite different.
If the purpose is to use recursion, i see no need for it, but a python "evangelist" might. :-)
I also see no need for the dictionary , nor the list of primes
e.g. to find the divisors of a number, i use this:
def divisors(x):
    div = []
    for i in range(2,int(x/2)+1):
        if x % i == 0:
            div.append(i)
    if len(div) == 2:
        print(f'Divisors of {x}', div)
        new_numbers(div)
    else:
        print(f'{x} is Not Semi Prime')
I assume by your definition that a semiprime can only have 2 divisors, both prime.
We also assume that the seed number is semi-prime, although if it is not, the iterations will stop soon enough.
the new_numbers() function generates 'xy' and 'yx', that are added to a list.
You then call divisors() for the listed results.
Paul
Output:
Start: 15 Divisors of 15 [3, 5] New numbers: 53 35 Divisors of 35 [5, 7] New numbers: 75 57 53 is Not Semi Prime Divisors of 57 [3, 19] New numbers: 193 319 75 is Not Semi Prime Divisors of 319 [11, 29] New numbers: 2911 1129 193 is Not Semi Prime 1129 is Not Semi Prime Divisors of 2911 [41, 71] New numbers: 7141 4171 Divisors of 4171 [43, 97] New numbers: 9743 4397 Divisors of 7141 [37, 193] New numbers: 19337 37193 4397 is Not Semi Prime 9743 is Not Semi Prime Divisors of 37193 [13, 2861] New numbers: 286113 132861 Divisors of 19337 [61, 317] New numbers: 31761 61317 132861 is Not Semi Prime 286113 is Not Semi Prime 61317 is Not Semi Prime 31761 is Not Semi Prime
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Messages In This Thread
math problem using recursion? - by mnh001 - Sep-01-2020, 03:54 PM
RE: math problem using recursion? - by DPaul - Sep-01-2020, 05:31 PM
RE: math problem using recursion? - by Larz60+ - Sep-01-2020, 06:52 PM
RE: math problem using recursion? - by mnh001 - Sep-01-2020, 08:17 PM
RE: math problem using recursion? - by mnh001 - Sep-01-2020, 10:57 PM
RE: math problem using recursion? - by DPaul - Sep-02-2020, 09:49 AM
RE: math problem using recursion? - by mnh001 - Sep-02-2020, 02:35 PM
RE: math problem using recursion? - by DPaul - Sep-02-2020, 05:22 PM
RE: math problem using recursion? - by bowlofred - Sep-02-2020, 05:36 PM
RE: math problem using recursion? - by mnh001 - Sep-02-2020, 06:24 PM
RE: math problem using recursion? - by Gribouillis - Sep-02-2020, 07:14 PM
RE: math problem using recursion? - by SmartGrid - Sep-03-2020, 12:55 PM
RE: math problem using recursion? - by mnh001 - Sep-03-2020, 02:34 PM
RE: math problem using recursion? - by DPaul - Sep-03-2020, 02:52 PM
RE: math problem using recursion? - by mnh001 - Sep-03-2020, 07:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Math Problem cryxma 2 2,004 Dec-21-2020, 09:53 PM
Last Post: Gribouillis
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 2,644 Oct-05-2020, 07:47 PM
Last Post: deanhystad
  Math problem in Python - pyqt5 rwahdan 6 5,900 Jun-18-2019, 08:11 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020