fork(2) download
  1. RoomItems = "ab ab ab abab abab abab"
  2. DirtyRoom = "abaabbabaabbabaabb"
  3.  
  4. RoomItems = sorted(RoomItems.split(" "), key=len)
  5.  
  6. def Yarr(RoomItems, DirtyRoom):
  7. for Item in RoomItems:
  8. if all(char in DirtyRoom[0:len(Item)] for char in Item):
  9. print Item, DirtyRoom[0:len(Item)]
  10. RoomItems.remove(Item)
  11. DirtyRoom = DirtyRoom.replace(DirtyRoom[0:len(Item)],"",1)+DirtyRoom[0:len(Item)]
  12. Yarr(RoomItems, DirtyRoom)
  13.  
  14. Yarr(RoomItems, DirtyRoom)
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
ab ab
abab aabb
ab ab
abab aabb
ab ab
abab aabb