Пример #1
0
        //14. The Japanese smokes Parliaments.

        public Boolean Valida14(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SCountry == "Japanese" && g.SSmoke != "Parliaments")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #2
0
        //10. The Norwegian lives in the first house.

        public Boolean Valida10(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.IOrder == 1 && g.SCountry != "Norwegian")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #3
0
        //13. The Lucky Strike smoker drinks orange juice.

        public Boolean Valida13(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SSmoke == "Lucky Strike" && g.SDrink != "orange juice")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #4
0
        //8. Kools are smoked in the yellow house.

        public Boolean Valida8(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SHouseColor == "yellow" && g.SSmoke != "Kools")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #5
0
        //9. Milk is drunk in the middle house.

        public Boolean Valida9(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.IOrder == 3 && g.SDrink != "Milk")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #6
0
        //5. The Ukrainian drinks tea.
        public Boolean Valida5(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SCountry == "Ukrainian" && g.SDrink != "Tea")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #7
0
        //7. The Old Gold smoker owns snails.

        public Boolean Valida7(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SSmoke == "Old Gold" && g.SAnimal != "snails")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #8
0
        //4. Coffee is drunk in the green house.
        public Boolean Valida4(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SHouseColor == "Green" && g.SDrink != "Coffee")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #9
0
        //3. The Spaniard owns the dog.
        public Boolean Valida3(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SCountry == "Spaniard" && g.SAnimal != "Dog")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #10
0
        //2. The Englishman lives in the red house.
        public Boolean Valida2(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                if (g.SCountry == "Englishman" && g.SHouseColor != "Red")
                {
                    retorno = false;
                }
            }
            return(retorno);
        }
Пример #11
0
        /// <summary>
        /// Gimes the countries.
        /// </summary>
        public void gimecountrys(string[] countrys)
        {
            if (tesSol)
            {
                return;
            }
            for (int k = 0; (ulong)k < StringPerm.FactorialLookup(4); ++k)
            {
                StringPerm p = new StringPerm(countrys, k);
                country1 = p.element[0].ToString();
                country2 = p.element[1].ToString();
                country3 = p.element[2].ToString();
                country4 = p.element[3].ToString();



                Guy[] vizinhosArray = new Guy[5] {
                    new Guy("yellow", animal1, "Kools", 1, drink1, "Norwegian"),
                    new Guy("blue", "horse", smoke11, 2, drink2, country1),
                    new Guy(color1, animal2, smoke12, 3, "Milk", country2),
                    new Guy(color2, animal3, smoke13, 4, drink3, country3),
                    new Guy(color3, animal4, smoke14, 5, drink4, country4),
                };
                Vizinhos vizinhoslist = new Vizinhos(vizinhosArray);
                bool     val          = vizinhoslist.Valida();
                if (val == true)
                {
                    tesSol      = true;
                    Solucao[0]  = color1;
                    Solucao[1]  = color2;
                    Solucao[2]  = color3;
                    Solucao[3]  = animal1;
                    Solucao[4]  = animal2;
                    Solucao[5]  = animal3;
                    Solucao[6]  = animal4;
                    Solucao[7]  = smoke11;
                    Solucao[8]  = smoke12;
                    Solucao[9]  = smoke13;
                    Solucao[10] = smoke14;
                    Solucao[11] = drink1;
                    Solucao[12] = drink2;
                    Solucao[13] = drink3;
                    Solucao[14] = drink4;
                    Solucao[15] = country1;
                    Solucao[16] = country2;
                    Solucao[17] = country3;
                    Solucao[18] = country4;
                }
            }
        }
Пример #12
0
        //12. Kools are smoked in the house next to the house where the horse is kept.

        public Boolean Valida12(Vizinhos e)
        {
            Boolean retorno = false;

            foreach (Guy g in e)
            {
                foreach (Guy g1 in e)
                {
                    if (g.SAnimal == "horse" && (g.IOrder - g1.IOrder == 1 || g.IOrder - g1.IOrder == -1))
                    {
                        if (g1.SSmoke == "Kools")
                        {
                            retorno = true;
                        }
                    }
                }
            }
            return(retorno);
        }
