int main() { std::vector<int> list{ 1,2,3 }; auto result = getCombinations( list ); print( result ); return 0; }
static void pass(lua_State* state, const char* name) { auto* cmb = getCombinations(state); copyString(cmb->passes[cmb->pass_count].data, name); cmb->vs_local_mask[cmb->pass_count] = 0; cmb->fs_local_mask[cmb->pass_count] = 0; ++cmb->pass_count; }
vector<string> letterCombinations(string digits) { int leng = digits.size(); if(leng<1) return vector<string>(); map<char,string> numToLetters = {{'1',""},{'2',"abc"},{'3',"def"},{'4',"ghi"},{'5',"jkl"},{'6',"mno"},{'7',"pqrs"},{'8',"tuv"},{'9',"wxyz"}}; vector<string> combs; string comb = ""; int digits_idx = 0; getCombinations(numToLetters,combs,comb,digits,digits_idx,leng); return combs; }
void getCombinations(map<char,string>& numToLetters, vector<string>& combs,string& comb,const string& digits,int digits_idx,int leng){ if(digits_idx>=leng){ combs.push_back(comb); return; } char digit = digits[digits_idx++]; for(char& c:numToLetters[digit]){ comb +=c; getCombinations(numToLetters,combs,comb,digits,digits_idx,leng); comb.erase(comb.size()-1); } }
static void vs(lua_State* L) { auto* cmb = getCombinations(L); Renderer* renderer = getRendererGlobal(L); if (!renderer) return; LuaWrapper::checkTableArg(L, 1); int len = (int)lua_rawlen(L, 1); for (int i = 0; i < len; ++i) { if (lua_rawgeti(L, -1, i + 1) == LUA_TSTRING) { const char* tmp = lua_tostring(L, -1); int define_idx = renderer->getShaderDefineIdx(tmp); cmb->all_defines_mask |= 1 << define_idx; cmb->vs_local_mask[cmb->pass_count - 1] |= 1 << indexOf(*cmb, define_idx); } } }
void getCombinations(const int *elems, unsigned int n, unsigned int k, int *pos, unsigned int depth, unsigned int margin, unsigned int* cnt_comb, unsigned int *out, int num_comb) { int j; if (depth >= k) { for (j = 0; j < k; ++j) { out[cnt_comb[0] + j*num_comb] = elems[pos[j]]; /*printf("%d:%d=%d\t",cnt_comb[0],j,out[cnt_comb[0] + j*num_comb]); //printf("Out loop : %d:%d\t",cnt_comb[0]+j*num_comb,elems[pos[j]]);//checkpoint*/ } /*printf("\n");*/ cnt_comb[0]++; /*printf("depth loop : %d\n",cnt_comb[0]);*/ return; } for (j = margin; j < n; ++j) { pos[depth]=j; /*printf("pos[d]=%d\n",pos[depth]);*/ getCombinations(elems, n, k, pos, depth + 1, j + 1, cnt_comb, out, num_comb); } }
static void vs(lua_State* L) { auto* cmb = getCombinations(L); Renderer* renderer = nullptr; if (lua_getglobal(L, "renderer") == LUA_TLIGHTUSERDATA) { renderer = LuaWrapper::toType<Renderer*>(L, -1); } lua_pop(L, 1); LuaWrapper::checkTableArg(L, 1); int len = (int)lua_rawlen(L, 1); for (int i = 0; i < len; ++i) { if (lua_rawgeti(L, -1, i + 1) == LUA_TSTRING) { const char* tmp = lua_tostring(L, -1); int define_idx = renderer->getShaderDefineIdx(tmp); cmb->m_all_defines_mask |= 1 << define_idx; cmb->m_vs_local_mask[cmb->m_pass_count - 1] |= 1 << indexOf(*cmb, define_idx); } } }
int ProfileMatchView::getDCombinations(int count, int combinations, int demand_combinations) { int combinations_check = count; int inc_index = combinations-1; int start; QVector<int> index_count; //set up the counting index vector for (int j=0; j<combinations; ++j) { index_count.push_back(j); } int nSupplys = (int)sPButtonList.count(); for (int a=0; a<nSupplys; ++a) { if (index_count[combinations-1]<nSupplys) { int demand_count=0; do{ getCombinations(combinations, index_count, demand_count, demand_combinations); count++; ++index_count[combinations-1]; if (index_count[combinations-1]==nSupplys) { if (index_count[inc_index]!=nSupplys) { start = index_count[inc_index]; ++start; if (start+combinations-inc_index > nSupplys) { --inc_index; start = index_count[inc_index]; ++start; if (start+combinations-inc_index > nSupplys) { --inc_index; start = index_count[inc_index]; ++start; } } if (inc_index+combinations<=nSupplys) { for (int j=inc_index; j<inc_index+combinations; ++j) { if (j<combinations) { index_count[j]= start+j-inc_index; } } } } else { --inc_index; if (inc_index>=0 && inc_index <= combinations) { ++index_count[inc_index]; start = index_count[inc_index]; for (int j=inc_index; j<inc_index+combinations; ++j) { if (j<combinations) { index_count[j]= start+j-inc_index; } } } else { ++inc_index; ++index_count[inc_index]; start = index_count[inc_index]; for (int j=inc_index; j<inc_index+combinations; ++j) { if (j<combinations) { index_count[j]= start+j-inc_index; } } } } } if (inc_index == 0) { inc_index = combinations-1; } }while(nSupplys>index_count[combinations-1]); } } if (combinations_check == count) { count = 0; } return count; }