Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Honestly I couldn't figure this out on my own but when I attempted it - sometimes it would complete and sometimes it would fail.
I came up with a cheat by putting the for loop in a function and running it under a while loop.
If the function doesn't return the same string as before it will run again until it returns the same string as it did before.
I do believe the description has been changed and improved since your post, so I can close this suggestion. Thanks for noting that out :)
Since the triplets are random you can get inaccurate results only parsing over the triplets once. Puayny is correct in their comment "This solution is incomplete though elegant, it will fail for some test cases currently not included. The 'for l in triplets' loop shouldn't run just once, it should run until there are no more swaps.". Their comment is the most efficient solution however since these are triples you could also just run the loop twice which I think is more than enough to get the correct sequence.
you have the wrong solution
if we check it on all possible triplets permutation for first test, then as a secrets we get
defaultdict(<class 'int'>, {'whatisup': 2565, 'tuwhapis': 120, 'uwhatpis': 76, 'twhapisu': 240, 'twhuapis': 6, 'twhapuis': 26, 'whatupis': 79, 'whatpisu': 660, 'whuatpis': 9, 'whatpuis': 16, 'twhaisup': 180, 'twhaupis': 28, 'whatipsu': 285, 'wuhatisp': 35, 'wuhiatsp': 88, 'whiuatsp': 71, 'whiatsup': 195, 'whuatisp': 18, 'whuiatsp': 10, 'uwhatisp': 7, 'uwhiatsp': 11, 'whatiusp': 30, 'whatuisp': 30, 'whiatusp': 60, 'twhiapsu': 60, 'whiatpsu': 75, 'twhiasup': 60})
I recommend using a set comprehension:
Besides being more terse, this doesn't build an extra list temporary.
is wrong
on python 3.8
its wrong
This comment is hidden because it contains spoiler information about the solution
I think a generalized version of this solution that runs multiple passes and stops only when 'r' remains unchanged for two passes would be a good answer. I made a rough implementation here https://www.codewars.com/kata/reviews/53fbcb9ecfc5f67703000032/groups/5ff218e51d40250001bac79a
This comment is hidden because it contains spoiler information about the solution
Can you please explain me what exactly changed in Python 3 which makes the solution break?
What is the purpose of this kata?
I wonder who accepts this kind of katas. Description should be improved.
Poor description
This comment is hidden because it contains spoiler information about the solution
Loading more items...