GoDoG23

Members
  • Content count

    33
  • Joined

  • Last visited

Community Reputation

139 Neutral

About GoDoG23

  • Rank
    Member
  1. Quote:Original post by Extrarius Quote:Original post by GoDoG23 [...]If you assume unsigned char is a byte you could simply precalculate a table. If don't want to store a 256 byte table you could try somehting like that: *** Source Snippet Removed ***A char is, by definition, of size 1. However, CHAR_BITS may not be 8, and the range may not be 0..255. Also, there isn't an need to add 8 times since you can simply use shifts, and for e you can use a mask. Finally, your look-up table method access memory several in a complicated way, which is slow and will push other data out of the cache. You are right. I forgot about sizeof(char) and CHAR_BIT thing. The algorithm was written without too much thinking. STATIC_ASSERT(CHAR_BIT == 8); ... unsigned char i_div_8 = i >> 3; unsigned char e = i - (i_div_8 << 3); unsigned char a = v[i_div_8]; unsigned char b = v[e]; unsigned char ra = r[i_div_8]; unsigned char rb = r[e]; return (a << 3) + b + v[(ra << 3) + rb];
  2. Quote:Original post by Extrarius Quote:Original post by lougv22 ... The answer is no, because unsigned char is an integral type of undefined size according to the standard. Even if they tell you to assume that an unsigned char is an 8-bit bit integer with the range 0..255, my solution is comparable to a binary branch tree once optimized. ... If you assume unsigned char is a byte you could simply precalculate a table. If don't want to store a 256 byte table you could try somehting like that: #define STATIC_ASSERT(exp) static const int static_assert[(exp)] template <unsigned char i> struct Div7 { enum { Result = typename Div7<i-7>::Result + 1 }; enum { Remainder = typename Div7<i-7>::Remainder }; }; template <> struct Div7<6> { enum { Result = 0 }; enum { Remainder = 6 }; }; template <> struct Div7<5> { enum { Result = 0 }; enum { Remainder = 5 }; }; template <> struct Div7<4> { enum { Result = 0 }; enum { Remainder = 4 }; }; template <> struct Div7<3> { enum { Result = 0 }; enum { Remainder = 3 }; }; template <> struct Div7<2> { enum { Result = 0 }; enum { Remainder = 2 }; }; template <> struct Div7<1> { enum { Result = 0 }; enum { Remainder = 1 }; }; template <> struct Div7<0> { enum { Result = 0 }; enum { Remainder = 0 }; }; unsigned char div7(unsigned char i) { STATIC_ASSERT(sizeof(char) == 1); static const unsigned char v[] = { Div7<0>::Result, Div7<1>::Result, Div7<2>::Result, Div7<3>::Result, Div7<4>::Result, Div7<5>::Result , Div7<6>::Result, Div7<7>::Result, Div7<8>::Result, Div7<9>::Result, Div7<10>::Result, Div7<11>::Result , Div7<12>::Result, Div7<13>::Result, Div7<14>::Result, Div7<15>::Result, Div7<16>::Result, Div7<17>::Result , Div7<18>::Result, Div7<19>::Result, Div7<20>::Result, Div7<21>::Result, Div7<22>::Result, Div7<23>::Result , Div7<24>::Result, Div7<25>::Result, Div7<26>::Result, Div7<27>::Result, Div7<28>::Result, Div7<29>::Result , Div7<30>::Result, Div7<31>::Result, Div7<32>::Result, Div7<33>::Result, Div7<34>::Result, Div7<35>::Result , Div7<36>::Result, Div7<37>::Result, Div7<38>::Result, Div7<39>::Result, Div7<40>::Result, Div7<41>::Result , Div7<42>::Result, Div7<43>::Result, Div7<44>::Result, Div7<45>::Result, Div7<46>::Result, Div7<47>::Result , Div7<48>::Result, Div7<49>::Result, Div7<50>::Result, Div7<51>::Result, Div7<52>::Result, Div7<53>::Result , Div7<54>::Result }; static const unsigned char r[] = { Div7<0>::Remainder, Div7<1>::Remainder, Div7<2>::Remainder, Div7<3>::Remainder, Div7<4>::Remainder, Div7<5>::Remainder , Div7<6>::Remainder, Div7<7>::Remainder, Div7<8>::Remainder, Div7<9>::Remainder, Div7<10>::Remainder, Div7<11>::Remainder , Div7<12>::Remainder, Div7<13>::Remainder, Div7<14>::Remainder, Div7<15>::Remainder, Div7<16>::Remainder, Div7<17>::Remainder , Div7<18>::Remainder, Div7<19>::Remainder, Div7<20>::Remainder, Div7<21>::Remainder, Div7<22>::Remainder, Div7<23>::Remainder , Div7<24>::Remainder, Div7<25>::Remainder, Div7<26>::Remainder, Div7<27>::Remainder, Div7<28>::Remainder, Div7<29>::Remainder , Div7<30>::Remainder, Div7<31>::Remainder, Div7<32>::Remainder, Div7<33>::Remainder, Div7<34>::Remainder, Div7<35>::Remainder , Div7<36>::Remainder, Div7<37>::Remainder, Div7<38>::Remainder, Div7<39>::Remainder, Div7<40>::Remainder, Div7<41>::Remainder , Div7<42>::Remainder, Div7<43>::Remainder, Div7<44>::Remainder, Div7<45>::Remainder, Div7<46>::Remainder, Div7<47>::Remainder , Div7<48>::Remainder, Div7<49>::Remainder, Div7<50>::Remainder, Div7<51>::Remainder, Div7<52>::Remainder, Div7<53>::Remainder , Div7<54>::Remainder }; unsigned char i_div_8 = i >> 3; unsigned char e = i - (i_div_8 + i_div_8 + i_div_8 + i_div_8 + i_div_8 + i_div_8 + i_div_8 + i_div_8); unsigned char a = v[i_div_8]; unsigned char ra = r[i_div_8]; unsigned char b = v[e]; unsigned char rb = r[e]; return a + a + a + a + a + a + a + a + b + v[ra + ra + ra + ra + ra + ra + ra + ra + rb]; }
  3. Naive approach with Sneftel idea: unsigned int div7(unsigned int i) { unsigned int sum = 0; while (i > 7) { unsigned int r = i; i >>= 3; r -= i << 3; sum += i; i += r; } if (i == 7) ++sum; return sum; }
  4. Gray code

    Quote:Original post by CProgrammer ... boolean IsGray(String s1,String s2) { if ((s1.length()==0) || (s2.length()==0)) return false; if (s1.charAt(0)!=s2.charAt(0)) { if(isGray(s1.substring(1, 2), s2.substring(1, 2)) ... else ... } else { ... } } Is not that the skeleton of the solution based on string mutation?
  5. Gray code

    Quote:Original post by Mantear Quote:Original post by GoDoG23 ... Are you proposing that there be a for-loop that loops through all sub-string lengths whenever you hit the s1[0]!=s2[0] condition, starting with the shortest strings to find detect multiple bit differences? That solution works, but if you use a for-loop like that, you might as well not bother with recursion to begin with. ... No. I'm not proposing a for loop, just a multiple recursion solution. I have send you two fully recursive solutions.
  6. Gray code

    Quote:Original post by Mantear Quote:Original post by GoDoG23 You don't need Dn_m; it's just the reasoning behing the formula. When you are in s[0] != s1[0] you know that there are 0 or >=2 differences. If E0_n-1 is true then the differences are 0 and if E0_n-1 is false the differences are >=2. I disagree. Having only a boolean return value from the recursive call, it's ambiguous as to whether you have 0, or 2, or 4, or any x*2 number of differences. Show a method in which it is not ambiguous. What do you want the code? I give you a formal method to the answer. You are thinking with one subproblem but you could use as many as you want. isGrey(s0.sub(0, s0.length()-1), ...) is not an ambiguous call. You know that you have at least 1 difference (you are in s0[0] != s1[0]). With that result you could know the real state of isGrey(s0.sub(1, ...).
  7. Gray code

    Quote:Original post by Mantear Quote:Original post by GoDoG23 Quote:Original post by swiftcoder Quote:Original post by GoDoG23 I think I got a fully recursive solution (multiple recursion). ... But if we look at subproblem E1 = isGrey(s0.sub(0, s0.lenght()-1), s1.sub(0, s1.lenght()-1) we could deduce the real state.That is the solution I thought I had, but I wasn't able to get it to work for multiple discontinuous differences. ... Let En_m be isGrey(s1.sub(n, m), s0.sub(n,m)) where En_m true iff (s1, s2) is grey code. Let Dn_m be differences(s1.sub(n, m), s0.sub(n,m)) where differences return the number of differences. Let n = s[0|1].lenght() if E1_n is false then D1_n == 0 or D1_n >= 2 if D1_n == 0 then D1_n-1 == 0 so as we are in s0[0] != s1[0] then we have D0_n-1 == 1 if D1_n >= 2 then D1_n-1 >= 1 so as we are in s0[0] != s1[0] then we have D0_n-1 >= 2 As we can see: E0_n-1 is false iff number of differences >= 2 We need to extend base case for lenght 1 strings and that's all. Again, how do you distinguish between the case where there are 0 differences or 2 (or any number of even) differences? The recursive call only returns a boolean, there's no way to represent the three states required. There is no Dn_m function that returns something more informative than a boolean. You don't need Dn_m; it's just the reasoning behing the formula. When you are in s[0] != s1[0] you know that there are 0 or >=2 differences. If E0_n-1 is true then the differences are 0 and if E0_n-1 is false the differences are >=2.
  8. Gray code

    Quote:Original post by swiftcoder Quote:Original post by GoDoG23 I think I got a fully recursive solution (multiple recursion). ... But if we look at subproblem E1 = isGrey(s0.sub(0, s0.lenght()-1), s1.sub(0, s1.lenght()-1) we could deduce the real state.That is the solution I thought I had, but I wasn't able to get it to work for multiple discontinuous differences. Could you post your test? I've made the following tests: Test()("1", "0"); Test()("000001", "000000"); Test()("000001", "100001"); Test()("001001", "101001"); Test()("", ""); Test()("0", "0"); Test()("000000", "000000"); Test()("000011", "000000"); Test()("000111", "000000"); Test()("100001", "000000"); Test()("100101", "000000"); Test()("000000", "000000"); Test()("1001", "0001"); Test()("1001", "1101"); Test()("1001", "1011"); Test()("1001", "1000"); Test()("1001", "0000"); Test()("1001", "0101"); Test()("1001", "1010"); Test()("1001", "1111"); Test()("1001", "1001"); Let En_m be isGrey(s1.sub(n, m), s0.sub(n,m)) where En_m true iff (s1, s2) is grey code. Let Dn_m be differences(s1.sub(n, m), s0.sub(n,m)) where differences return the number of differences. Let n = s[0|1].lenght() if E1_n is false then D1_n == 0 or D1_n >= 2 if D1_n == 0 then D1_n-1 == 0 so as we are in s0[0] != s1[0] then we have D0_n-1 == 1 if D1_n >= 2 then D1_n-1 >= 1 so as we are in s0[0] != s1[0] then we have D0_n-1 >= 2 As we can see: E0_n-1 is false iff number of differences >= 2 We need to extend base case for lenght 1 strings and that's all.
  9. Gray code

    I think I got a fully recursive solution (multiple recursion). The problem is that the function have 3 different states: 0 differences, 1 difference (its a grey code), >=2 differences, but the skeleton returns a boolean value. So we could memorize, lookahead or come with a fancy recursive formula. When subproblem E0 = isGrey(s0.sub(1), s1.sub(1)) is false we could be at 0 differences or >=2 differences. But if we look at subproblem E1 = isGrey(s0.sub(0, s0.lenght()-1), s1.sub(0, s1.lenght()-1) we could deduce the real state.
  10. Hidding functions when outsourcing

    Put yout public API and private API in their own library. So you could pass source code from your public API and headers plus .lib/.dll from your private API.
  11. SQL is a standart so almost every SQLite SQL statement is a Postgres valid statatemnt. Postgres SQL commands Postgres complete manual
  12. Matrix.Scaling Issue(Unsolved)

    Matrix.Multiply(Matrix.Scaling(0.2 * CSng(Cos(CDbl(elapsedtime))), 0, 0.2 * CSng(Cos(CDbl(elapsedtime)))), Matrix2) Supposing that Matrix.Scaling(x, y, z) is creating a scaling matrix then the second argument must be 1 not 0. And I think in DX the multiply order must be changed: Matrix.Multiply(matrix2, Matrix.Scanling(...))
  13. IDs versus Pointers

    Unless I'm missing something, for shared resources you need to provide some kind of resource_id to resource mapping. If you want stream resources from disk to memory and those resources are shared then to return an already loaded one you need some kind of mapping.
  14. libglew32s.a

    Supposing you have gcc in your execution path: {PATH TO GLEW SRC DIRECTORY}\gcc -Iinclude -c src/glew.c -o ../lib/libglew32s.a You should have libglew32s.a in {PATH TO GLEW SRC DIRECTORY}\lib directory
  15. libglew32s.a

    Try to compile it your self. Glew/Glee is just one .c file so there is not that difficult.