Mar-29-2024, 06:20 PM
You are making this so much harder than it has to be. There should be no "odd_leapfrog" or "even_leapfrog". There should be no "direction". There should be no "position + 1" or "position + 2". There shouldn't even be an "else" statement.
for n in range(1, len(frog_list) if frog_list[n] != sorted_frogs[n] move frog_list[n] to the empty_space while the empty space is not frog_list[0] move correct frog to empty space n = n + 1That's all there is to it. The hardest part is finding what frog gets moved to the empty space, and that is simple since you have a sorted list of frogs that tells you where every frog belongs.