A couple of other responders answered the Quora question I posted useing
the same approach as Roger used. Here's the link to the problem and the
posted answers.  https://bit.ly/34hhA9B
However, I use Quora mainly to polish my J skills, so I try to solve Quora
problems by brute force, using generating verbs such as permutation,
combination, and odometer, to generate actual data structures that
represent the problem, rather than using pure statistical approaches. This
is mainly because I'm not much of a statistician, but I also want to be
able to examine the resulting data structures to answer additional
questions such as: "How many ways can guest 3 & 6 be together", or "How
many ways are there where guests 4, 6, or 7 never stay in the same room
with the other two", or perhaps the AND of those two constraints. Once I
have built the data structure, even my J skills can usually extract
those kinds of answers from the data structures.

Skip Cave



On Tue, Apr 7, 2020 at 7:04 PM Roger Hui <[email protected]> wrote:

> Rationale:  Start with 10 guesses.  In the room with 4 beds, there are 4!10
> ways to choose the guests.  After that, there are 6 guests left, and 2!6
> different ways to put them into a room with 2 beds.  After that, there are
> 4 guests left, and 2!4 ways to put them into a room with 2 beds.  After
> that, there are 2 guests left, and 2!2 ways to put them into the last room
> with 2 beds.
>
> I guess we are assuming that guests do not share a bed, and a guest can not
> take up more than one bed.
>
>
>
> On Tue, Apr 7, 2020 at 5:00 PM Roger Hui <[email protected]>
> wrote:
>
> > A hotel has 4 rooms. In one of them, there are 4 beds and in the rest 2
> > beds. How many different ways can you put 10 passengers in these rooms?*
> >
> >    */ 4 2 2 2 ! 10 6 4 2
> > 18900
> >
> > Curious they talk about putting passengers in the rooms rather than
> guests.
> >
> >
> > On Tue, Apr 7, 2020 at 4:45 PM Skip Cave <[email protected]>
> wrote:
> >
> >> Here's the Quora problem I wanted to solve with the partition question:
> >>
> >> *A hotel has 4 rooms. In one of them, there are 4 beds and in the rest 2
> >> beds. How many different ways can you put 10 passengers in these rooms?*
> >>
> >> Using the J programming language, brute force approach:
> >>
> >> p=.1 0 0 0 1 0 1 0 1 0 NB. Partition vector
> >>
> >> Generate all the permutations on 10 unique items. Partition each
> >> permutation into 4 partitions, (4, 2, 2, 2). Sort each partition, then
> >> remove all duplicate sets of 4 partition sets. Store the reduced
> partition
> >> sets in nn, and report the final size.
> >>
> >> $nn=.~.;"1/:~"1 ea p<;.1"1 perm 10
> >>
> >> 18900 10
> >>
> >> So the answer is 18,900 unique ways to partition 10 guests in 4 rooms
> (4,
> >> 2, 2, 2).
> >>
> >> Show the first and last few partition options:
> >>
> >> 10{. pnn=.p<;.1"1 nn
> >>
> >> │0 1 2 3│4 5│6 7│8 9│
> >>
> >> │0 1 2 3│4 5│6 8│7 9│
> >>
> >> │0 1 2 3│4 5│6 9│7 8│
> >>
> >> │0 1 2 3│4 5│7 8│6 9│
> >>
> >> │0 1 2 3│4 5│7 9│6 8│
> >>
> >> │0 1 2 3│4 5│8 9│6 7│
> >>
> >> │0 1 2 3│4 6│5 7│8 9│
> >>
> >> │0 1 2 3│4 6│5 8│7 9│
> >>
> >> │0 1 2 3│4 6│5 9│7 8│
> >>
> >> │0 1 2 3│4 6│7 8│5 9│ …..
> >>
> >> ….│6 7 8 9│3 5│0 4│1 2│
> >>
> >> │6 7 8 9│3 5│1 2│0 4│
> >>
> >> │6 7 8 9│3 5│1 4│0 2│
> >>
> >> │6 7 8 9│3 5│2 4│0 1│
> >>
> >> │6 7 8 9│4 5│0 1│2 3│
> >>
> >> │6 7 8 9│4 5│0 2│1 3│
> >>
> >> │6 7 8 9│4 5│0 3│1 2│
> >>
> >> │6 7 8 9│4 5│1 2│0 3│
> >>
> >> │6 7 8 9│4 5│1 3│0 2│
> >>
> >> │6 7 8 9│4 5│2 3│0 1│
> >> Skip Cave
> >> Cave Consulting LLC
> >>
> >>
> >> On Tue, Apr 7, 2020 at 4:13 PM Hauke Rehr <[email protected]>
> wrote:
> >>
> >> > sorry, I mistook the full stop for an inflection
> >> >
> >> > Am 07.04.20 um 23:10 schrieb Skip Cave:
> >> > > L: https://code.jsoftware.com/wiki/Vocabulary/lcapco
> >> > > Skip Cave
> >> > > Cave Consulting LLC
> >> > >
> >> > >
> >> > > On Tue, Apr 7, 2020 at 4:03 PM Skip Cave <[email protected]>
> >> > wrote:
> >> > >
> >> > >> It is just L:
> >> > >>
> >> > >> Skip Cave
> >> > >> Cave Consulting LLC
> >> > >>
> >> > >>
> >> > >> On Tue, Apr 7, 2020 at 4:02 PM Hauke Rehr <[email protected]>
> >> > wrote:
> >> > >>
> >> > >>> Where is L:. documented? I can’t find it in the Vocabulary.
> >> > >>>
> >> > >>> Am 07.04.20 um 22:59 schrieb Skip Cave:
> >> > >>>> That's it!
> >> > >>>> I wanted a combination of partitioning and indexing, and L: does
> >> the
> >> > >>> job. I'll
> >> > >>>> have to do some studying to understand L:.
> >> > >>>>
> >> > >>>> r
> >> > >>>>
> >> > >>>> 9 8 6 1 2 2 2 6 8 7
> >> > >>>>
> >> > >>>> 5 4 8 4 2 7 9 1 4 1
> >> > >>>>
> >> > >>>> 4 3 3 7 7 0 6 7 6 6
> >> > >>>>
> >> > >>>> m1
> >> > >>>>
> >> > >>>> ┌───────┬─────┬───┬─┐
> >> > >>>>
> >> > >>>> │0 1 5 3│4 2 8│7 6│9│
> >> > >>>>
> >> > >>>> └───────┴─────┴───┴─┘
> >> > >>>>
> >> > >>>> m1 {L:0"1 r
> >> > >>>>
> >> > >>>> ┌───────┬─────┬───┬─┐
> >> > >>>>
> >> > >>>> │9 8 2 1│2 6 8│6 2│7│
> >> > >>>>
> >> > >>>> ├───────┼─────┼───┼─┤
> >> > >>>>
> >> > >>>> │5 4 7 4│2 8 4│1 9│1│
> >> > >>>>
> >> > >>>> ├───────┼─────┼───┼─┤
> >> > >>>>
> >> > >>>> │4 3 0 7│7 3 6│7 6│6│
> >> > >>>>
> >> > >>>> └───────┴─────┴───┴─┘
> >> > >>>>
> >> > >>>>
> >> > >>>> On the other hand, if all I want to do is partition arrays,
> Michael
> >> > >>> Day's
> >> > >>>> solution is a handy technique that I will try to remember:
> >> > >>>>
> >> > >>>>
> >> > >>>> 1 0 0 0 1 0 0 1 0 1 <;.1"1 r
> >> > >>>>
> >> > >>>> ┌───────┬─────┬───┬─┐
> >> > >>>>
> >> > >>>> │9 8 6 1│2 2 2│6 8│7│
> >> > >>>>
> >> > >>>> ├───────┼─────┼───┼─┤
> >> > >>>>
> >> > >>>> │5 4 8 4│2 7 9│1 4│1│
> >> > >>>>
> >> > >>>> ├───────┼─────┼───┼─┤
> >> > >>>>
> >> > >>>> │4 3 3 7│7 0 6│7 6│6│
> >> > >>>>
> >> > >>>> └───────┴─────┴───┴─┘
> >> > >>>> Skip Cave
> >> > >>>>
> >> ----------------------------------------------------------------------
> >> > >>>> For information about J forums see
> >> > http://www.jsoftware.com/forums.htm
> >> > >>>>
> >> > >>>
> >> > >>> --
> >> > >>> ----------------------
> >> > >>> mail written using NEO
> >> > >>> neo-layout.org
> >> > >>>
> >> > >>>
> >> ----------------------------------------------------------------------
> >> > >>> For information about J forums see
> >> http://www.jsoftware.com/forums.htm
> >> > >>>
> >> > >>
> >> > >
> ----------------------------------------------------------------------
> >> > > For information about J forums see
> >> http://www.jsoftware.com/forums.htm
> >> > >
> >> >
> >> > --
> >> > ----------------------
> >> > mail written using NEO
> >> > neo-layout.org
> >> >
> >> > ----------------------------------------------------------------------
> >> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> >> >
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >>
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to