コード例 #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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
        //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
 //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
ファイル: Guy.cs プロジェクト: ruinalmeida/Zebra
        /// <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;

                }

            }
        }