{"action":"closed","issue":{"url":"https://api.github.com/repos/matheussatel2015/teste/issues/1","labels_url":"https://api.github.com/repos/matheussatel2015/teste/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/matheussatel2015/teste/issues/1/comments","events_url":"https://api.github.com/repos/matheussatel2015/teste/issues/1/events","html_url":"https://github.com/matheussatel2015/teste/issues/1","id":76801882,"number":1,"title":"teste","user":{"login":"matheussatel2015","id":12464115,"avatar_url":"https://avatars.githubusercontent.com/u/12464115?v=3","gravatar_id":"","url":"https://api.github.com/users/matheussatel2015","html_url":"https://github.com/matheussatel2015","followers_url":"https://api.github.com/users/matheussatel2015/followers","following_url":"https://api.github.com/users/matheussatel2015/following{/other_user}","gists_url":"https://api.github.com/users/matheussatel2015/gists{/gist_id}","starred_url":"https://api.github.com/users/matheussatel2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matheussatel2015/subscriptions","organizations_url":"https://api.github.com/users/matheussatel2015/orgs","repos_url":"https://api.github.com/users/matheussatel2015/repos","events_url":"https://api.github.com/users/matheussatel2015/events{/privacy}","received_events_url":"https://api.github.com/users/matheussatel2015/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-15T17:49:02Z","updated_at":"2015-05-15T17:49:12Z","closed_at":"2015-05-15T17:49:12Z","body":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\n\r\nnamespace Cruzada\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            CRUZADA cruzada = new CRUZADA();\r\n            Console.Read();\r\n\r\n            //chaves.Add(new Chave().Add(\"x1 x2 x3\"));\r\n            //chaves.Add(new Chave().Add(\"x6 x7 x8\"));\r\n            //chaves.Add(new Chave().Add(\"x10 x11 x12\"));\r\n            //chaves.Add(new Chave().Add(\"x1 x5 x9\"));\r\n            //chaves.Add(new Chave().Add(\"x3 x6 x10\"));\r\n            //chaves.Add(new Chave().Add(\"x7 x11 x13\"));\r\n            //chaves.Add(new Chave().Add(\"x4 x8 x12\"));\r\n\r\n\r\n            //palavras[0].printToArray();\r\n            //palavras[1].printToArray();\r\n\r\n            //chaves[0].printToArray();\r\n           // chaves[1].printToArray();\r\n\r\n            /*\r\n            \r\n\r\n            for (int i = 0; i < chaves.Count; i++)\r\n            {\r\n                var _obj_chave = chaves[i];\r\n\r\n                var _palavras_ = palavras.FindAll(p => p.getSize() == _obj_chave.getSize() && p.isUsed == false);\r\n\r\n                if (dic.Count == 0)\r\n                {\r\n                    Random rnd = new Random(Guid.NewGuid().GetHashCode());\r\n                    var _obj_palavra_ = _palavras_[rnd.Next(0, _palavras_.Count)];\r\n\r\n                    _obj_palavra_.setUsed(true);\r\n\r\n                    _obj_chave.PALAVRA = _obj_palavra_.str_palavra;\r\n\r\n                    var dic_include = Dicionario.setDicionario(_obj_chave.getVetor(), _obj_palavra_.getVetor());\r\n\r\n                    if (dic_include != null)\r\n                        dic.AddRange(dic_include);\r\n\r\n                }\r\n                else\r\n                {\r\n                    List<Dicionario> dic_tmp = new List<Dicionario>();\r\n                    for (int c = 0; c < _obj_chave.getSize(); c++)\r\n                    {\r\n                        var d = dic.Find(b => b.key == _obj_chave.getVetor()[c].ToString());\r\n                        if (d != null)\r\n                            dic_tmp.Add(d);\r\n                    }\r\n\r\n                    Console.WriteLine(\"\");\r\n\r\n                    for (int f = 0; f < dic_tmp.Count; f++)\r\n                    {\r\n                        Console.WriteLine(\"ACHEI \" + dic_tmp[f].Dic_String());\r\n                    }\r\n\r\n                    if (dic_tmp.Count > 0)\r\n                    {\r\n                        Console.WriteLine(_obj_chave.STRING());\r\n                        List<Palavra> ppp = _palavras_;\r\n                        for (int ic = 0; ic < dic_tmp.Count; ic++)\r\n                        {\r\n                            int index = _obj_chave.IndexByKey(dic_tmp[ic].key);\r\n                            ppp = ppp.FindAll(a => a.FindByIndexKey(index, dic_tmp[ic].palavra) == true);\r\n                        }\r\n\r\n                        if (ppp.Count > 0)\r\n                        {\r\n                            Random rnd = new Random(Guid.NewGuid().GetHashCode());\r\n                            var _obj_palavra_ppp_ = ppp[rnd.Next(0, ppp.Count)];\r\n\r\n                            _obj_palavra_ppp_.setUsed(true);\r\n\r\n                            _obj_chave.PALAVRA = _obj_palavra_ppp_.str_palavra;\r\n\r\n                            Console.WriteLine(\"\");\r\n\r\n                            for (int f = 0; f < ppp.Count; f++)\r\n                            {\r\n                                Console.WriteLine(\"ACHEI \" + ppp[f].str_palavra);\r\n                            }\r\n                        }\r\n                        else\r\n                        {\r\n                            Console.WriteLine(\"Nao existe palavras no diretorio\");\r\n                        }\r\n                    }\r\n                    else\r\n                    {\r\n                        var _palavras_1 = palavras.FindAll(p => p.getSize() == _obj_chave.getSize() && p.isUsed == false);\r\n\r\n                        Random rnd = new Random(Guid.NewGuid().GetHashCode());\r\n                        var _obj_palavra_ = _palavras_1[rnd.Next(0, _palavras_1.Count)];\r\n\r\n                        _obj_palavra_.setUsed(true);\r\n\r\n                        _obj_chave.PALAVRA = _obj_palavra_.str_palavra;\r\n\r\n                        var dic_include = Dicionario.setDicionario(_obj_chave.getVetor(), _obj_palavra_.getVetor());\r\n\r\n                        if (dic_include != null)\r\n                            dic.AddRange(dic_include);\r\n                    }                    \r\n                }\r\n\r\n            }\r\n\r\n            Console.WriteLine(\"\");\r\n\r\n            for (int i = 0; i < chaves.Count; i++)\r\n            {\r\n                Console.WriteLine(chaves[i].CHAVEPALAVRA());\r\n            }*/\r\n\r\n             \r\n            \r\n        }\r\n\r\n        \r\n\r\n    }\r\n\r\n    public class CRUZADA \r\n    {\r\n        List<Dicionario> dic = new List<Dicionario>();\r\n        List<Palavra> palavras = new List<Palavra>();\r\n        List<Chave> chaves = new List<Chave>();\r\n\r\n        public CRUZADA()\r\n        {\r\n\r\n            String ppppp = \"aco,age,ali,alo,ama,ame,amo,ana,ano,aos,asa,ata,ate,ato,ave,avo,axe,bar,bau,bem,bip,bis,bit,boa,boi,bom,bus,cai,cal,cao,cem,ceu,cha,com,cor,cru,dai,dao,dar,das,dei,der,des,deu,dia,diz,doa,doi,dom,dor,dos,dou,dum,duo,eco,ego,eis,ela,ele,era,faz,fez,fim,fio,fiz,foi,for,foz,fui,gas,gel,gim,giz,gnu,goi,gol,hep,hum,ida,ipe,ifa,ira,jus,kit,lar,lei,ler,les,leu,lhe,lia,lua,luz,mae,mai,mal,mao,mar,mas,mau,mel,mes,meu,mil,mim,nao,nas,nau,nem,nha,nos,noz,nua,num,nus,oba,ode,ohm,ola,ole,opa,ora,ova,ovo,pai,pao,par,pas,pau,paz,pes,pez,pia,poe,por,pos,psi,pus,que,qui,rei,rem,reu,ria,rim,rio,rir,ris,riu,roa,roi,rol,rua,rui,rum,sai,sal,sao,sei,sem,ser,set,seu,sim,soa,sob,sol,som,spa,sua,sue,sul,tal,tao,tau,tem,ter,teu,tia,til,tio,toa,tom,tua,uai,ufa,uma,una,une,uni,uno,usa,use,uso,uva,vai,val,vao,var,vem,ver,ves,vez,via,vil,vim,vir,viu,voa,voo,vos,vou,voz,zen\";\r\n            var plist = ppppp.Split(',');\r\n\r\n            for (int i = 0; i < plist.Length; i++)\r\n            {\r\n                palavras.Add(new Palavra().Add(plist[i]));\r\n            }\r\n\r\n            //Exe 1\r\n            //chaves.Add(new Chave().Add(\"x1 x2 x3\"));\r\n\r\n            //Exe 2\r\n            //chaves.Add(new Chave().Add(\"x1 x2 x3\"));\r\n            //chaves.Add(new Chave().Add(\"x4 x2 x5\"));\r\n\r\n            //Exe 3\r\n            /*\r\n            chaves.Add(new Chave().Add(\"x1 x2 x3\"));\r\n            chaves.Add(new Chave().Add(\"x4 x5 x6\"));\r\n            chaves.Add(new Chave().Add(\"x7 x8 x9\"));\r\n            chaves.Add(new Chave().Add(\"x1 x4 x7\"));\r\n            chaves.Add(new Chave().Add(\"x2 x5 x8\"));\r\n            chaves.Add(new Chave().Add(\"x3 x6 x9\"));*/\r\n\r\n            //4\r\n            //chaves.Add(new Chave().Add(\"x2 x3 x4\"));\r\n            //chaves.Add(new Chave().Add(\"x5 x6 x7\"));\r\n            //chaves.Add(new Chave().Add(\"x2 x6 x8\"));\r\n            //chaves.Add(new Chave().Add(\"x1 x3 x7\"));\r\n            \r\n            //5\r\n            chaves.Add(new Chave().Add(\"x1 x2 x3\"));\r\n            chaves.Add(new Chave().Add(\"x6 x7 x8\"));\r\n            chaves.Add(new Chave().Add(\"x10 x11 x12\"));\r\n            chaves.Add(new Chave().Add(\"x1 x5 x9\"));\r\n            chaves.Add(new Chave().Add(\"x3 x6 x10\"));\r\n            chaves.Add(new Chave().Add(\"x7 x11 x13\"));\r\n            chaves.Add(new Chave().Add(\"x4 x8 x12\"));\r\n            \r\n\r\n\r\n            //for (int i = 0; i < chaves.Count; i++)\r\n            bool achei = true;\r\n            while(achei)\r\n            {\r\n                FIND(chaves[0]);\r\n\r\n                Console.WriteLine(\"\");\r\n                for (int c = 0; c < chaves.Count; c++)\r\n                {\r\n                    Console.WriteLine(\"ID \" + c.ToString() + \" \" + chaves[c].PALAVRA);\r\n                }\r\n\r\n                var aaa = chaves.Find(a => a.PALAVRA.Equals(\"\"));\r\n                if (aaa == null)\r\n                {\r\n                    achei = false;\r\n                    Console.WriteLine(achei.ToString());\r\n                }\r\n                else\r\n                {\r\n\r\n                    Console.WriteLine(achei.ToString());\r\n                    dic.Clear();\r\n\r\n                    for (int i = 0; i < palavras.Count; i++)\r\n                    {\r\n                        palavras[i].isUsed = false;\r\n                    }\r\n                    for (int c = 0; c < chaves.Count; c++)\r\n                    {\r\n                        chaves[c].PALAVRA = \"\";\r\n                        chaves[c].isUsed = false;\r\n                    }\r\n\r\n                    Console.WriteLine(\"\");\r\n                    for (int c = 0; c < chaves.Count; c++)\r\n                    {\r\n                        Console.WriteLine(\"ID \" + c.ToString() + \" \" + chaves[c].PALAVRA);\r\n                    }\r\n\r\n                    Console.WriteLine(\"RESET\");\r\n                }\r\n\r\n            }\r\n\r\n            Console.WriteLine(\"\");\r\n            for (int c = 0; c < chaves.Count; c++)\r\n            {\r\n                Console.WriteLine(chaves[c].PALAVRA);\r\n            }\r\n        }\r\n\r\n        public Chave FIND(Chave chave)\r\n        {\r\n            if (chave == null)\r\n                return null;\r\n            if (chave.isUsed)\r\n                return null;\r\n\r\n            //Console.WriteLine(\"\");\r\n            //for (int c = 0; c < chaves.Count; c++)\r\n            //{\r\n            //    Console.WriteLine(chaves[c].PALAVRA);\r\n            //}\r\n\r\n\r\n            List<Dicionario> dic_tmp = new List<Dicionario>();\r\n            for (int c = 0; c < chave.getSize(); c++)\r\n            {\r\n                var d = dic.Find(b => b.key == chave.getVetor()[c].ToString());\r\n                if (d != null)\r\n                    dic_tmp.Add(d);\r\n            }\r\n\r\n            if (dic_tmp.Count == 0)\r\n            {\r\n                var _palavras_ = palavras.FindAll(p => p.getSize() == chave.getSize() && p.isUsed == false);\r\n\r\n                if (dic.Count == 0)\r\n                {\r\n                    Random rnd = new Random(Guid.NewGuid().GetHashCode());\r\n                    var _obj_palavra_ = _palavras_[rnd.Next(0, _palavras_.Count)];\r\n                    _obj_palavra_.setUsed(true);\r\n                    chave.PALAVRA = _obj_palavra_.str_palavra;\r\n                    chave.isUsed = true;\r\n                    var dic_include = Dicionario.setDicionario(chave.getVetor(), _obj_palavra_.getVetor());\r\n\r\n                    if (dic_include != null)\r\n                        dic.AddRange(dic_include);\r\n                }\r\n            }\r\n            else\r\n            {             \r\n                //for (int f = 0; f < dic_tmp.Count; f++)\r\n                //{\r\n                    //Console.WriteLine(\"ACHEI \" + dic_tmp[f].Dic_String());\r\n               // }\r\n\r\n                if (dic_tmp.Count > 0)\r\n                {\r\n                    //Console.WriteLine(chave.STRING());\r\n                    List<Palavra> ppp = palavras.FindAll(p => p.getSize() == chave.getSize() && p.isUsed == false);\r\n                    for (int ic = 0; ic < dic_tmp.Count; ic++)\r\n                    {\r\n                        int index = chave.IndexByKey(dic_tmp[ic].key);\r\n                        ppp = ppp.FindAll(a => a.FindByIndexKey(index, dic_tmp[ic].palavra) == true);\r\n                    }\r\n\r\n                    if (ppp.Count > 0)\r\n                    {\r\n                        Random rnd = new Random(Guid.NewGuid().GetHashCode());\r\n                        var _obj_palavra_ppp_ = ppp[rnd.Next(0, ppp.Count)];\r\n\r\n                        _obj_palavra_ppp_.setUsed(true);\r\n\r\n                        chave.PALAVRA = _obj_palavra_ppp_.str_palavra;\r\n                        chave.isUsed = true;\r\n\r\n                        var dic_include = Dicionario.setDicionario(chave.getVetor(), _obj_palavra_ppp_.getVetor());\r\n\r\n                        if (dic_include != null)\r\n                            dic.AddRange(dic_include);\r\n                    }\r\n                    else\r\n                    {\r\n                        //Console.WriteLine(\"Nao existe palavras no diretorio\");\r\n                        return null;\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    var _palavras_1 = palavras.FindAll(p => p.getSize() == chave.getSize() && p.isUsed == false);\r\n\r\n                    Random rnd = new Random(Guid.NewGuid().GetHashCode());\r\n                    var _obj_palavra_ = _palavras_1[rnd.Next(0, _palavras_1.Count)];\r\n\r\n                    _obj_palavra_.setUsed(true);\r\n\r\n                    chave.PALAVRA = _obj_palavra_.str_palavra;\r\n\r\n                    var dic_include = Dicionario.setDicionario(chave.getVetor(), _obj_palavra_.getVetor());\r\n\r\n                    if (dic_include != null)\r\n                        dic.AddRange(dic_include);\r\n                }                    \r\n            }\r\n\r\n            for (int i = 0; i < chave.vct_key.Length; i++)\r\n            {\r\n                for (int ichaves = 0; ichaves < chaves.Count; ichaves++)\r\n                {\r\n                    if (!chaves[ichaves].isUsed)\r\n                    {\r\n                        for (int c = 0; c < chaves[ichaves].vct_key.Length; c++)\r\n                        {\r\n                            if (chaves[ichaves].vct_key[c].Equals(chave.vct_key[i]))\r\n                            {\r\n                                FIND(chaves[ichaves]);\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n\r\n            return null;\r\n        }\r\n    }\r\n\r\n    public class Dicionario\r\n    {\r\n        public string key = \"\";\r\n        public string palavra = \"\";\r\n\r\n        public void setChave(string k, string p) {\r\n\r\n            key = k;\r\n            palavra = p;\r\n        }\r\n\r\n        public static List<Dicionario> setDicionario(String[] chave, char[] palavra)\r\n        {\r\n            List<Dicionario> dic = new List<Dicionario>();\r\n            for (int i = 0; i < chave.Length; i++)\r\n            {\r\n                var d = new Dicionario();\r\n                d.setChave(chave[i].ToString(), palavra[i].ToString());\r\n                dic.Add(d);\r\n            }\r\n\r\n            if (dic.Count > 0)\r\n                return dic;\r\n            else\r\n                return null;\r\n        }\r\n\r\n        public string Dic_String()\r\n        {\r\n            return key + \" \" + palavra;\r\n        }\r\n    }\r\n\r\n    public class Chave\r\n    {\r\n        string str_key;\r\n        public String[] vct_key;\r\n        int siz_key = 0;\r\n        public string PALAVRA = \"\";\r\n        public bool isUsed = false;\r\n\r\n        public Chave Add(string p)\r\n        {\r\n            this.str_key = p;\r\n            this.vct_key = p.Split(' ');\r\n            this.siz_key = this.vct_key.Length;\r\n            return this;\r\n        }\r\n\r\n        public String[] getVetor()\r\n        {\r\n            return vct_key;\r\n        }\r\n\r\n        public void printToArray()\r\n        {\r\n            for (int i = 0; i < vct_key.Length; i++)\r\n            {\r\n                Console.Write(vct_key[i]);\r\n            }\r\n        }\r\n\r\n        public int getSize() {\r\n            return siz_key;\r\n        }\r\n\r\n        public string getKey()\r\n        {\r\n            return \"\";\r\n        }\r\n\r\n        public int IndexByKey(string k)\r\n        {\r\n            for (int i = 0; i < vct_key.Length; i++)\r\n\t\t\t{\r\n                if( vct_key[i].Equals(k) )\r\n                    return i;\t\t\t \r\n\t\t\t}\r\n            return -1;\r\n        }\r\n\r\n        public string STRING()\r\n        {\r\n            return str_key;\r\n        }\r\n\r\n        public string CHAVEPALAVRA()\r\n        {\r\n            return str_key + \" \" + PALAVRA;\r\n        }\r\n    }\r\n\r\n    public class Palavra\r\n    {\r\n        public string str_palavra;\r\n        char[] vct_palavra;\r\n        int siz_palavra = 0;\r\n        public bool isUsed = false;\r\n\r\n        public Palavra Add(string p)\r\n        {\r\n            this.str_palavra = p;\r\n            this.vct_palavra = p.ToCharArray();\r\n            this.siz_palavra = this.vct_palavra.Length;\r\n            this.isUsed = false;\r\n            return this;\r\n        }\r\n\r\n        public bool FindByIndexKey(int index, string p)\r\n        {\r\n            var c = vct_palavra[index];\r\n            if (c.ToString().Equals(p))\r\n            {\r\n                return true;\r\n            }\r\n            return false;\r\n        }\r\n\r\n        public void setUsed(bool isused)\r\n        {\r\n            //this.isUsed = isused;\r\n        }\r\n\r\n        public char[] getVetor()\r\n        {\r\n            return vct_palavra;\r\n        }\r\n\r\n        public void printToArray() {\r\n            for (int i = 0; i < vct_palavra.Length; i++)\r\n            {\r\n                Console.Write(vct_palavra[i]);\r\n            }\r\n        }\r\n\r\n        public int getSize()\r\n        {\r\n            return siz_palavra;\r\n        }\r\n    }\r\n}\r\n"}}