1
\$\begingroup\$

Christmas is coming up, and this year you have been charged with organizing your family's christmas get-together. You have a list of foods you want be there, but before you assign foods to people, you need to know who's coming. So...

Challenge

Given an input of relative's names separated by commas or whatever (note that the names may have spaces in them, e.g. "Aunt Gertrude") and a list of meals including turkey, divide the meals among them equally, but saving the turkey and any extra for yourself, because you don't want to be unfair. In other words, if 6 people are coming and there are 10 meals, you have to do the turkey and 3 others, because 6 goes into 9 once, leaving 4 for you. Input will never have more people than meals.

Full list of possible dishes (Taken from Wikipedia)

Apple Cider
Boiled Custard
Candy canes
Champagne
Chocolate fudge
Christmas cookies
Cranberry sauce
Eggnog
Fish
Fruitcake
Gingerbread Men
Christmas ham
Hot buttered rum
Hot chocolate
Mashed potato
Mixed nuts
Oyster stew
Persimmon pudding
Apple pie
Pecan pie
Pumpkin pie
Sparkling cider
Stuffing
Sweet potato pie
Sweet potato casserole with marshmallow
Russian tea cakes
Tom and Jerry
Turkey


Here is a formatted version if you prefer:
["Apple Cider","Boiled Custard","Candy canes","Champagne","Chocolate fudge","Christmas cookies","Cranberry Sauce","Eggnog","Fish","Fruitcake","Gingerbread Men","Christmas Ham","Hot buttered rum","Hot chocolate","Mashed potato","Mixed nuts","Oyster stew","Persimmon pudding","Apple pie","Pecan pie","Pumpkin pie","Sparkling cider","Stuffing","Sweet potato pie","Sweet potato casserole with marshmallow","Russian tea cakes","Tom and Jerry","Turkey"]

Name format

Relative's names will take any of the following formats

Aunt x
Uncle x
Creepy Uncle x
Grandpa x
Grandma x
Cousin x
Mother-in-law x
Father-in-law x
Papa x
Nana x
x
x can be any 20 char or less combination of upper/lower case letters

I/O

Input can be taken in any reasonable, convenient format, but I will assume list if not otherwise specified: [relative a,b,c],[food x,y,z]

Output can also be in any reasonable convenient format, I personally prefer a list of lists You do not need to output the turkey or extra meals

Examples

["Aunt Gertrude", "Cousin Sally", "Grandpa Joe", "Creepy Uncle Rick"],["Sparkling Cider", "Pumpkin Pie", "Pecan Pie", "Oyster Stew", "Chocolate Fudge", "Turkey"] -> [["Aunt Gertrude","Sparkling Cider"],["Cousin Sally", "Pumpkin Pie"],["Grandpa Joe","Pecan Pie"],["Creepy Uncle Rick","Oyster Stew"]]

["Aunt getoFFmyLAWn","Grandpa Lipbalm","Cousin onlyplaysroblox","Papa losthisjob"],["Pumpkin pie","Sparkling cider","Stuffing","Sweet potato pie","Sweet potato casserole with marshmallow","Russian tea cakes","Tom and Jerry"] -> [['Aunt getoFFmyLAWn', 'Pumpkin pie'], ['Grandpa Lipbalm', 'Sparkling cider'], ['Cousin onlyplaysroblox', 'Stuffing'], ['Papa losthisjob', 'Sweet potato pie']]

As christmas is almost here, you don't have time to be planning more than needed, so use those skills and program up some lists!

Notes

  • No standard loopholes
  • If you have only a function, please provide code to call it as well
  • Please provide an explanation
  • Smallest byte count ~ 2-3 days after Christmas wins!
