# Coding challenge (on Ruby Garden)

From: George Ogata [mailto:g_ogata@optushome.com.au]
This bit looks strange to me, though:

if (arr_of_arr.length - (arr_of_arr - arr).length) > arr.length
^^^^^^^^^^^^^^^^

Of course, you are right… this line should be
if (arr_of_arr.length - (arr_of_arr.delete_if{|a| a == arr}) > arr.length

with this change, this latest failure passes. Can’t wait for the next one

David

David Naseby wrote:

From: George Ogata [mailto:g_ogata@optushome.com.au]
This bit looks strange to me, though:

if (arr_of_arr.length - (arr_of_arr - arr).length) > arr.length
^^^^^^^^^^^^^^^^

Of course, you are right… this line should be
if (arr_of_arr.length - (arr_of_arr.delete_if{|a| a == arr}) > arr.length

with this change, this latest failure passes. Can’t wait for the next one

David

Hope I didn’t keep you waiting too long…

one_in_each([1,2,3,4],[[1,3,4],[1,2,3,4],[2,3,4],])

should be false.

Hope I didn’t keep you waiting too long…

one_in_each([1,2,3,4],[[1,3,4],[1,2,3,4],[2,3,4],])

should be false.

Your solution fails, i.e. it returns false, for

``````items = [1,2,2]
row =   [1,2]
rows = [ row, row, [1,3]]
``````

/Christoph

···

“George Ogata” g_ogata@optushome.com.au wrote

Christoph wrote:

Your solution fails, i.e. it returns false, for

``````items = [1,2,2]
row =   [1,2]
rows = [ row, row, [1,3]]
``````

Good point.

Hmm, I wonder if I can get away with it by being pedantic about the wording of the
requirements.

But this doesn't work:

array: [1,2]
a-of-as: [ [1,2,3,4], [5,6,7,8] ]

because the 1 and the 2 both get placed in the same array; it’s
a many-to-one correspondence.

In your example, the 1 and the 2 get “placed in the same array”. The array just appears
more than once. Or does it have to be a capitalized “Array” for this argument to hold?

Oh well, if it’s not acceptable, then:

def one_in_each
i,r;i==||r.find{|s|s.member?(i[0])&&one_in_each(i[1…-1],((d=r.dup).slice!r.index
s;d))}!=nil;end

(115 chars — replace newlines with spaces.)