Пример #13
0
        //11. The man who smokes Chesterfields lives in the house next to the man with the fox.

        public Boolean Valida11(Vizinhos e)
        {
            Boolean retorno = false;

            foreach (Guy g in e)
            {
                foreach (Guy g1 in e)
                {
                    if (g.SSmoke == "Chesterfield" && (g.IOrder - g1.IOrder == 1 || g.IOrder - g1.IOrder == -1))
                    {
                        if (g1.SAnimal == "fox")
                        {
                            retorno = true;
                        }
                    }
                }
            }
            return(retorno);
        }
Пример #14
0
        //6. The green house is immediately to the right of the ivory house.
        public Boolean Valida6(Vizinhos e)
        {
            Boolean retorno = true;

            foreach (Guy g in e)
            {
                foreach (Guy g1 in e)
                {
                    if (g.SHouseColor == "Green" && g1.SHouseColor == "ivory")
                    {
                        if (g.IOrder != g1.IOrder - 1)
                        {
                            retorno = false;
                        }
                    }
                }
            }
            return(retorno);
        }
Пример #15
0
        //15. The Norwegian lives next to the blue house.

        public Boolean Valida15(Vizinhos e)
        {
            Boolean retorno = false;

            foreach (Guy g in e)
            {
                foreach (Guy g1 in e)
                {
                    if (g.SCountry == "Norwegian" && (g.IOrder - g1.IOrder == 1 || g.IOrder - g1.IOrder == -1))
                    {
                        if (g1.SHouseColor == "blue")
                        {
                            retorno = true;
                        }
                    }
                }
            }
            return(retorno);
        }
Пример #16
0
        //6. The green house is immediately to the right of the ivory house.
        public Boolean Valida6(Vizinhos e)
        {
            Boolean retorno = true;
            foreach (Guy g in e)
            {
                foreach (Guy g1 in e)
                {
                    if (g.SHouseColor =="Green" && g1.SHouseColor =="ivory")
                    {

                        if (g.IOrder != g1.IOrder-1)
                        {
                            retorno = false;
                        }
                    }
                }
            }
            return retorno;
        }
Пример #17
0
 //7. O fumador de Marlboro tem uma snails The Old Gold smoker owns snails.
 public Boolean Valida7(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SSmoke =="Old Gold"  && g.SAnimal  !="snails")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #18
0
 //4. Coffee is drunk in the green house.
 public Boolean Valida4(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SHouseColor =="Green"  && g.SDrink  !="Coffee")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #19
0
 //5. The Ukrainian drinks tea.
 public Boolean Valida5(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SCountry =="Ukrainian"  && g.SDrink  !="Tea")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #20
0
 //2. The Englishman lives in the red house.
 public Boolean Valida2(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SCountry=="Englishman" && g.SHouseColor !="Red")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #21
0
 //3. The Spaniard owns the dog.
 public Boolean Valida3(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SCountry=="Spaniard" && g.SAnimal !="Dog")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #22
0
 //14. The Japanese smokes Parliaments.
 public Boolean Valida14(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SCountry =="Japanese"  && g.SSmoke   !="Parliaments")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #23
0
 //15. The Norwegian lives next to the blue house.
 public Boolean Valida15(Vizinhos e)
 {
     Boolean retorno = false;
     foreach (Guy g in e)
     {
         foreach (Guy g1 in e)
         {
             if  ( g.SCountry  =="Norwegian" && ( g.IOrder -g1.IOrder ==1  ||  g.IOrder -g1.IOrder == -1 ))
             {
                 if (g1.SHouseColor == "blue")
                 {
                     retorno = true;
                 }
             }
         }
     }
     return retorno;
 }
Пример #24
0
 //13. The Lucky Strike smoker drinks orange juice.
 public Boolean Valida13(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SSmoke =="Lucky Strike"  && g.SDrink   !="orange juice")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #25
0
 //12. Kools are smoked in the house next to the house where the horse is kept.
 public Boolean Valida12(Vizinhos e)
 {
     Boolean retorno = false;
     foreach (Guy g in e)
     {
         foreach (Guy g1 in e)
         {
             if  ( g.SAnimal  =="horse" && ( g.IOrder -g1.IOrder ==1  ||  g.IOrder -g1.IOrder == -1 ))
             {
                 if (g1.SSmoke == "Kools")
                 {
                     retorno = true;
                 }
             }
         }
     }
     return retorno;
 }
Пример #26
0
 //11. The man who smokes Chesterfields lives in the house next to the man with the fox.
 public Boolean Valida11(Vizinhos e)
 {
     Boolean retorno = false;
     foreach (Guy g in e)
     {
         foreach (Guy g1 in e)
         {
             if  ( g.SSmoke=="Chesterfield" && ( g.IOrder -g1.IOrder ==1  ||  g.IOrder -g1.IOrder == -1 ))
             {
                 if (g1.SAnimal == "fox")
                 {
                     retorno = true;
                 }
             }
         }
     }
     return retorno;
 }
Пример #27
0
 //10. The Norwegian lives in the first house.
 public Boolean Valida10(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.IOrder ==1  && g.SCountry   !="Norwegian")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #28
0
 //8. Kools are smoked in the yellow house.
 public Boolean Valida8(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.SHouseColor =="yellow"  && g.SSmoke  !="Kools")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #29
0
 //9. Milk is drunk in the middle house.
 public Boolean Valida9(Vizinhos e)
 {
     Boolean retorno = true;
     foreach (Guy g in e)
     {
         if (g.IOrder ==3  && g.SDrink  !="Milk")
         {
             retorno = false;
         }
     }
     return retorno;
 }
Пример #30
0
        /// <summary>
        /// Gimes the countries.
        /// </summary>
        public void gimecountrys(string[] countrys)
        {
            if (tesSol) return;
            for (int k = 0; (ulong)k < StringPerm.FactorialLookup(4); ++k) {
                StringPerm p = new StringPerm (countrys, k);
                country1 = p.element [0].ToString ();
                country2 = p.element [1].ToString ();
                country3 = p.element [2].ToString ();
                country4 = p.element [3].ToString ();

                Guy[] vizinhosArray = new Guy[5] {
                    new Guy ("yellow", animal1, "Kools", 1, drink1, "Norwegian"),
                    new Guy ("blue", "horse", smoke11, 2, drink2, country1),
                    new Guy (color1, animal2, smoke12, 3, "Milk", country2),
                    new Guy (color2, animal3, smoke13, 4, drink3, country3),
                    new Guy (color3, animal4, smoke14, 5, drink4, country4),

                };
                Vizinhos vizinhoslist= new Vizinhos(vizinhosArray);
                bool val = vizinhoslist.Valida();
                if (val==true)
                {
                    tesSol = true;
                    Solucao[0] =color1;
                    Solucao[1] =color2;
                    Solucao[2] =color3;
                    Solucao[3] =animal1;
                    Solucao[4] =animal2;
                    Solucao[5] =animal3;
                    Solucao[6] =animal4;
                    Solucao[7] =smoke11;
                    Solucao[8] =smoke12;
                    Solucao[9] =smoke13;
                    Solucao[10] =smoke14;
                    Solucao[11] =drink1;
                    Solucao[12] =drink2;
                    Solucao[13] =drink3;
                    Solucao[14] =drink4;
                    Solucao[15] =country1;
                    Solucao[16] =country2;
                    Solucao[17] =country3;
                    Solucao[18] =country4;

                }

            }
        }