Python Forum
math problem using recursion?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
math problem using recursion?
#1
First the problem.
1. Start with a semi-prime (eg, 15 = 3 * 5).
2. Take the factors and concatenate them both forwards and backwards to give 2 new numbers. (Ie, 35 and 53)
3. Test for semi-prime-ness. If semi-prime, go to step 2. If not, end that branch.
The process ends when no further semi-primes are generated.

This creates a tree of numbers.
The tree is built as you go from the top down.
See image for the tree of 15.    

For 15 the length of the chain of semi-primes is 7.
The object is to find the start number with the longest chain of semi-primes.

I "think" this might be a good place to use recursion. However, I've never done
recursion and only have a hazy grasp of it. I've seen a few videos about it
but they either don't show an example or the examples they give are for
factorials or Fibonacci. Neither of which seems to be of help with this
problem.

To get the semi-primes themselves and their factors I thought I could either
calculate them on the fly or pre-compute them and put them into a list or
dictionary or something. But as for the recursion part how would this problem
be coded in Python? TIA
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