Python Forum
Frog Puzzle Random To Custom
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frog Puzzle Random To Custom
#4
Quote:I just want to make the input to custom number instead of randomized number ie i want my code to sort this [0,5,1,3,4,2] instead of randomized number,
It is easy to convert a string like "5 1 3 4 2" to a list of ints using split(). First split the string into a list of numeric strings using split(), then use int() to convert the strings to numbers.
input_str = input("Enter Frogs: ")  # User types 5 1 3 4 2 <enter>.  Do not type the zero.
frog_list = [0]
for number_str in input_str.split():
    frog_list.append(int(number_str))
sorted_frogs = [0] + sorted(frog_list[1:], reverse=True)
frog_count = len(frog_list) - 1

print(frog_list, sorted_frogs, frog_count)
I give you this code because I think you need to test your frog sort. When I run your code with 58 66 97 51 8, it prints this:
Output:
[0, 58, 66, 97, 51, 8] [66, 58, 0, 97, 51, 8] [66, 58, 97, 0, 51, 8] [66, 58, 97, 51, 0, 8] [66, 58, 97, 51, 8, 0] [66, 58, 97, 51, 8, 0] [66, 58, 97, 51, 0, 8] [66, 58, 97, 0, 51, 8] [66, 0, 97, 58, 51, 8] [0, 66, 97, 58, 51, 8] [0, 66, 97, 58, 51, 8] [97, 66, 0, 58, 51, 8] [97, 66, 58, 0, 51, 8] [97, 66, 58, 51, 0, 8] [97, 66, 58, 51, 8, 0] [97, 66, 58, 51, 8, 0] [97, 66, 58, 51, 0, 8] [97, 66, 58, 0, 51, 8] [97, 66, 0, 58, 51, 8] [97, 0, 66, 58, 51, 8] [0, 97, 66, 58, 51, 8] Minimum number of moves: 20
This is the correct order (assuming 0 should end in the leftmost slot), but the solution is not optimal. Looking at your approach to the problem, you'll only find the optimal solution by luck of it being the only solution you try.

I think the output should be
Output:
[0, 58, 66, 97, 51, 8] [58, 0, 66, 97, 51, 8] [58, 97, 66, 0, 51, 8] [0, 97, 66, 58, 51, 8] Minimum number of moves: 3
And the solution for [0, 5, 1, 3, 4, 2] is
Output:
[0, 5, 1, 3, 4, 2] [2, 5, 1, 3, 4, 0] [2, 5, 0, 3, 4, 1] [2, 5, 4, 3, 0, 1] [0, 5, 4, 3, 2, 1] Minimum number of moves: 4
Reply


Messages In This Thread
Frog Puzzle Random To Custom - by MoreMoney - Mar-23-2024, 10:39 AM
RE: Frog Puzzle Random To Custom - by Pedroski55 - Mar-24-2024, 07:57 AM
RE: Frog Puzzle Random To Custom - by Pedroski55 - Mar-24-2024, 06:14 PM
RE: Frog Puzzle Random To Custom - by deanhystad - Mar-25-2024, 09:53 PM
RE: Frog Puzzle Random To Custom - by MoreMoney - Mar-26-2024, 08:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Codility Frog River One Westerner 2 2,508 Jan-09-2021, 06:35 PM
Last Post: deanhystad
  Slider puzzle captcha resolver, how do this? dw0rd1337 0 3,590 Jan-04-2021, 11:55 PM
Last Post: dw0rd1337
  I code a program to solve puzzle but i can't make it more dynamic. Shahmadhur13 5 2,923 Apr-18-2020, 10:05 AM
Last Post: Shahmadhur13
  how to program robot to pass wise man puzzle steven12341234 0 2,036 Dec-02-2018, 08:31 AM
Last Post: steven12341234
  Need help with this coding puzzle torchtopher 1 2,184 Jun-22-2018, 01:14 AM
Last Post: buran

Forum Jump:

User Panel Messages

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