# Re: Mix and Match (#186)

**URL:** <https://www.ruby-forum.com/t/re-mix-and-match-186/155686>\
**Category:** Ruby\
**Created:** [December 15, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686 "2008-12-15T16:27:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 15, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/1 "2008-12-15T16:27:46Z")

</div>

Is it possible to post a solution already? (I guess the question is  
poetical, just strange that no one posted one yet - was it so hard, or  
no  
one has time amidst the pre-XMas craze, or… ?)

Cheers,  
Peter

* * *

[http://scrubyt.org](http://scrubyt.org)  
[http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 15, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/2 "2008-12-15T16:39:34Z")

</div>

On Dec 15, 2008, at 9:19 AM, removed\_email\_address@domain.invalid wrote:

> Is it possible to post a solution already? (I guess the question is  
> poetical, just strange that no one posted one yet - was it so hard,  
> or no  
> one has time amidst the pre-XMas craze, or… ?)

Perhaps a little harder than it may appear, or as you suggest, people  
may be busy. In the worst case, a brute force solution should be easy  
to do.

I may try this later today, or tomorrow, once I’m done with the last  
papers I need for school and some other errands.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 15, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/3 "2008-12-15T22:52:26Z")

</div>

On Mon, Dec 15, 2008 at 3:31 PM, Matthew M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Dec 15, 2008, at 9:19 AM, removed\_email\_address@domain.invalid wrote:
> 
> Is it possible to post a solution already? (I guess the question is
> 
> > poetical, just strange that no one posted one yet - was it so hard, or no  
> > one has time amidst the pre-XMas craze, or… ?)
> 
> Perhaps a little harder than it may appear, or as you suggest, people may  
> be busy. In the worst case, a brute force solution should be easy to do.

Seeing as how this quiz has been so quiet, here’s a v quick (and very  
brute  
force!) attempt: [http://pastie.org/339925](http://pastie.org/339925) - - please be kind! 🙂

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2008, 1:49am UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/4 "2008-12-16T01:49:42Z")

</div>

On 15.12.2008, at 23:07 , Matthew M. wrote:

> > > > hard, or no  
> > > > very brute
> 
> What I meant is that if I give Janet garden/lavender/orange, I  
> should not also give Nancy garden/lavender/orange. I want a distinct  
> combination for each recipient.

I am not about to partake but these requirements seem to conflict, no?

ppl = [:janet, :nancy, :betty]  
candles = [:lavender =\> 3, :garden =\> 3, :orange =\> 3].

the following seems like the best answer to me but contains duplication,

lav, lav, ger  
gar, or, or  
gar, or, lav

the “uniquest” would be:

lav, lav, lav  
gar, gar, gar  
or. or. or

but it has more duplication whereas the least duplication has no  
uniqueness:  
lav, gar, or  
lav, gar, or  
lav, gar, or

How is uniqueness supposed to be balanced against duplication?

einarmagnus

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2008, 12:15am UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/5 "2008-12-16T00:15:32Z")

</div>

On Dec 15, 2008, at 3:44 PM, steven shingler wrote:

> > Perhaps a little harder than it may appear, or as you suggest,  
> > people may  
> > be busy. In the worst case, a brute force solution should be easy  
> > to do.
> 
> Seeing as how this quiz has been so quiet, here’s a v quick (and  
> very brute  
> force!) attempt: [http://pastie.org/339925](http://pastie.org/339925) - - please be kind! 🙂

Minor point… I probably wasn’t clear by “minimize group duplication.”

In your code, you use dup\_count in an attempt to avoid having a  
particular recipient’s gift contain duplication candles. Actually, I  
like this requirement, although it wasn’t what I meant. (Other subs:  
please try and make each gift without candle duplication.)

What I meant is that if I give Janet garden/lavender/orange, I should  
not also give Nancy garden/lavender/orange. I want a distinct  
combination for each recipient.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2008, 2:21am UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/6 "2008-12-16T02:21:52Z")

</div>

> But seriously, it will depend on the input. If I had to choose between  
> those options, I’d prefer to give individuals a variety of fragrances  
> (avoid duplication more than enforcing uniqueness).

oops that sucks (should have read the quiz more carefully) - my solution  
is enforcing uniqueness but doesn’t care about duplication at all ☹  
Shouldn’t take too much effort to add that though… will do tomorrow.

Cheers,  
Peter

* * *

[http://scrubyt.org](http://scrubyt.org)  
[http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2008, 2:07am UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/7 "2008-12-16T02:07:51Z")

</div>

On Dec 15, 2008, at 6:41 PM, Einar Magnús Boson wrote:

> > > > On Dec 15, 2008, at 9:19 AM, removed\_email\_address@domain.invalid wrote:  
> > > > to do.  
> > > > In your code, you use dup\_count in an attempt to avoid having a
> 
> gar, or, lav  
> lav, gar, or  
> lav, gar, or  
> lav, gar, or
> 
> How is uniqueness supposed to be balanced against duplication?

By buying more candles. 😃

But seriously, it will depend on the input. If I had to choose between  
those options, I’d prefer to give individuals a variety of fragrances  
(avoid duplication more than enforcing uniqueness).

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2008, 3:08am UTC](https://www.ruby-forum.com/t/re-mix-and-match-186/155686/8 "2008-12-16T03:08:03Z")

</div>

> But seriously, it will depend on the input. If I had to choose between  
> those options, I’d prefer to give individuals a variety of fragrances  
> (avoid duplication more than enforcing uniqueness).

Ok so a beefed up version (no duplicates if possible, and as unique as  
possible):

[http://pastie.org/339995](http://pastie.org/339995)

Cheers,  
Peter

* * *

[http://scrubyt.org](http://scrubyt.org)  
[http://www.rubyrailways.com](http://www.rubyrailways.com)
