Skip to Content
author's profile photo Roberto Vacca

Best Performance Solution - The wardrobe of the Countess

Hi Guys,

this is a question to get involved in a race to the best performance with ABAP language (any version). They are allowed all possible technological solutions in SAP.

What we want to achieve is the best time in the determination of solutions to a big problem :)

This is the Wardrobe problem:

Countess "Rich Exaggerated", in a period of economic hardship, decided to recycle his old wardrobe of clothes.

However, she is always under the dictates of good taste, and she wants to determine which and how many set of clothes with at most two colors can be combined.

More precisely: the wardrobe of Countess consists of a number of clothes, each of a certain color. The clothes can be of any of the following types: shoe, bag, skirt, pants, shirt, jacket, hat. A set is made up of a clothing of each type (except for the fact that always includes only or a skirt or pants).

The problem is to list all the possible complete in which the clothes are all the same color, or at most two different colors. Being the highly eccentric countess, her wardrobe consists of clothes of many different colors, whose number can not be specified by input.

The input to the program will be contained in a text file; each line contains two strings, separated by a blank space: the first string specifies the item of clothing (one of those given above), while the second indicates the color.


shoe yellow

bag pink

jacket beige

bag yellow

pants greymouse

hat pink

skirt yellow

jacket yellow

skirt pink

shirt pink

shirt greymouse

It is assumed that the same couple ( clothes+color ) will never be shown twice.

The program should calculate and print in screen the list of possible complete.

For example, in our case, one of the possible complete is the following:

shoe yellow, bag pink, skirt yellow, shirt pink, jacket yellow, hat pink.

Each line specifies a full complete, and must be ordered as shown (before the shoe, then the bag, then the skirt or pants, then shirt, and then jacket and hat), separating the clothes among them with a comma and a space (as in the example).

The order of the rows is not relevant, but must appear all the possible complete once and only once. The program must not create output messages than those required.

Hope to hear from you.



* Please Login or Register to Comment on or Follow discussions.


  • Feb 23, 2017 at 12:29 PM


    great story,

    I'd love to read the missing part of the story where he changed to a she while deciding what clothes the recycle


    • Feb 23, 2017 at 01:06 PM

      If you solve it, I'll probably post the end of the story! :D

      • Feb 23, 2017 at 03:45 PM

        Hi Roberto,

        ok you got me, I concede defeat :-)


        • Feb 23, 2017 at 04:54 PM

          Ok...story ends with her man burning These clothes and go looking at the next match in the Champions League: D

          Give me a beeeeer!


  • Feb 23, 2017 at 08:28 PM

    Gender-confused Countess should invest in SAP AFS solution. :) You're missing some details on the exception handling - what if there are some items that can't be matched with the rest? Or what if there are not enough clothes to build a set? E.g. one could leave home without a hat easily but definitely not wearing just pants and shoes.

    Other that that, it seems like a basic "read file into internal tables, loop through and spit out the entries" task. What's the catch? Fishing for some free consulting, eh?

    As a side note - only a man could come up with such silly requirement. This Countess would end up on a "dos and don'ts page" of the Glamour magazine with a black rectangle over her face if she dressed like that. Yikes!

    • Feb 27, 2017 at 11:41 AM

      :D Very Funny

      It's only an old Final Exam of a 3 year Degree On Computer Programming Language Course of one recognized teacher of Italian university. Nothing more :) An old problem Trip on how to escape from discussing with a woman .. :D

      It was initially proposed for Pascal - Declaration programming language but it's always a good exercise for recursive questions :)

  • Feb 24, 2017 at 11:33 AM

    I was bored today, so here you have my try.

    I need to check the performance, but I think is working fine.

    With this wardrobe I've got these sets;

    I put all the code in the text attached. In this new community only two attachments are allowed per comment... counting images... and you cannot attach a zip file... :(

    wardrobes.txt (21.4 kB)
    clothes.jpg (180.9 kB)
    • Feb 27, 2017 at 05:02 PM

      I'm sure some folks on SCN will have a fit about the Hungarian notation and routines. :)

      No disrespect to the professor but I'm not sure such tasks necessarily teach the skills needed in real life. Could be just me though... Anyway, thanks for sharing!

      • Feb 27, 2017 at 05:51 PM

        I had to check what Hungarian notation was (I didn't remember it) he he

        Well, I'm used to use it because my current project forces us to use it. They revise the code and check this among other things (some are ridiculous) . If they don't like the code they cancel the transport of the TR until it's fixed.

        Thanks for the feedback!

  • Add a comment
    10|10000 characters needed characters exceeded