Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Friday Programming Quiz [modified]

Friday Programming Quiz [modified]

Scheduled Pinned Locked Moved The Lounge
helptutorial
34 Posts 15 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Rama Krishna Vavilala

    Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #2

    Assuming that low a number of ingredients, you could write code that assigns a bit to each ingredient, and a field with the bits set for the ingredients that each cocktail needs. Then you can very simply work out which ones you have the ingredients for, without having to write much code at all. Anna Kournikova is a cocktail ? Yummy.

    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

    R S E 3 Replies Last reply
    0
    • C Christian Graus

      Assuming that low a number of ingredients, you could write code that assigns a bit to each ingredient, and a field with the bits set for the ingredients that each cocktail needs. Then you can very simply work out which ones you have the ingredients for, without having to write much code at all. Anna Kournikova is a cocktail ? Yummy.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      R Offline
      R Offline
      Rama Krishna Vavilala
      wrote on last edited by
      #3

      Christian Graus wrote:

      Assuming that low a number of ingredients, you could write code that assigns a bit to each ingredient, and a field with the bits set for the ingredients that each cocktail needs. Then you can very simply work out which ones you have the ingredients for, without having to write much code at all.

      Is that Plain English code? :)

      C 1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        Christian Graus wrote:

        Assuming that low a number of ingredients, you could write code that assigns a bit to each ingredient, and a field with the bits set for the ingredients that each cocktail needs. Then you can very simply work out which ones you have the ingredients for, without having to write much code at all.

        Is that Plain English code? :)

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #4

        LOL - could be. It struck me as the sort of thing that requires too much code for me to bother, but the code is obvious once I explained the approach. It's Saturday morning here and I worked until midnight last night, give me a break :-)

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        1 Reply Last reply
        0
        • C Christian Graus

          Assuming that low a number of ingredients, you could write code that assigns a bit to each ingredient, and a field with the bits set for the ingredients that each cocktail needs. Then you can very simply work out which ones you have the ingredients for, without having to write much code at all. Anna Kournikova is a cocktail ? Yummy.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #5

          Christian Graus wrote:

          Anna Kournikova is a cocktail ? Yummy.

          Heh. It's a white russian, but with very little fat. Geddit? Eh? Eh? :rolleyes:

          ----

          i hope you are feeling sleepy for people not calling you by the same.

          --BarnaKol on abusive words

          1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

            M Offline
            M Offline
            Member 96
            wrote on last edited by
            #6

            Um...the output should be Anna Kournikova only. You can't make a Pina Colada without pineapple juice or coconut milk.


            "110%" - it's the new 70%

            M R 2 Replies Last reply
            0
            • R Rama Krishna Vavilala

              Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

              M Offline
              M Offline
              Michael Bergman
              wrote on last edited by
              #7

              Rama Krishna Vavilala wrote:

              Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Pina Colada -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 17:58 Friday 11th May, 2007

              Given that there isn't any Coconut Juice or Pinapple Juice in stock, did you want an algorithm with a bug which adds them in (and removes the Beer, 151 Rum, and Amaretto)? Just curious.

              m.bergman

              -- For Bruce Schneier, quanta only have one state : afraid.

              R P 2 Replies Last reply
              0
              • M Member 96

                Um...the output should be Anna Kournikova only. You can't make a Pina Colada without pineapple juice or coconut milk.


                "110%" - it's the new 70%

                R Offline
                R Offline
                Rama Krishna Vavilala
                wrote on last edited by
                #8

                OOPS: I corrected it.

                M 1 Reply Last reply
                0
                • M Member 96

                  Um...the output should be Anna Kournikova only. You can't make a Pina Colada without pineapple juice or coconut milk.


                  "110%" - it's the new 70%

                  M Offline
                  M Offline
                  Michael Bergman
                  wrote on last edited by
                  #9

                  You could make the Flaming Dr Pepper with the items in stock.

                  m.bergman

                  -- For Bruce Schneier, quanta only have one state : afraid.

                  1 Reply Last reply
                  0
                  • R Rama Krishna Vavilala

                    OOPS: I corrected it.

                    M Offline
                    M Offline
                    Michael Bergman
                    wrote on last edited by
                    #10

                    Rama Krishna Vavilala wrote:

                    OOPS: I corrected it.

                    You are, indeed, faster than I. ;P

                    m.bergman

                    -- For Bruce Schneier, quanta only have one state : afraid.

                    1 Reply Last reply
                    0
                    • M Michael Bergman

                      Rama Krishna Vavilala wrote:

                      Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Pina Colada -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 17:58 Friday 11th May, 2007

                      Given that there isn't any Coconut Juice or Pinapple Juice in stock, did you want an algorithm with a bug which adds them in (and removes the Beer, 151 Rum, and Amaretto)? Just curious.

                      m.bergman

                      -- For Bruce Schneier, quanta only have one state : afraid.

                      R Offline
                      R Offline
                      Rama Krishna Vavilala
                      wrote on last edited by
                      #11

                      Sorry! It's corrected

                      1 Reply Last reply
                      0
                      • R Rama Krishna Vavilala

                        Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

                        J Offline
                        J Offline
                        Josh Smith
                        wrote on last edited by
                        #12

                        Rama Krishna Vavilala wrote:

                        Beer

                        Mmmmmmm....beer....friday night......brain go byebye.....beeeer

                        :josh: My WPF Blog[^] FYI - Bob is a scarecrow who keeps Chuck Norris away from CodeProject.

                        1 Reply Last reply
                        0
                        • R Rama Krishna Vavilala

                          Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

                          D Offline
                          D Offline
                          David Stone
                          wrote on last edited by
                          #13

                          Here's an oddball language. Prolog. We did a similar solution involving restaurants and meals in my programming languages class a few quarters ago. Here's the adaptation for this problem. (I'm half betting/half hoping that nobody will actually plug this into a prolog interpreter...as I didn't actually check any of it. ;P This should work though.)

                          item(Vodka).
                          item(Rum).
                          item(OneFiftyOneRum).
                          item(Beer).
                          item(Amaretto).
                          item(Kahlua).
                          item(SkimMilk).
                          item(Mint).
                          item(Sugar).
                          item(CoconutJuice).
                          item(PineappleJuice);
                          item(Bourbon).

                          drink(AnnaKournikova, [Vodka, Kahlua, SkimMilk]).
                          drink(FlamingDrPepper, [Beer, OneFiftyOneRum, Amaretto]).
                          drink(PinaColada, [Rum, CoconutJuice, PineappleJuice]).
                          drink(MintJulep, [Mint, Bourbon, Sugar]).

                          stock([Vodka, Rum, OneFiftyOneRum, Beer, Amaretto, Kahlua, SkimMilk, Mint, Sugar]).

                          % Determines if the Drink is made with the given Ingredients
                          canBeMade(Drink, Ingredients) :-
                             drink(Drink, ActualIngredients),                          % Get the ingredients in the meal
                             intersection(ActualIngredients, Ingredients, Intersect),  % Get the intersection of the actual ingredients with the specified ingredients
                             ActualIngredients = Intersect.                            % Check that they're equal

                          % Print a list
                          print_list([]).
                          print_list([H|T]) :- print(H), print_list(T).

                          :- print_list(canBeMade(_, stock)).


                          Last modified: 28mins after originally posted --

                          We are certainly uncertain at least I'm pretty sure I am...

                          R S 2 Replies Last reply
                          0
                          • M Michael Bergman

                            Rama Krishna Vavilala wrote:

                            Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Pina Colada -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 17:58 Friday 11th May, 2007

                            Given that there isn't any Coconut Juice or Pinapple Juice in stock, did you want an algorithm with a bug which adds them in (and removes the Beer, 151 Rum, and Amaretto)? Just curious.

                            m.bergman

                            -- For Bruce Schneier, quanta only have one state : afraid.

                            P Offline
                            P Offline
                            PIEBALDconsult
                            wrote on last edited by
                            #14

                            It should instruct the robot to go to the store.

                            1 Reply Last reply
                            0
                            • R Rama Krishna Vavilala

                              Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

                              C Offline
                              C Offline
                              Chris Meech
                              wrote on last edited by
                              #15

                              I started coding in C++ and drinking at the same time. This is not going to be pretty. :)

                              Chris Meech I am Canadian. [heard in a local bar]

                              1 Reply Last reply
                              0
                              • R Rama Krishna Vavilala

                                Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #16

                                Hmmm... now that I think of it, I think my Set class could be useful here. If the set R (recipe) is a subset of the set I (available ingredients) then we can make that drink. -- modified at 21:52 Friday 11th May, 2007

                                namespace Template
                                {
                                public partial class
                                Template
                                {
                                private static PIEBALD.Types.Set<string> I = new PIEBALD.Types.Set<string>
                                (
                                "Vodka"
                                ,
                                "Rum"
                                ,
                                "151 Rum"
                                ,
                                "Beer"
                                ,
                                "Amaretto"
                                ,
                                "Kahlua"
                                ,
                                "Skim Milk"
                                ,
                                "Mint"
                                ,
                                "Sugar"
                                ) ;

                                    private static void
                                    CanMake
                                    (
                                        string                    Name
                                    ,
                                        PIEBALD.Types.Set<string> R
                                    )
                                    {
                                        System.Console.WriteLine
                                        (
                                            "You can{0} make a/n {1}"
                                        ,
                                            (R<=I)?"":"not"
                                        ,
                                            Name
                                        ) ;
                                
                                        return ;
                                    }
                                
                                    \[System.STAThreadAttribute\]
                                    public static int
                                    Main
                                    (
                                        string\[\] args
                                    )
                                    {
                                        try
                                        {
                                            I.EqualityComparer = System.StringComparer.CurrentCultureIgnoreCase ;
                                
                                            CanMake
                                            (
                                                "Anna Kournikova"
                                            ,
                                                new PIEBALD.Types.Set<string>
                                                (
                                                    "Vodka"
                                                ,
                                                    "Kahlua"
                                                ,
                                                    "Skim Milk"
                                                )
                                            ) ;
                                
                                            CanMake
                                            (
                                                "Flaming Dr Pepper"
                                            ,
                                                new PIEBALD.Types.Set<string>
                                                (
                                                    "Beer"
                                                , 
                                                    "151 Rum"
                                                ,    
                                                    "Amaretto"
                                                )
                                            ) ;
                                
                                
                                            CanMake
                                            (
                                                "Pina Colada"
                                            ,
                                                new PIEBALD.Types.Set<string>
                                                (
                                                    "Rum"
                                                ,   
                                                    "Coconut Juice"
                                                , 
                                                    "Pineapple Juice"
                                                )
                                            ) ;
                                
                                1 Reply Last reply
                                0
                                • D David Stone

                                  Here's an oddball language. Prolog. We did a similar solution involving restaurants and meals in my programming languages class a few quarters ago. Here's the adaptation for this problem. (I'm half betting/half hoping that nobody will actually plug this into a prolog interpreter...as I didn't actually check any of it. ;P This should work though.)

                                  item(Vodka).
                                  item(Rum).
                                  item(OneFiftyOneRum).
                                  item(Beer).
                                  item(Amaretto).
                                  item(Kahlua).
                                  item(SkimMilk).
                                  item(Mint).
                                  item(Sugar).
                                  item(CoconutJuice).
                                  item(PineappleJuice);
                                  item(Bourbon).

                                  drink(AnnaKournikova, [Vodka, Kahlua, SkimMilk]).
                                  drink(FlamingDrPepper, [Beer, OneFiftyOneRum, Amaretto]).
                                  drink(PinaColada, [Rum, CoconutJuice, PineappleJuice]).
                                  drink(MintJulep, [Mint, Bourbon, Sugar]).

                                  stock([Vodka, Rum, OneFiftyOneRum, Beer, Amaretto, Kahlua, SkimMilk, Mint, Sugar]).

                                  % Determines if the Drink is made with the given Ingredients
                                  canBeMade(Drink, Ingredients) :-
                                     drink(Drink, ActualIngredients),                          % Get the ingredients in the meal
                                     intersection(ActualIngredients, Ingredients, Intersect),  % Get the intersection of the actual ingredients with the specified ingredients
                                     ActualIngredients = Intersect.                            % Check that they're equal

                                  % Print a list
                                  print_list([]).
                                  print_list([H|T]) :- print(H), print_list(T).

                                  :- print_list(canBeMade(_, stock)).


                                  Last modified: 28mins after originally posted --

                                  We are certainly uncertain at least I'm pretty sure I am...

                                  R Offline
                                  R Offline
                                  Rama Krishna Vavilala
                                  wrote on last edited by
                                  #17

                                  David Stone wrote:

                                  oddball language. Prolog

                                  Hey! That's my second favorite language. (First one being Scheme).

                                  1 Reply Last reply
                                  0
                                  • R Rama Krishna Vavilala

                                    Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

                                    S Offline
                                    S Offline
                                    Shog9 0
                                    wrote on last edited by
                                    #18

                                    Here's my entry: http://www.shog9.com/drinks/drinks.html [^] (Firefox only. Kinda works in Opera, IE throws away newlines, which kinda defeats the purpose of including a parser) The code is terrible, and i freely admit it; also, it doesn't quite work the way you described it... but i like how it works, so i just kinda went with it. As a bonus, it also has the proper ingredient list for a mint julep... :rolleyes: Now, if you'll excuse me, all this coding has made me thirsty...

                                    ----

                                    i hope you are feeling sleepy for people not calling you by the same.

                                    --BarnaKol on abusive words

                                    S R S 3 Replies Last reply
                                    0
                                    • S Shog9 0

                                      Here's my entry: http://www.shog9.com/drinks/drinks.html [^] (Firefox only. Kinda works in Opera, IE throws away newlines, which kinda defeats the purpose of including a parser) The code is terrible, and i freely admit it; also, it doesn't quite work the way you described it... but i like how it works, so i just kinda went with it. As a bonus, it also has the proper ingredient list for a mint julep... :rolleyes: Now, if you'll excuse me, all this coding has made me thirsty...

                                      ----

                                      i hope you are feeling sleepy for people not calling you by the same.

                                      --BarnaKol on abusive words

                                      S Offline
                                      S Offline
                                      Sathesh Sakthivel
                                      wrote on last edited by
                                      #19

                                      Hey Shog, There is just a blank page. Seems you have coded in a drinking mood means there should be an error but nothing is there.

                                      Regards, Satips.

                                      S 1 Reply Last reply
                                      0
                                      • S Sathesh Sakthivel

                                        Hey Shog, There is just a blank page. Seems you have coded in a drinking mood means there should be an error but nothing is there.

                                        Regards, Satips.

                                        S Offline
                                        S Offline
                                        Shog9 0
                                        wrote on last edited by
                                        #20

                                        I didn't bother testing in IE... guess i'll have to give that wretched beast a look.

                                        ----

                                        i hope you are feeling sleepy for people not calling you by the same.

                                        --BarnaKol on abusive words

                                        1 Reply Last reply
                                        0
                                        • R Rama Krishna Vavilala

                                          Given: 1. A list of cocktail recipes. Each recipe consists of ingredients . 2. A list of ingredients in stock The problem: Find all the cocktails in the list of cocktails that can be made using the ingredients in stock. Let's not consider the quantities in stock and assume that they are infinite. Example: Ingredients in stock: Vodka, Rum, 151 Rum, Beer, Amaretto, Kahlua, Skim Milk, Mint, Sugar Recipes: Anna Kournikova: Vodka, Kahlua, Skim Milk Flaming Dr Pepper: Beer, 151 Rum, Amaretto Pina Colada: Rum, Coconut Juice, Pineapple Juice Mint Julep: Mint, Bourbon, Sugar The output should be: Anna Kournikova, Flaming Dr Pepper -- modified at 17:57 Friday 11th May, 2007 Use a language of your choice and Data Structures of your choice -- modified at 19:06 Friday 11th May, 2007

                                          T Offline
                                          T Offline
                                          Tomas Petricek
                                          wrote on last edited by
                                          #21

                                          Very nice quiz for functional languages :-). In F# it looks like this:

                                          let drinks = [
                                          ("Anna Kournikova", ["Vodka"; "Kahlua"; "Skim Milk"]);
                                          ("Flaming Dr Pepper", ["Beer"; "151 Rum"; "Amaretto"]);
                                          ("Pina Colada", ["Rum"; "Coconut Juice"; "Pineapple Juice"]);
                                          ("Mint Julep", ["Mint"; "Bourbon"; "Sugar"])];;
                                          let ingred =
                                          ["Vodka"; "Rum"; "151 Rum"; "Beer"; "Amaretto";
                                          "Kahlua"; "Skim Milk"; "Mint"; "Sugar"];;

                                          let ingset = Set.of_list ingred;;
                                          drinks |> List.filter (fun (_, ing) -> ing |> Seq.for_all ingset.Contains )
                                          |> List.map fst;;

                                          Homepage: TomasP.net | Photo of the month: Calendar | C# and LINQ, F#, Phalanger: My Blog
                                          Latest article: Phalanger, PHP for .NET: Introduction for .NET developers

                                          T M S 3 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups