<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/finding-possible-class-schedules/"></div></div><div><a data-url="https://www.r-bloggers.com/finding-possible-class-schedules/" data-counturl="https://www.r-bloggers.com/finding-possible-class-schedules/" data-count="horizontal" data-text="Finding possible class schedules" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://feedproxy.google.com/~r/FellgernonBit-rstats/~3/RD7TpdnWac4/materias"> Fellgernon Bit - rstats</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Over the weekend my brother wanted to figure out his class schedule for the next semester. He is a veterinary medicine and zootechnology student at UNAM. For this upcoming semester there is a set of classes he has to take and each has 8 or so instructor options. The website where he finds the class times lists about 8 pre-constructed class schedules. So he normally finds one he likes quite a bit, and then manually starts checking if he can change X instructor for Y for a given class. He does this based on the referalls and information he has gathered about the instructors, plus he factors in whether it’d be an overall better schedule. For example, he might prefer to have a packed Tuesday if that means that he can leave early on Friday and avoid classes on Saturday.</p>
<p>The problem is that it’s very easy to make a mistake. You (well he) gets all excited thinking that he’s found the perfect schedule. Only to then realize that there is a conflict between two classes. Or that the practical portion of a class is in a location one hour away from the university, meaning that the schedule he has selected won’t work. This process is very frustrating.</p>
<p>I was watching him and I started to think if I could help him with some code. Turns out that it was straightforward to write some code to find which options are valid. Once I wrote a test case, it took us like half an hour to fill out the data. I know that tomorrow is when he and his classmates start registering for classes, so this information might help his classmates.</p>
<p>First, I define some helper functions. These are rather straightforward but I’ll be using them later on. For example, <code>dias()</code> is just there for typing less.</p>
<figure>
<pre><code data-lang="r"><span>## Helper functions
</span><span>dias</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>d</span><span>,</span><span> </span><span>i</span><span>)</span><span> </span><span>{</span><span>
</span><span>paste0</span><span>(</span><span>d</span><span>,</span><span> </span><span>i</span><span>)</span><span>
</span><span>}</span><span>
</span><span>extract</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>m</span><span>,</span><span> </span><span>p</span><span>)</span><span> </span><span>{</span><span>
</span><span>m</span><span>[[</span><span>p</span><span>]]</span><span>
</span><span>}</span><span>
</span><span>extract_names</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>m</span><span>,</span><span> </span><span>p</span><span>)</span><span> </span><span>{</span><span>
</span><span>names</span><span>(</span><span>m</span><span>)[</span><span>p</span><span>]</span><span>
</span><span>}</span></code></pre>
</figure>
<p>Next comes the input information. I organized it in a set of nested <code>list</code> objects. The schedule is stored as a character vector. For example, Lucia Eliana’s class meets on Wednesdays (__M__iercoles in Spanish) from 9 to 11 am. I only keep the starting hours (9 and 10 am) because otherwise the code won’t detect valid opitons that include another class that starts at 11 am. For classes that are 1 hour away from the university, we included 1 hour before and 1 hour after the class.</p>
<figure>
<pre><code data-lang="r"><span>## Input class/prof info and schedule
</span><span>materias</span><span> </span><span>&lt;-</span><span> </span><span>list</span><span>(</span><span>
</span><span>repro</span><span> </span><span>=</span><span> </span><span>list</span><span>(</span><span>
</span><span>'lucia eliana'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>8</span><span>:</span><span>13</span><span>)),</span><span>
</span><span>'esquivel lacroix'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>14</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>12</span><span>:</span><span>18</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>14</span><span>:</span><span>15</span><span>)),</span><span>
</span><span>'ismael porras'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>8</span><span>:</span><span>14</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>)),</span><span>
</span><span>'esquivel lacroix 2'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>14</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>14</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>12</span><span>:</span><span>18</span><span>)),</span><span>
</span><span>'salvador galina'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>8</span><span>:</span><span>13</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>)),</span><span>
</span><span>'alberto balcazar'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>15</span><span>:</span><span>16</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>12</span><span>:</span><span>18</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>14</span><span>:</span><span>15</span><span>)),</span><span>
</span><span>'ana myriam boeta'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>8</span><span>:</span><span>13</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>10</span><span>:</span><span>11</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>)),</span><span>
</span><span>'rafael eduardo paz'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>11</span><span>:</span><span>17</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>14</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>16</span><span>:</span><span>17</span><span>)),</span><span>
</span><span>'juan heberth'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>9</span><span>:</span><span>10</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>11</span><span>:</span><span>17</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>11</span><span>:</span><span>12</span><span>)),</span><span>
</span><span>'vicente octavio mejia'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>8</span><span>:</span><span>17</span><span>))</span><span>
</span><span>),</span><span>
</span><span>economia</span><span> </span><span>=</span><span> </span><span>list</span><span>(</span><span>
</span><span>'valentin efren espinoza'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>8</span><span>:</span><span>10</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>9</span><span>:</span><span>11</span><span>)),</span><span>
</span><span>'maria del pilar velazquez'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>16</span><span>:</span><span>18</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>16</span><span>:</span><span>18</span><span>)),</span><span>
</span><span>'arturo alonso pesado'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>)),</span><span>
</span><span>'laura mendez'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>13</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>18</span><span>:</span><span>20</span><span>)),</span><span>
</span><span>'laura mendez 2'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>)),</span><span>
</span><span>'manuela garcia'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>17</span><span>:</span><span>19</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>16</span><span>:</span><span>18</span><span>)),</span><span>
</span><span>'francisco alejandro'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>7</span><span>:</span><span>9</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>7</span><span>:</span><span>9</span><span>)),</span><span>
</span><span>'isaac reyes'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>13</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>13</span><span>:</span><span>15</span><span>)),</span><span>
</span><span>'jose luis tinoco'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>12</span><span>:</span><span>14</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>9</span><span>:</span><span>11</span><span>)),</span><span>
</span><span>'isaac reyes 2'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>14</span><span>:</span><span>16</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>14</span><span>:</span><span>16</span><span>))</span><span>
</span><span>),</span><span>
</span><span>bacterianas</span><span> </span><span>=</span><span> </span><span>list</span><span>(</span><span>
</span><span>'jose luis gutierrez'</span><span> </span><span>=</span><span> </span><span>dias</span><span>(</span><span>'s'</span><span>,</span><span> </span><span>8</span><span>:</span><span>11</span><span>),</span><span>
</span><span>'rodrigo mena'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>18</span><span>:</span><span>19</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>18</span><span>:</span><span>19</span><span>)),</span><span>
</span><span>'beatriz arellano'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>7</span><span>:</span><span>8</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>10</span><span>:</span><span>11</span><span>)),</span><span>
</span><span>'de la pena, ramirez ortega'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>18</span><span>:</span><span>19</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>18</span><span>:</span><span>19</span><span>)),</span><span>
</span><span>'ramirez ortega'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>7</span><span>:</span><span>8</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>7</span><span>:</span><span>8</span><span>)),</span><span>
</span><span>'rodrigo mena 2'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>16</span><span>:</span><span>17</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>16</span><span>:</span><span>17</span><span>)),</span><span>
</span><span>'de la pena'</span><span> </span><span>=</span><span> </span><span>dias</span><span>(</span><span>'s'</span><span>,</span><span> </span><span>8</span><span>:</span><span>11</span><span>),</span><span>
</span><span>'efren diaz aparicio'</span><span> </span><span>=</span><span> </span><span>dias</span><span>(</span><span>'s'</span><span>,</span><span> </span><span>8</span><span>:</span><span>11</span><span>),</span><span>
</span><span>'lucia del carmen favila'</span><span> </span><span>=</span><span> </span><span>dias</span><span>(</span><span>'s'</span><span>,</span><span> </span><span>8</span><span>:</span><span>11</span><span>)</span><span>
</span><span>),</span><span>
</span><span>parasitarias</span><span> </span><span>=</span><span> </span><span>list</span><span>(</span><span>
</span><span>'cintli martinez'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>16</span><span>:</span><span>17</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>18</span><span>:</span><span>20</span><span>)),</span><span>
</span><span>'osvaldo froylan'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>18</span><span>:</span><span>19</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>18</span><span>:</span><span>20</span><span>)),</span><span>
</span><span>'maria quintero, agustin perez'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>13</span><span>:</span><span>14</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>7</span><span>:</span><span>9</span><span>)),</span><span>
</span><span>'maria quintero'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>16</span><span>:</span><span>18</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>16</span><span>:</span><span>17</span><span>)),</span><span>
</span><span>'evangelina romero'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>7</span><span>:</span><span>8</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>7</span><span>:</span><span>9</span><span>)),</span><span>
</span><span>'guadarrama 01'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>7</span><span>:</span><span>8</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>)),</span><span>
</span><span>'guadarrama 03'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>13</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>7</span><span>:</span><span>8</span><span>)),</span><span>
</span><span>'guadarrama 04'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>16</span><span>:</span><span>17</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>18</span><span>:</span><span>20</span><span>)),</span><span>
</span><span>'guadarrama 05'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>7</span><span>:</span><span>9</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>7</span><span>:</span><span>8</span><span>))</span><span>
</span><span>),</span><span>
</span><span>diagnosticas</span><span> </span><span>=</span><span> </span><span>list</span><span>(</span><span>
</span><span>'1701'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>11</span><span>:</span><span>16</span><span>)),</span><span>
</span><span>'1702'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>13</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>13</span><span>:</span><span>18</span><span>)),</span><span>
</span><span>'1703'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>7</span><span>:</span><span>9</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>8</span><span>:</span><span>13</span><span>)),</span><span>
</span><span>'1704'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>18</span><span>:</span><span>20</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>13</span><span>:</span><span>18</span><span>)),</span><span>
</span><span>'1705'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>7</span><span>:</span><span>11</span><span>)),</span><span>
</span><span>'1706'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>15</span><span>:</span><span>17</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'m'</span><span>,</span><span> </span><span>15</span><span>:</span><span>19</span><span>)),</span><span>
</span><span>'1707'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>10</span><span>:</span><span>12</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>10</span><span>:</span><span>15</span><span>)),</span><span>
</span><span>'1708'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>18</span><span>:</span><span>20</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'ma'</span><span>,</span><span> </span><span>15</span><span>:</span><span>19</span><span>)),</span><span>
</span><span>'1709'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'l'</span><span>,</span><span> </span><span>11</span><span>:</span><span>13</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>8</span><span>:</span><span>13</span><span>)),</span><span>
</span><span>'1711'</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>dias</span><span>(</span><span>'j'</span><span>,</span><span> </span><span>13</span><span>:</span><span>15</span><span>),</span><span> </span><span>dias</span><span>(</span><span>'v'</span><span>,</span><span> </span><span>10</span><span>:</span><span>13</span><span>))</span><span>
</span><span>)</span><span>
</span><span>)</span></code></pre>
</figure>
<p>Now that the input information is complete, I use <code>expand.grid()</code> to find out all the different possible options.</p>
<figure>
<pre><code data-lang="r"><span>## Get all the options
</span><span>options</span><span> </span><span>&lt;-</span><span> </span><span>expand.grid</span><span>(</span><span>lapply</span><span>(</span><span>materias</span><span>,</span><span> </span><span>function</span><span>(</span><span>x</span><span>)</span><span> </span><span>{</span><span> </span><span>seq_len</span><span>(</span><span>length</span><span>(</span><span>x</span><span>))}))</span><span>
</span><span>dim</span><span>(</span><span>options</span><span>)</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## [1] 81000     5</code></pre>
</figure>
<p>There’s 81,00 of them including the classes that meet on Saturday. You can see why it’s a frustrating process to find which combination of classes work when doing this manually.</p>
<p>Next, I explore all these options to find those that are valid, meaning that none of the classes overlap. I do this by finding which options have no duplicated hours from the character vectors defined earlier. Nothing fancy.</p>
<figure>
<pre><code data-lang="r"><span>valid</span><span> </span><span>&lt;-</span><span> </span><span>apply</span><span>(</span><span>options</span><span>,</span><span> </span><span>1</span><span>,</span><span> </span><span>function</span><span>(</span><span>input</span><span>)</span><span> </span><span>{</span><span>
</span><span>info</span><span> </span><span>&lt;-</span><span> </span><span>mapply</span><span>(</span><span>extract</span><span>,</span><span> </span><span>materias</span><span>,</span><span> </span><span>input</span><span>)</span><span>
</span><span>!</span><span>any</span><span>(</span><span>duplicated</span><span>(</span><span>unlist</span><span>(</span><span>info</span><span>)))</span><span>
</span><span>})</span></code></pre>
</figure>
<p>Now that I have the valid options, I can find the names of the instructors for them. There’s 2,847 valid schedules in the end, out of the 81,000. That’s 3.5 percent!</p>
<figure>
<pre><code data-lang="r"><span>valid_prof</span><span> </span><span>&lt;-</span><span> </span><span>apply</span><span>(</span><span>options</span><span>[</span><span>valid</span><span>,</span><span> </span><span>],</span><span> </span><span>1</span><span>,</span><span> </span><span>function</span><span>(</span><span>input</span><span>)</span><span> </span><span>{</span><span>
</span><span>mapply</span><span>(</span><span>extract_names</span><span>,</span><span> </span><span>materias</span><span>,</span><span> </span><span>input</span><span>)</span><span>
</span><span>})</span><span>
</span><span>ncol</span><span>(</span><span>valid_prof</span><span>)</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## [1] 2847</code></pre>
</figure>
<p>You can search the interactive version <a target="_blank" href="https://lcolladotor.shinyapps.io/materias/">here</a> to select only the options with a given instructor. For example, in my brother’s case there are 30 valid options once he decided to prioritize two instructors as shown in the non-interactive table below.</p>
<figure>
<pre><code data-lang="r"><span>## Ideally, this code would create an interactive table, but it doesn't work for some reason:
#library('DT')
#datatable(t(valid_prof), options = list(pagingType='full_numbers', pageLength=10), rownames = FALSE)
</span><span>valid_prof</span><span> </span><span>&lt;-</span><span> </span><span>t</span><span>(</span><span>valid_prof</span><span>)</span><span>
</span><span>rownames</span><span>(</span><span>valid_prof</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>seq_len</span><span>(</span><span>nrow</span><span>(</span><span>valid_prof</span><span>))</span><span>
</span><span>top_options</span><span> </span><span>&lt;-</span><span> </span><span>valid_prof</span><span>[</span><span>valid_prof</span><span>[,</span><span> </span><span>1</span><span>]</span><span> </span><span>==</span><span> </span><span>'lucia eliana'</span><span> </span><span>&amp;</span><span> </span><span>valid_prof</span><span>[,</span><span> </span><span>2</span><span>]</span><span> </span><span>%in%</span><span> </span><span>c</span><span>(</span><span>'isaac reyes'</span><span>,</span><span> </span><span>'isaac reyes 2'</span><span>),</span><span> </span><span>]</span><span>
</span><span>kable</span><span>(</span><span>top_options</span><span>,</span><span> </span><span>format</span><span> </span><span>=</span><span> </span><span>'markdown'</span><span>,</span><span> </span><span>row.names</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>)</span></code></pre>
</figure>
<table>
<thead>
<tr>
<th> </th>
<th>repro</th>
<th>economia</th>
<th>bacterianas</th>
<th>parasitarias</th>
<th>diagnosticas</th>
</tr>
</thead>
<tbody>
<tr>
<td>5</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>jose luis gutierrez</td>
<td>cintli martinez</td>
<td>1701</td>
</tr>
<tr>
<td>11</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>rodrigo mena</td>
<td>cintli martinez</td>
<td>1701</td>
</tr>
<tr>
<td>14</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>beatriz arellano</td>
<td>cintli martinez</td>
<td>1701</td>
</tr>
<tr>
<td>19</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>ramirez ortega</td>
<td>cintli martinez</td>
<td>1701</td>
</tr>
<tr>
<td>25</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>de la pena</td>
<td>cintli martinez</td>
<td>1701</td>
</tr>
<tr>
<td>31</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>efren diaz aparicio</td>
<td>cintli martinez</td>
<td>1701</td>
</tr>
<tr>
<td>37</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>lucia del carmen favila</td>
<td>cintli martinez</td>
<td>1701</td>
</tr>
<tr>
<td>46</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>jose luis gutierrez</td>
<td>osvaldo froylan</td>
<td>1701</td>
</tr>
<tr>
<td>50</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>beatriz arellano</td>
<td>osvaldo froylan</td>
<td>1701</td>
</tr>
<tr>
<td>58</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>ramirez ortega</td>
<td>osvaldo froylan</td>
<td>1701</td>
</tr>
<tr>
<td>67</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>de la pena</td>
<td>osvaldo froylan</td>
<td>1701</td>
</tr>
<tr>
<td>76</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>efren diaz aparicio</td>
<td>osvaldo froylan</td>
<td>1701</td>
</tr>
<tr>
<td>85</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>lucia del carmen favila</td>
<td>osvaldo froylan</td>
<td>1701</td>
</tr>
<tr>
<td>123</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>jose luis gutierrez</td>
<td>guadarrama 01</td>
<td>1701</td>
</tr>
<tr>
<td>130</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>rodrigo mena</td>
<td>guadarrama 01</td>
<td>1701</td>
</tr>
<tr>
<td>134</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>beatriz arellano</td>
<td>guadarrama 01</td>
<td>1701</td>
</tr>
<tr>
<td>137</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>de la pena, ramirez ortega</td>
<td>guadarrama 01</td>
<td>1701</td>
</tr>
<tr>
<td>144</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>de la pena</td>
<td>guadarrama 01</td>
<td>1701</td>
</tr>
<tr>
<td>151</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>efren diaz aparicio</td>
<td>guadarrama 01</td>
<td>1701</td>
</tr>
<tr>
<td>158</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>lucia del carmen favila</td>
<td>guadarrama 01</td>
<td>1701</td>
</tr>
<tr>
<td>209</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>jose luis gutierrez</td>
<td>guadarrama 05</td>
<td>1701</td>
</tr>
<tr>
<td>217</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>rodrigo mena</td>
<td>guadarrama 05</td>
<td>1701</td>
</tr>
<tr>
<td>222</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>de la pena, ramirez ortega</td>
<td>guadarrama 05</td>
<td>1701</td>
</tr>
<tr>
<td>232</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>de la pena</td>
<td>guadarrama 05</td>
<td>1701</td>
</tr>
<tr>
<td>242</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>efren diaz aparicio</td>
<td>guadarrama 05</td>
<td>1701</td>
</tr>
<tr>
<td>252</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>lucia del carmen favila</td>
<td>guadarrama 05</td>
<td>1701</td>
</tr>
<tr>
<td>872</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>jose luis gutierrez</td>
<td>guadarrama 05</td>
<td>1704</td>
</tr>
<tr>
<td>885</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>de la pena</td>
<td>guadarrama 05</td>
<td>1704</td>
</tr>
<tr>
<td>894</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>efren diaz aparicio</td>
<td>guadarrama 05</td>
<td>1704</td>
</tr>
<tr>
<td>903</td>
<td>lucia eliana</td>
<td>isaac reyes 2</td>
<td>lucia del carmen favila</td>
<td>guadarrama 05</td>
<td>1704</td>
</tr>
</tbody>
</table>
<h3>Reproducibility</h3>
<figure>
<pre><code data-lang="r"><span>## Reproducibility info
</span><span>library</span><span>(</span><span>'devtools'</span><span>)</span><span>
</span><span>session_info</span><span>()</span></code></pre>
</figure>
<figure>
<pre><code data-lang="text">## Session info --------------------------------------------------------------</code></pre>
</figure>
<figure>
<pre><code data-lang="text">##  setting  value                       
##  version  R version 3.3.0 (2016-05-03)
##  system   x86_64, mingw32             
##  ui       RStudio (0.99.902)          
##  language (EN)                        
##  collate  English_United States.1252  
##  tz       America/Mexico_City         
##  date     2016-08-02</code></pre>
</figure>
<figure>
<pre><code data-lang="text">## Packages ------------------------------------------------------------------</code></pre>
</figure>
<figure>
<pre><code data-lang="text">##  package   * version date       source        
##  devtools  * 1.12.0  2016-06-24 CRAN (R 3.3.1)
##  digest      0.6.9   2016-01-08 CRAN (R 3.3.0)
##  evaluate    0.9     2016-04-29 CRAN (R 3.3.0)
##  formatR     1.4     2016-05-09 CRAN (R 3.3.0)
##  highr       0.6     2016-05-09 CRAN (R 3.3.0)
##  knitr     * 1.13    2016-05-09 CRAN (R 3.3.0)
##  magrittr    1.5     2014-11-22 CRAN (R 3.3.0)
##  memoise     1.0.0   2016-01-29 CRAN (R 3.3.0)
##  rsconnect   0.4.3   2016-05-02 CRAN (R 3.3.0)
##  stringi     1.1.1   2016-05-27 CRAN (R 3.3.0)
##  stringr     1.0.0   2015-04-30 CRAN (R 3.3.0)
##  withr       1.0.2   2016-06-20 CRAN (R 3.3.1)</code></pre>
</figure>
<h3>Want more?</h3>
<p>Check other <a target="_blank" href="https://twitter.com/jhubiostat">@jhubiostat</a> student blogs at <a target="_blank" href="http://bmorebiostat.com/">Bmore Biostats</a> as well as topics on <a target="_blank" href="https://twitter.com/search?q=%23rstats">#rstats</a>.</p>
<p><img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/FellgernonBit-rstats/~4/RD7TpdnWac4"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/finding-possible-class-schedules/"></div></div><div><a data-url="https://www.r-bloggers.com/finding-possible-class-schedules/" data-counturl="https://www.r-bloggers.com/finding-possible-class-schedules/" data-count="vertical" data-text="Finding possible class schedules" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://feedproxy.google.com/~r/FellgernonBit-rstats/~3/RD7TpdnWac4/materias"> Fellgernon Bit - rstats</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/n1Cai37RgqY"></a></div>