Skip to Content

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.

Example:

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.

Thanks

Regards.

0
Show 13
* Please Login or Register to Comment on or Follow discussions.
avatar image
Feb 22, 2017 at 05:12 PM
244

Hi,

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

Andy

4 Share

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

1 Share

Hi Roberto,

ok you got me, I concede defeat :-)

Andy.

0 Share

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!

Rob

0 Share

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!

4 Share

: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 :)

0 Share

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)
3 Share

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!

0 Share

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!

1 Share
3 Share

"When you do things right, people won't be sure you've done anything at all" .. that's an old fancy way to say that real life is not necessarily a right life..

In real life they tell you black is white, and the moon is just the sun at night. Hungarian Notation is in the end a commenting technique and comments lie :)

0 Share

Looks like Hungarians and Polish liked their notations! Thanks for the link Jelena, at least now I know the source of much of my scorn; and that Hungarian notation is nothing like Polish notation. I just searched and came up with a Czech notation too. I wonder if any of the other former Eastern Block have their own notations.

1 Share

A commenting technique so robust that it is fused with real code.

0 Share
10 |10000 characters needed characters left characters exceeded