Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithmic problem
#4
This is a fun problem. I ended up with a recursive solution. I modified the Alex list for brevity

Find where Alex[0] matches John
Output:
John 6 1 1 3 3 6 2 5 4 1 1 3 | Alex 6 3 2 5 Match 1 0 0 0 0 0 0 0 0 0 0 0
Now find the first match for Alex[1:] and John[1:]
Output:
John 1 1 3 3 6 2 5 4 1 1 3 | Alex 3 2 5 Match 1 0 0 1 0 0 0 0 0 0 0 0
And then find the first match for Alex[2:] and John[4:]
Output:
John 3 6 2 5 4 1 1 3 | Alex 2 5 Match 1 0 0 1 0 0 1 0 0 0 0 0
This is repeated until the Alex list is empty. When the Alex list is empty you unwind the recursion and find the next match.

The trickiest part is you cannot place a tick mark in the match list if the Alex list is not an ordered sub-list of the John list. In addition to an empty Alex list, this signals a break in the recursion.
Mhd45 likes this post
Reply


Messages In This Thread
Algorithmic problem - by Mhd45 - Nov-02-2022, 06:05 AM
RE: Algorithmic problem - by Yoriz - Nov-02-2022, 06:32 AM
RE: Algorithmic problem - by deanhystad - Nov-02-2022, 08:26 PM
RE: Algorithmic problem - by deanhystad - Nov-04-2022, 04:26 AM

Forum Jump:

User Panel Messages

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