\$\endgroup\$
  • 2
    \$\begingroup\$ Most votes by ~ 2-3 days after Christmas wins! but you have tagged your challenge code-golf (I suggest removing the last note, and don’t make this a bad pop-con!) \$\endgroup\$ – Mr. Xcoder Dec 23 '17 at 22:04
  • \$\begingroup\$ @Mr.Xcoder good catch! \$\endgroup\$ – FantaC Dec 23 '17 at 22:49
  • 1
    \$\begingroup\$ @JonathanAllan Fixed \$\endgroup\$ – FantaC Dec 23 '17 at 22:50
  • \$\begingroup\$ Can the x in the names contain spaces (e.g. "Cousin George jr.")? \$\endgroup\$ – Titus Dec 27 '18 at 20:15
  • \$\begingroup\$ @Titus no you are not required to add that capability \$\endgroup\$ – FantaC Jan 7 at 19:51
3
\$\begingroup\$

Jelly, 17 bytes

I went off-piste with the meals in my example without realising! It shouldn't matter I think, and looks tastier to my British eyes.

ḟ“Øẇ½»W¤s⁹L‘¤ṖZṖż

A dyadic link taking a list of foods (lists of characters) on the left and people (also lists of characters) on the right which returns a list containing a list per person containing a list of characters (their name) and a list of foods (each a list of characters).

e.g. (using "..." to represent a list of characters):

left = ["Champagne", "Turkey", "Stuffing", "Port", "Roast Potatoes", "Brussel Sprouts", "Parsnips", "Pigs In Blankets", "Gravy", "Steamed Vegetables", "Cheese Plate", "Christmas Pudding"]
right = ["Aunt Gertrude", "Cousin Sally", "Grandpa Joe"]

output = [[["Champagne", "Brussel Sprouts"],"Aunt Gertrude"],[["Stuffing", "Parsnips"],"Cousin Sally"],[["Port", "Pigs In Blankets"],"Grandpa Joe"]]

(leaving us with Turkey, Roast Potatoes, Gravy, Steamed Vegetables, and Christmas Pudding.)

Try it online! (The footer calls the dyadic link and then pretty prints the result)

How?

ḟ“Øẇ½»W¤s⁹L‘¤ṖZṖż - Link: foods, people
            ¤     - nilad followed by link(s) as a nilad:
         ⁹        -   chain's right argument, people
          L       -   length
           ‘      -   increment (add yourself to the cook count)
       ¤          - nilad followed by link(s) as a nilad:
 “Øẇ½»            -   compressed string = list of characters, ['T','u','r','k','e','y']
      W           -   wrap in a list                          [['T','u','r','k','e','y']]
ḟ                 - filter discard (from foods) if exists in that list (we cook any Turkey)
        s         - split (the resulting list of foods) into chunks (of number of cooks)
             Ṗ    - pop off the excess
              Z   - transpose to a list of fair shares
               Ṗ  - pop off our share
                ż - zip with people names (to provide the allocations)
\$\endgroup\$
  • \$\begingroup\$ That looks to be a brilliant Christmas lunch! Who doesn't like pigs in blankets! \$\endgroup\$ – caird coinheringaahing Dec 24 '17 at 5:06
1
\$\begingroup\$

Operation Flashpoint scripting language, 155 bytes

f={t=_this;a=t select 0;b=(t select 1)-["Turkey"];i=0;d=count a;e=count b;c=e/d;c=c-c%1;while{i<c*d}do{a set[i%d,(a select i%d)+","+(b select i)];i=i+1};a}

Call with:

array = [["Aunt Gertrude", "Cousin Sally", "Grandpa Joe", "Creepy Uncle Rick"],["Sparkling Cider", "Pumpkin Pie", "Pecan Pie", "Oyster Stew", "Chocolate Fudge", "Turkey"]];
hint format["%1", array call f]

Output:

\$\endgroup\$
  • \$\begingroup\$ wth this is awesome \$\endgroup\$ – FantaC Dec 24 '17 at 17:05
0
\$\begingroup\$

PHP, 112 bytes

function($p,$f){return array_combine($p+[($n=count($p))=>0],array_chunk(array_diff($f,[Turkey]),count($f)/$n));}

anonymous function, takes an array of people and an array of meals,
returns an associative array name=>array of meals plus one element 0=>extra meals (without the Turkey).

Try it online.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.