C++ 11 to C# code Conversion issue -


i trying convert following c++11 code c# using visual studio 2012:

typedef enum { _a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l,_m,_n,_o,_1,_2,_3 }  tkeyidentity; typedef std::vector<tkeyidentity const>     tkeypath; typedef std::vector<tkeypath const>         tkeymap;  const tkeymap keypad = {     { _h, _l },         //     { _i, _k, _m },     // b     { _f, _j, _l, _n }, // c     { _g, _m, _o },     // d      { _h, _n }         // e   }  const tkeypath keypadroot = {     _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _1, _2, _3 };  traversekeypaths( tkeypath const &keypath, int pressesremaining, int vowelsallowed ) {     ( auto pressedkey: keypath )     {           int value = traversekeypaths(keypad[ pressedkey ],pressesremaining, vowelsallowed - isvowel[pressedkey] );         } } 

the complete c++ code available :http://lucid-motif.blogspot.com/2013/11/coding-puzzle-knight-sequences.html

c# code:

enum tkeyidentity { _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _1, _2, _3 }; list<string> keypadroot = new list<string> { "_a", "_b", "_c", "_d", "_e", "_f", "_g", "_h", "_i", "_j", "_k", "_l", "_m", "_n", "_o", "_1", "_2", "_3" };  string[] = new string[] { "_h", "_l" }; //a string[] b = new string[] { "_i", "_k", "_m" }; //b string[] c = new string[] { "_f", "_j", "_l", "_n" }; //c string[] d = new string[] { "_g", "_m", "_o" }; //d  list<string> keypadmoves = new list<string>(); keypadmoves.addrange(a); keypadmoves.addrange(b); keypadmoves.addrange(c); keypadmoves.addrange(d); . .  int traversekeypaths(list<string> keypadroot, int pressesremaining, int vowelsallowed) {    foreach (tkeyidentity pressedkey in enum.getvalues(typeof(tkeyidentity)))    {       int value = traversekeypaths(keypadroot, pressesremaining, vowelsallowed);    }  } 

the c# code not working expected. issue below line:

 traversekeypaths(keypadroot, pressesremaining, vowelsallowed); 

i need pass first parameter keypadmoves; if pass keypadmoves, recursive call goes infinite loop.

you have kinds of code in attempted c# equivalent don't seem correspond original c++ code. here direct compilable translation, assuming have 'isvowel' defined somewhere:

using system.collections.generic;  public enum tkeyidentity {     _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _1, _2, _3 }  public class traversekeypaths {     public readonly list<list<tkeyidentity>> keypad = new list<list<tkeyidentity>>()     {         new list<tkeyidentity> {tkeyidentity._h, tkeyidentity._l},         new list<tkeyidentity> {tkeyidentity._i, tkeyidentity._k, tkeyidentity._m},         new list<tkeyidentity> {tkeyidentity._f, tkeyidentity._j, tkeyidentity._l, tkeyidentity._n},         new list<tkeyidentity> {tkeyidentity._g, tkeyidentity._m, tkeyidentity._o},         new list<tkeyidentity> {tkeyidentity._h, tkeyidentity._n}     };      public readonly list<tkeyidentity> keypadroot = new list<tkeyidentity>() { tkeyidentity._a, tkeyidentity._b, tkeyidentity._c, tkeyidentity._d, tkeyidentity._e, tkeyidentity._f, tkeyidentity._g, tkeyidentity._h, tkeyidentity._i, tkeyidentity._j, tkeyidentity._k, tkeyidentity._l, tkeyidentity._m, tkeyidentity._n, tkeyidentity._o, tkeyidentity._1, tkeyidentity._2, tkeyidentity._3 };      public traversekeypaths(list<tkeyidentity> keypath, int pressesremaining, int vowelsallowed)     {         foreach (var pressedkey in keypath)         {             int value = new traversekeypaths(keypad[(int)pressedkey], pressesremaining, vowelsallowed - isvowel[pressedkey]);         }     } } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -