Forum strony www.multipasko.pl [Regulamin]


Dodaj wpis w tym temacie
Spis tematów
Login:

Hasło:
Strona: 1 2 ... 14 15 16 17 18 19
Wyślij wiadomość do admina

Przewiń wpisy ↓

C++ od niechcenia

2020-01-19 (17:36)

status BochiCintra
Data rejestracji: 2019-07-29 00:00:00
Ilość postów: 99

16005
wpis nr 1 268 863
[ CZCIONKA MONOSPACE ]

https://www.4shared.com/archive/m-Z5QBAXiq/Projeto.html
graphical interface C ++ builder

#include <iostream> // not usable
#include <stdio.h>
#include <string.h>
#include <conio.h> // not usable
2020-01-19 (18:03)

status BochiCintra
Data rejestracji: 2019-07-29 00:00:00
Ilość postów: 99

16005
wpis nr 1 268 866
[ CZCIONKA MONOSPACE ]

generates combinations v, k, t, m

#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#include <windows.h>
#endif

typedef unsigned int UINT;
#define BETA 100

#define first_perm(n) ((1 << n) - 1);

#ifdef _WIN32
HCRYPTPROV hCryptProv;

UINT def_random() {
BYTE r[2];
if(!CryptGenRandom(hCryptProv, sizeof(UINT), r)) {
printf("Error during CryptGenRandom.");
}
return (UINT)(r[1] << 8 | r[0]);
}
#endif

#ifdef __unix__
/* Mac OS X/Linux specific */
FILE *drand;

UINT def_random() {
UINT r;
fread(&r, sizeof(UINT), 1, drand);
return r;
}
#endif

#define _random() def_random()

/* GCC specific definitions */
#define bits_count(v) __builtin_popcount(v)
#define least_one(v) __builtin_ffs(v)

/* http://www-graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation */
/* return next lexicographic permutation */
UINT next_perm(UINT v)
{
UINT t = v | (v - 1);
return (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(v) + 1));
}

/* following
http://mikeash.com/pyblog/friday-qa-2011-03-18-random-numbers.html */
/*
* return a random UINT 0 <= r < n
*/
UINT randomR(UINT n)
{
UINT two31 = 1U << 31;
UINT max = (two31 / n) * n;

while (true) {
UINT r = _random();
if (r < max)
return r % n;
}
}

/* http://rosettacode.org/wiki/Evaluate_binomial_coefficients#C */
/*
* binomial coefficient
*/
UINT combi(UINT n, UINT k)
{
UINT r = 1;
UINT d = n - k;

if (d > k) {
k = d;
d = n - k;
}

while (n > k) {
r *= n--;
while (d && !(r % d))
r /= d--;
}

return r;
}

/*
* select k digits from ds. n is length of ds
*/
UINT sample(UINT k, UINT n, UINT ds[]) {
if (k == 0)
return 0;
if (n == 0)
return 0;

UINT s = sample(k-1, n-1, ds);
UINT p = ds[randomR(n)];
if (p & s)
return ds[n-1] | s;
else
return p | s;
}

/*
* displays subset expressed as bit positions
*/
void show_set(UINT v)
{
bool f = true;
while (v) {
if (!f)
printf(" ");
printf("%02d", least_one(v));
f = false;
v &= v - 1;

}

printf("\n");
}

/*
* union of all subsets
*/
UINT funion(UINT c, UINT w[])
{
UINT r = 0;

for (UINT j = 0; j < c; ++j)
r |= w[j];

return r;
}

/*
* init work memory with subsets that are far from
* initial ticket (defined as first_perm)
*/
UINT init(UINT c, UINT n, UINT l, UINT k, UINT w[])
{
UINT i = 0;
UINT v = first_perm(n);

while (c--) {
if (bits_count(v & k) < l)
w[i++] = v;
v = next_perm(v);
}

return i;
}

/*
* copies subsets that are far from passed ticket
*/
UINT check_cover(UINT r, UINT l, UINT t, UINT from[], UINT to[])
{
UINT i = 0;

for (UINT j = 0; j < r; ++j)
if (bits_count(from[j] & t) < l)
to[i++] = from[j];

return i;
}

void solve(UINT v, UINT k, UINT t, UINT m)
{
UINT r = combi(v, m);
UINT *work = malloc(sizeof(UINT) * (BETA+1) * r);

UINT a = first_perm(k);

show_set(a);

r = init(r, m, t, a, work);

while (r) {
UINT d = funion(a, work);
int bc = bits_count(d);

UINT digits[bc];

int i = 0;

while (d) {
digits[i++] = d & -d;
d &= d - 1;
}

UINT best_ticket, best_remaining, best_pos = 0;

best_ticket = sample(k, bc, digits);
best_remaining = check_cover(r, t, best_ticket, work, work+r);

//for (UINT i = 1;i ">" BETA; ++i){ // generates faster combinations and more cards
for (UINT i = 1; i < BETA; ++i) {
UINT new_ticket = sample(k, bc, digits);
UINT new_remaining = check_cover(r, t, new_ticket,
work, work+((1+i)*r));

if (new_remaining < best_remaining) {

best_ticket = new_ticket;
best_remaining = new_remaining;
best_pos = i;

}
}

show_set(best_ticket);
if (best_remaining)
memcpy(work, work+(best_pos+1)*r, sizeof(UINT) * best_remaining);

r = best_remaining;
}

free(work);
}

int main(int argc, char *argv[])
{
system("Color 1F");
UINT v, k, t, m;
v=12;
k=6;
t=5;
m=6;

/* sscanf(argv[1], "%u", &v);
sscanf(argv[2], "%u", &k);
sscanf(argv[3], "%u", &t);
sscanf(argv[4], "%u", &m);*/

// #ifdef _WIN32
if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
// printf("Error during CryptAcquireContext!\n");
}
// #endif

// #ifdef __unix__
// drand = fopen("/dev/random", "r");
// #endif

solve(v, k, t, m);

// #ifdef _WIN32
// if (!CryptReleaseContext(hCryptProv, 0)) {
// printf("Failed CryptReleaseContext\n");
// }
// #endif

// #ifdef __unix__
// fclose(drand);
// #endif

// return 0;
}
2020-01-21 (14:12)

status Lottonauta
Data rejestracji: 2012-09-03 00:00:00
Ilość postów: 3147

13559
wpis nr 1 269 215
[ CZCIONKA MONOSPACE ]

@BochiCintra,

nice program code.
Are you its author?
2020-01-21 (14:41)

status BochiCintra
Data rejestracji: 2019-07-29 00:00:00
Ilość postów: 99

16005
wpis nr 1 269 232
[ CZCIONKA MONOSPACE ]

@lottonauta

https://blog.wakatta.jp/blog/2012/02/13/psychic-modeling-fast-version/

no, this is original I just made some changes

int main(int argc, char *argv[])
{


UINT v, k, t, m;


#ifdef _WIN32
if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
printf("Error during CryptAcquireContext!\n");
}
#endif

#ifdef __unix__
drand = fopen("/dev/random", "r");
#endif

if((argc <= 1) || (argv <= 1)){
printf("Digite o Total de Numeros (1 a 32) :");
scanf("%d", &v);

if((v < 1) || (v > 32)){
printf("\nTotal de Numeros Invalido!\n\n");
system("Pause");
return 0;
}

printf("Digite o Total de Numeros por Bilhetes (1 a 18) :");
scanf("%d", &k);

if((k < 3) || (k > 25)){
printf("\nTotal de Numeros por Bilhetes Invalido!\n\n");
system("Pause");
return 0;
}

printf("Digite a Garantia da Matriz (1 a 20) :");
scanf("%d", &t);

if((t < 2) || (t > 20)){
printf("\nGarantia da Matriz Invalida!\n\n");
system("Pause");
return 0;
}

printf("Digite a Condicao da Matriz (1 a 20) :");
scanf("%d", &m);

if((m < 2) || (m > 20)){
printf("\nCondicao da Matriz Invalida!\n\n");
system("Pause");
return 0;
}

solve(v, k, t, m);
printf("\n====== PARAMETROS ======\n");
printf("\nV = %0d", v);
printf("\nK = %0d", k);
printf("\nT = %0d", t);
printf("\nM = %0d", m);
printf("\n\n");

}

/* #ifdef _WIN32
if (!CryptReleaseContext(hCryptProv, 0)) {
printf("Failed CryptReleaseContext\n");
}
#endif

#ifdef __unix__
fclose(drand);
#endif*/

return 0;
}
2020-01-21 (14:48)

status BochiCintra
Data rejestracji: 2019-07-29 00:00:00
Ilość postów: 99

16005
wpis nr 1 269 236
[ CZCIONKA MONOSPACE ]

@lottonauta
https://github.com/jrocha/cover/blob/master/CoverC.c
this generates and reduces

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <conio.h>
#include <ctype.h>

#define MIN_V 5
#define MED_V 63
#define MAX_V 80
#define MIN_K 3
#define MAX_K 20
#define MIN_T 1
#define MAX_T 15
#define MAX_M 15

#define MAX_COVER 100000000

#define ERR_WRONG_NUMBER_ARGS 101
#define ERR_INVALID_V 102
#define ERR_INVALID_K 103
#define ERR_INVALID_T 104
#define ERR_INVALID_M 105
#define ERR_INVALID_VK 106
#define ERR_INVALID_KT 107
#define ERR_INVALID_KM 108
#define ERR_INVALID_COMB 109

#define TIME_STRINGLEN 26

#define rnd(num) (rand() % (num)) /* gives an integer random number between 0 and num - 1, inclusive */

unsigned long C[MAX_V+1][MAX_K+1]; // used to calculate combination C(x,y), need 64 bits for C(p,8) when p>=64

int *Tset; // boolean array, indicates if a t-set is covered

int Kaux[MAX_K]; // auxiliar to calculate k-sets, used in FindNextCover

int M[MAX_M]; // auxiliar to calculate m-subsets, used in SetICover, AddCoverFromRoll
int SubK[MAX_M]; // subconjunto de um volante K com elementos variando de t a m
int SubVK[MAX_M]; // subconjunto com elementos que não estão em um volante K com elementos variando de m-t a m-1

int V[MAX_V]; // auxiliar to calculate numbers that are not in a k-set

int **MTIndex; // auxiliar to precalculate all C(m,t) combinations

int ***KXIndex; // auxiliar to precalculate all C(k,t0) combinations, varying t0 from t to m
int ***VXIndex; // auxiliar to precalculate all C(v-k,m-t0) combinations, varying t0 from t to m-1

unsigned long ArrayCover [MAX_COVER]; // holds coverings
int CoverCount = 0; // counts number of coverings
unsigned long Size = 0; // counts number of drawns, C(v,m)
int *ICover; // holds the indexes of the cover that covers a combination
int *ICoverAux; // backup of ICover

int v,k,t,m; // v = max number, k = numbers per set, t = guarantee, m = drawn

// fill all C(v,k) combinations
// baseado na Relacao de Stiffel do triangulo de Pascal
// C(n,p) + C(n,p+1)=C(n+1,p+1)
void FillC()
{
int i,j;
for(i=0; i<=v; i++)
{
C[i][0] = 1;
for(j=1; j<=k; j++)
{
if (i < j)
C[i][j] = 0;
else
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
}

// preenche Array com as todas as combinacoes prontas
// ex: x=6,y=3 gera (0,1,2),(0,1,3).... (3,4,5)
void FillCombArray (int **Array, int x, int y)
{
int i;
int tCount = 0;

// safe
if (y > x || !y)
return;

for (i=0 ; i < y ; i++)
Array[tCount][i] = i;

while (Array[tCount][0] < x-y)
{
int j = 0;
while(j<y-1 && Array[tCount][j+1] <= Array[tCount][j] + 1)
j++;
tCount++;
Array[tCount][j] = Array[tCount-1][j]+1;
for(i = 0; i < j; i++)
Array[tCount][i] = i;
for(i = j+1; i < y; i++)
Array[tCount][i] = Array[tCount-1][i];
}
}

int Initialize()
{
unsigned long i;
int j;

// fill C array
FillC();

//alloc memory to Tset array
Tset = (int *)malloc(C[v][t]*sizeof(int));
if (Tset == NULL)
return 0;
memset(Tset,0,C[v][t]*sizeof(int));

//alloc memory to MTIndex array
MTIndex = (int **)malloc(C[m][t]*sizeof (int *));
if (MTIndex == NULL)
return 0;

for(i = 0; i < C[m][t]; i++)
{
MTIndex[i] = (int *)malloc(t * sizeof(int));
if (MTIndex[i] == NULL)
return 0;
}

// fill all C(m,t) combinations
FillCombArray(MTIndex, m, t);

// alloc memory to KXIndex array
// auxiliar to precalculate all C(k,t0) combinations, varying t0 from t to m
KXIndex = (int ***)malloc((m-t+1) * sizeof(int **));
if (KXIndex == NULL)
return 0;

for(j = 0; j < m-t+1; j++)
{
KXIndex[j] = (int **)malloc(C[k][j+t] * sizeof(int *));
if (KXIndex[j] == NULL)
return 0;
for(i = 0; i < C[k][j+t]; i++)
{
KXIndex[j][i] = (int *)malloc((j+t) * sizeof(int));
if (KXIndex[j][i] == NULL)
return 0;
}
// fill all C(k,j+t) combinations
FillCombArray(KXIndex[j], k, j+t);
}

// auxiliar to precalculate all C(v-k,m-t0) combinations, varying t0 from t to m-1
// alloc memory to VXIndex array, only if m-t>0
if (t < m)
{
VXIndex = (int ***)malloc((m-t) * sizeof(int **));
if (VXIndex == NULL)
return 0;

for(j = 0; j < m-t; j++)
{
VXIndex[j] = (int **)malloc(C[v-k][m-j-t] * sizeof(int *));
if (VXIndex[j] == NULL)
return 0;
for(i = 0; i < C[v-k][m-j-t]; i++)
{
VXIndex[j][i] = (int *)malloc((m-j-t) * sizeof(int));
if (VXIndex[j][i] == NULL)
return 0;
}
// fill all C(v-k,m-j-t) combinations
FillCombArray(VXIndex[j], v-k, m-j-t);

}
}

// number of possible drawns
Size = C[v][m];

// initialize cover index array
ICover = malloc(Size*sizeof(int));
if(ICover == NULL)
return 0;

ICoverAux = malloc(Size*sizeof(int));
if(ICoverAux == NULL)
return 0;

for(i = 0; i < Size; i++)
ICover[i] = ICoverAux[i] = MAX_COVER;

//initialize Random
srand( (unsigned)time( NULL ) );

return 1;
}
void Finalize()
{
unsigned long i;
unsigned long l;
int j;

for (l=0;l<Size;l++)
{
if (ICover[l] >= MAX_COVER)
printf ("%u not covered\n",l);
}

// cover index
if (ICoverAux)
free(ICoverAux);
if (ICover)
free(ICover);

if (t < m)
{
// free VXIndex
for(j = 0; j < m-t; j++)
{
for(i = 0; i < C[v-k][m-j-t]; i++)
{
if (VXIndex[j][i])
free(VXIndex[j][i]);
}
if (VXIndex[j])
free(VXIndex[j]);
}
if (VXIndex)
free(VXIndex);
}

// free KXIndex
for(j = 0; j < m-t+1; j++)
{
for(i = 0; i < C[k][j+t]; i++)
{
if (KXIndex[j][i])
free(KXIndex[j][i]);
}
if (KXIndex[j])
free(KXIndex[j]);
}
if (KXIndex)
free(KXIndex);

// free MTIndex
for (i=0; i<C[m][t]; i++)
{
if (MTIndex[i])
free(MTIndex[i]);
}
if (MTIndex)
free(MTIndex);

// free boolean array
if (Tset)
free(Tset);
}

// code a p-set into an unsigned long
unsigned long Code(int *A, int p)
{
unsigned long r=0;
int i;
for (i=0;i<p;i++)
r += C[A[i]][i+1];
return r;
}

// decode a p-set into an array of int
void Decode (unsigned long num, int *A, int p)
{
int i,j;
for(i = p-1; i >= 0; i--)
{
j = i;
while(C[j+1][i+1] <= num)
j++;
num -= C[j][i+1];
A[i] = j;
}
}

void PrintCover(char *FileName)
{
int K[MAX_K]; // auxiliar to decode k-sets

FILE *stream;
int i;
int l_size = 0;
errno_t err;

err = fopen_s(&stream, FileName, "w" );

if (err != 0)
{
// printf("Could not write to file %s\n", FileName);
// return;
}
// Imprime o Array de Cobertura
for (i=0;i<CoverCount;i++)
{
if (ArrayCover[i] != (unsigned long)-1)
{
int j;
Decode (ArrayCover[i], K, k);
for (j=0;j<k;j++)
printf( "%02d ", K[j]+1);

printf( "\n");
l_size ++;

}
}

printf( "Tamanho da Cobertura = %02d\n ",l_size );

//fclose(stream);
}

int GETSOL(int *A, int *B)
{
int i;
unsigned long index = 0;
for (i=0;i<t;i++)
index += C[A[B[i]]][i+1]; // 32 bits are enough for C(v,t)
return Tset[index];
}

void SETSOL(int *A, int *B)
{
int i;
unsigned long index = 0;
for (i=0;i<t;i++)
index += C[A[B[i]]][i+1]; // 32 bits are enough for C(v,t)
Tset[index]=1;
}

void ADDSOL (int *K)
{
unsigned long i;

for (i=0; i<C[k][t]; i++)
SETSOL(K, KXIndex[0][i]);
}

int SOLVED (int *M)
{
unsigned long i;
int r = 0;

for (i=0; !r && i<C[m][t]; i++)
r = GETSOL(M, MTIndex[i]);

return r;
}


// A é um array de dezenas de tamanho x
// B é um array de dezenas de tamanho y
// match é o numero esperado de elementos comuns
// retorna 1 ou 0 se o numero de elementos comuns é maior ou igual ao esperado
int MATCH (int *A, int x, int *B, int y, int match)
{
int i, j;
int r=0;

for (i=0;i<x;i++)
{
for (j=0; j<y; j++)
if (A[i] == B[j])
{
r++;
break;
}
if (r == match)

return 1;
}
return 0;
}

int IndexOf(int *pArray, int value, int StartPos, unsigned long Len)
{
unsigned long i;
for(i=StartPos;i<Len;i++)
{
if(pArray[i] == value)
return i;
}
return -1;
}

// puts in V all elements that are not in K
void DiffVK (int *K)
{
int i,j;
int notinA = 0;

// puts in V all elements that are not in K
for(i=0, j=0; i<v; i++)
{
if (j<k && K[j] == i)


j++;
else
{
V[notinA] = i;
notinA++;
}
}
}

// seta o array ICover
// indice corresponde a um possivel sorteio
// valor corresponde a qual volante esta cobrindo
void SetICover (int *Mparam, int cover)
{
unsigned long cm;
cm = Code(Mparam, m);
if (ICover[cm] > cover)
ICover[cm] = cover;
}

// union de dezenas de A e B, e jogando em Mparam
// x = numero de dezenas de A
// y = numero de dezenas de B
// x+y = m
void Union(int *Mparam, int *A, int x, int *B, int y)
{
int i,ix,iy;

// safe
if((x+y) != m)
{
printf("Invalid parameters to Union %d %d",x,y);
return;
}
ix = 0;
iy = 0;
for (i=0; i<m; i++)
{
// faz o union na ordem para evitar o sort
if (iy >= y || (ix < x && A[ix] < B[iy]))
{
Mparam[i] = A[ix];
ix++;
}
else
{
Mparam[i] = B[iy];
iy++;
}
}
}

// preencher o array ICover com todos os volantes derivados de K
void FillICover (int *K, int cover)
{
unsigned long i, vi;
int j, vj;
int t0;

// construcao de todos os conjuntos de m dezenas que fariam t acertos
// a partir de um volante com k dezenas
// * supondo C(40,6,3,5) - volante = (0,1,2,3,4,5)
// [1] constroi subconjuntos de t0 elementos a partir de k = C(k, t0), começando com t0=t
// * subconjuntos (0,1,2),(0,1,3),(0,1,4),...,(3,4,5)
// [2] constroi subconjuntos com m-t0 elementos, que não estão em k = C(v-k, m-t0)
// * (6,7),(6,8),(6,9),...,(38,39)
// [3] faz a união dos subconjuntos, por construção o conjunto obtido faria t acertos
// * (0,1,2,6,7),(0,1,3,6,7),....(3,4,5,38,39)
// repete o processo até que t0 seja igual a m
// * isso pega também os sorteios que fariam 4 e 5 acertos

// prepara array V com elementos que não estão em K
DiffVK(K);

for (t0=t; t0<=m; t0++)
{
for (i=0; i<C[k][t0]; i++)
{
for (j=0; j<t0; j++)
{
// [1]
SubK[j] = K[KXIndex[t0-t][i][j]];
}
// [2]
if (t0 < m)
{
for (vi=0; vi<C[v-k][m-t0]; vi++)
{
for (vj=0; vj<m-t0; vj++)
{
SubVK[vj] = V[VXIndex[t0-t][vi][vj]];
}
// [3] - resultado do Union fica em M
Union(M, SubK, t0, SubVK, m-t0);
SetICover(M, cover);
}
}
else
// se t0=m, então SubK tem m elementos
SetICover(SubK, cover);
}
}
}


void AddCoverCommon(int *K)
{
// preenche o array ICover com todos os volantes derivados de K
FillICover(K, CoverCount);

// adiciona um volante
ADDSOL(K);
// save K
ArrayCover[CoverCount] = Code(K, k);

CoverCount++;

if (CoverCount == MAX_COVER)

{

printf("maximum number of coverings reached, aborting execution, look for incomplete.txt\n");
PrintCover("incomplete.txt");

Finalize();
exit(1);
}
}

void AddCoverFromRoll(int *K)
{
int i,j;

// for each C(k,m) combination
for (i=0; i<(int)C[k][m]; i++)
{
for (j=0; j<m; j++)
M[j] = K[KXIndex[m-t][i][j]];

// check to see if it is already covered
if(SOLVED(M) == 0)
{
// se não está coberto adiciona
AddCoverCommon(K);
break;
}
}
}

void Roll()
{
int K[MAX_K]; // auxiliar to calculate k-sets

int i;

for (i=0 ; i < k ; i++)
K[i] = i;

AddCoverFromRoll(K);
while (K[0] < v-k)
{
int j = 0;
while(j<k-1 && K[j+1] <= K[j] + 1)
j++;
K[j]++;
for(i = 0; i < j; i++)
K[i] = i;
AddCoverFromRoll(K);
}
}

int compare (const int *i, const int *j)
{
return *i-*j;
}

// procura proxima cobertura para um volante removido
// em C(x,6,3,6) ao remover um volante (0,1,2,3,4,5)
// o sorteio (0,1,2,3,4,5) pode ser coberto por um outro jogo, exemplo: (0,1,2,7,8,9)
int FindNextCover(unsigned long ind, int cover)
{
int i;

// obtem as dezenas do sorteio
Decode(ind, M, m);

for (i = cover+1; i < CoverCount; i++)
{
// ignore if already removed
if (ArrayCover[i] != (unsigned long)-1 )
{
// obtem as dezenas do volante
Decode(ArrayCover[i], Kaux, k);

// se esse outro volante, tem t dezenas em comum com esse sorteio, retorna
if (MATCH(M, m, Kaux, k, t))
return i;
}
}
return MAX_COVER;
}

// apenas limpa todas as entradas de um volante no ICover
void RemoveCover(int cover)
{
unsigned long i;

for(i=0;i<Size;i++)
{
if(ICover[i] == cover)
{
ICover[i] = MAX_COVER;
}
}
}

// esse método procura por sorteios não cobertos por nenhum volante
// quando encontra, tenta achar um outro volante que cubra
// se não encontra, retorna 0
// se preencheu tudo, retorna 1
int IsComplete(int cover)
{
unsigned long i;
int nc;

for(i=0;i<Size;i++)
{
if(ICover[i] == MAX_COVER)
{
// try to find an alternative
nc = FindNextCover(i, cover);
if (nc == MAX_COVER)
return 0;
ICover[i] = nc;
}
}
return 1;
}

int Optimize(void)
{
// [1] para cada volante, a partir do segundo [um volante sempre vai existir]
// [2] se volante já não foi removido
// [3] faz um backup do volante
// [4] faz um backup do ICover
// [5] remove o volante
// [6] pega as dezenas do volante K
// [7] monta o conjunto V com todas as dezenas que não estão no volante K
// [8] monta volante K', sorteia uma dezena de K e troca por uma dezena sorteada de V
// [9] ordena K'
// [10] preenche o ICover com esse novo volante
// [11] se ICover esta completo, i.e., não tem nenhuma entrada MAX_COVER
// [12] salva esse novo volante e incrementa contador de mudancas com sucesso
// [13] senão, volta backup do volante e do array ICover
// [14] retorna contador de mudancas com sucesso

int K[MAX_K]; // auxiliar to calculate k-sets
int mov = 0; // moving counter
int i;
unsigned long Kbkp;
int iM; // indice do volante K
int iv; // indice do conjunto V

// [1]
for (i=1; i<CoverCount; i++)
{
// [2] ignore if already removed
if(ArrayCover[i] != (unsigned long) -1)
{
// try to eliminate some covering
// if it is already covered, then try to remove
if (IndexOf(ICover,i,0,Size) == -1)
{
//set to zero
ArrayCover[i] = (unsigned long) -1;
}
else
{
// [3] e [4] backup
Kbkp = ArrayCover[i];
memcpy(ICoverAux,ICover,sizeof(int)*Size);

// [5] remove
RemoveCover(i);

// [6] decode into K
Decode(Kbkp, K, k);

// [7] puts in V all elements that are not in K
DiffVK(K);

// [8]
iM = rnd(k);
iv = rnd(v-k);
K[iM] = V[iv];

// [9] sort K
qsort(K, k, sizeof(int), compare);

// [10] preenche ICover a partir desse novo volante
FillICover(K, i);

// [11] se a cobertura continua completa
if (IsComplete(i))
{
// [12]
ArrayCover[i] = Code(K, k);
mov++;
}
else
{
// [13] restore backup
ArrayCover[i] = Kbkp;
memcpy(ICover,ICoverAux,sizeof(int)*Size);
}
}
}
}
// [14]
return mov;
}

int CoverSize(void)
{
int size = 0;
int i;
for(i = 0; i < CoverCount; i++)
if (ArrayCover[i] != (unsigned long)-1) size++;
return size;
}

int StartFromFile(char *filename)
{
int K[MAX_K]; // auxiliar to read k-sets

FILE *stream;

size_t aux =0;
int i;
char c[2];
char tab[1];
errno_t err;

err = fopen_s(&stream, filename, "r" );
if(err != 0)
{
printf("%s File not found!\n",filename);
return -1;
}

while (!feof(stream))
{
for(i=0;i<k;i++)
{
aux = fread(c,sizeof(char),2,stream);
aux = fread(tab,sizeof(char),1,stream);
if (!aux) break;
K[i] = atoi(c)-1;
if (K[i] >= v || K[i] < 0)
{
printf("Invalid value found: %d\n",K[i]+1);
printf("%s", c);
fclose(stream);
return -1;
}
}
aux = fread(tab,sizeof(char),1,stream);
if (!aux) break;
AddCoverCommon(K);
}
fclose(stream);
return 0;
}



void main(int argc, char *argv[])
{
char *fileout = NULL;
char *filein = NULL;
int size; // guarda o total de volantes
int newsize; // guarda o total de volantes apos a otimizacao
int mov = 0; // guarda o total de mudancas conseguidas com sucesso
int loop = 0; // guarda o numero de tentativas de otimizacao
char ch; // para guardar o input do usuario (S/N)
int LOOP_BREAK = 10; // guarda o maximo de tentativas sem perguntar
FILE *pont_arq;
/*struct _timeb timebuffer1;
struct _timeb timebuffer2;
char timeline[TIME_STRINGLEN];*/
//errno_t err;

//double elapsed_time;
pont_arq = fopen("combinações.txt", "w");

if((argc <= 1) || (argv <= 1)){
printf("Digite o Total de Numeros (1 a 80) :");
scanf("%d", &v);

if((v < 1) || (v > 80)){
printf("\nTotal de Numeros Invalido!\n\n");
system("Pause");
return 0;
}

printf("Digite o Total de Numeros por Bilhetes (1 a 18) :");
scanf("%d", &k);

if((k < 3) || (k > 18)){
printf("\nTotal de Numeros por Bilhetes Invalido!\n\n");
system("Pause");
return 0;
}

printf("Digite a Garantia da Matriz (1 a 20) :");
scanf("%d", &t);

if((t < 2) || (t > 15)){
printf("\nGarantia da Matriz Invalida!\n\n");
system("Pause");
return 0;
}

printf("Digite a Condicao da Matriz (1 a 20) :");
scanf("%d", &m);

if((m < 2) || (m > 15)){
printf("\nCondicao da Matriz Invalida!\n\n");
system("Pause");
return 0;
}
if(!Initialize (v,k,t,m))

printf("\n====== PARAMETROS ======\n");
printf("\nV = %0d", v);
printf("\nK = %0d", k);
printf("\nT = %0d", t);
printf("\nM = %0d", m);
printf("\n\n");

}

// read file if supplied
/*if(filein)
{
if (StartFromFile (filein))
{
printf("Error reading file %s\n",filein);
Finalize();
return;
}

// check to see if is complete
if (IndexOf(ICover,MAX_COVER,0,Size) != -1)
Roll();
}
else*/
Roll ();

size = CoverSize();

printf("Tamanho da Cobertura %d\n", size);

// Inicio da Otimizacao

do
{
mov += Optimize();
newsize = CoverSize();
// se o numero de volantes diminuiu ou estourou limite de tentativas
if (newsize < size || loop > LOOP_BREAK )
{
// mostra resultado

printf( "Moves:%d. Tamanho da Cobertura %d\n", mov, newsize,CoverSize());

// zera contador de mudancas
mov = 0;

PrintCover(fileout);
// se estourou limite de tentativas, pergunta se continua tentando
if (loop > LOOP_BREAK)
{
printf("Tentar reduzir mais? Continua? (S/N) ");
ch = _getch();
ch = toupper( ch );
_putch (ch);
if(ch == 'N') break;
}

// novo tamanho é o conseguido pelo otimizador
size = newsize;

// zera contador de tentativas
loop = 0;
}
loop++;
} while(1);

Finalize();

}
2020-05-07 (23:00)

status Lottonauta
Data rejestracji: 2012-09-03 00:00:00
Ilość postów: 3147

13559
wpis nr 1 291 167
[ CZCIONKA MONOSPACE ]

2020-05-07 (21:40)

status sindbad wpis nr 1 291 126

Potrzebna szybka funkcja kodowania CSN




Zdefiniuj CSN.
2020-05-08 (17:41)

status sindbad
Data rejestracji: 2008-10-13 00:00:00
Ilość postów: 20531

3794
wpis nr 1 291 318
[ CZCIONKA MONOSPACE ]

Lottonauta, nie rozumiem.

Jeśli macie coś gotowego poza tymi od Amadeusa to można w tym temacie zamieścić.
2020-05-08 (18:04)

status Lottonauta
Data rejestracji: 2012-09-03 00:00:00
Ilość postów: 3147

13559
wpis nr 1 291 324
[ CZCIONKA MONOSPACE ]

Sindbad,

nie jestem w temacie, więc nie rozumiem co to CSN, chociarz domyślam się, że chodzi o zaindeksowanie kolejnych losowań ułożonych w porządku leksykograficnzym.
Zajmowałem się swego czasu tym tematem, więc opisz tutaj ten porządek w CSN (bo można to zrobić na wiele sposobów), to może coś podpowiem.
Pokaż też rozwiązanie od Amadeusa (jestem ciekaw jak to rozwiązał).

Pozdrawiam
2020-05-08 (18:48)

status 777ch
Data rejestracji: 2005-11-07 00:00:00
Ilość postów: 22655

1386
wpis nr 1 291 326
[ CZCIONKA MONOSPACE ]

Lottonauta

Mam pytanie a właściwie tylko dwa pytania ,albo trzy


1. Potrafisz przełożyć procedury pisane w Vba na C lub C++ --> ?
2. Potrafisz przełożyć procedury pisane w paskal object na C lub C++ --> ?

czyli razem ..... dwa pytania
pozdrawiam

Nie piszę w tym języku , a powinienem .....
ale ...nie piszę...

właściwe pytanie miało być inne
potrafisz manipulować bitami w C lub c++
tworzyć tablice ,podmieniając bity w pamięci
odczytując ect. to miałem na myśli
dla zapytania numer 3 --> manipulacja bitami

--- wpis edytowano 2020-05-08 18:52 ---

2020-05-08 (19:15)

status mak1nero
Data rejestracji: 2020-04-14 00:00:00
Ilość postów: 885

16159
wpis nr 1 291 331
[ CZCIONKA MONOSPACE ]

Program nie działa:

---------------------------
Project1.exe - Błąd systemu
---------------------------
Nie można uruchomić programu, ponieważ na komputerze nie znaleziono vcl60.bpl. Spróbuj ponownie zainstalować program, aby naprawić ten problem.
---------------------------
OK
---------------------------
2020-05-08 (19:32)

status sindbad
Data rejestracji: 2008-10-13 00:00:00
Ilość postów: 20531

3794
wpis nr 1 291 340
[ CZCIONKA MONOSPACE ]

Ja myślałem, że macie jakieś gotowe metody, bo nie mam czasy nawet na szukanie.
Mam to gdzieś na starym dysku w pudle na strychu, ale myślę, że będzie podobne do tego, co napisał Amadeus. Pamiętam też coś innego od Dylonga, ale to dawne czasy.
W sumie chodzi jedynie o numer kombinacji bez udziwnień, że 1 to koza a 12 to byk albo, co innego he!

Pozdrawiam


//-----------------------------------------------------------------------------

// Amadeus

Const Combinations : Array[0..80,0..10] Of int64 =

(

(1,00,0000,00000,000000,0000000,00000000,000000000,000000000000,000000000000,000000000000),
(1,01,0000,00000,000000,0000000,00000000,000000000,000000000000,000000000000,000000000000),
(1,02,0001,00000,000000,0000000,00000000,000000000,000000000000,000000000000,000000000000),
(1,03,0003,00001,000000,0000000,00000000,000000000,000000000000,000000000000,000000000000),
(1,04,0006,00004,000001,0000000,00000000,000000000,000000000000,000000000000,000000000000),
(1,05,0010,00010,000005,0000001,00000000,000000000,000000000000,000000000000,000000000000),
(1,06,0015,00020,000015,0000006,00000001,000000000,000000000000,000000000000,000000000000),
(1,07,0021,00035,000035,0000021,00000007,000000001,000000000000,000000000000,000000000000),
(1,08,0028,00056,000070,0000056,00000028,000000008,000000000001,000000000000,000000000000),
(1,09,0036,00084,000126,0000126,00000084,000000036,000000000009,000000000001,000000000000),
(1,10,0045,00120,000210,0000252,00000210,000000120,000000000045,000000000010,000000000001),
(1,11,0055,00165,000330,0000462,00000462,000000330,000000000165,000000000055,000000000011),
(1,12,0066,00220,000495,0000792,00000924,000000792,000000000495,000000000220,66),
(1,13,0078,00286,000715,0001287,00001716,000001716,000000001287,000000000715,286),
(1,14,0091,00364,001001,0002002,00003003,000003432,000000003003,000000002002,1001),
(1,15,0105,00455,001365,0003003,00005005,000006435,000000006435,000000005005,3003),
(1,16,0120,00560,001820,0004368,00008008,000011440,000000012870,000000011440,8008),
(1,17,0136,00680,002380,0006188,00012376,000019448,000000024310,000000024310,19448),
(1,18,0153,00816,003060,0008568,00018564,000031824,000000043758,000000048620,43758),
(1,19,0171,00969,003876,0011628,00027132,000050388,000000075582,000000092378,92378),
(1,20,0190,01140,004845,0015504,00038760,000077520,000000125970,000000167960,184756),
(1,21,0210,01330,005985,0020349,00054264,000116280,000000203490,000000293930,352716),
(1,22,0231,01540,007315,0026334,00074613,000170544,000000319770,000000497420,646646),
(1,23,0253,01771,008855,0033649,00100947,000245157,000000490314,000000817190,1144066),
(1,24,0276,02024,010626,0042504,00134596,000346104,000000735471,000001307504,1961256),
(1,25,0300,02300,012650,0053130,00177100,000480700,000001081575,000002042975,3268760),
(1,26,0325,02600,014950,0065780,00230230,000657800,000001562275,000003124550,5311735),
(1,27,0351,02925,017550,0080730,00296010,000888030,000002220075,000004686825,8436285),
(1,28,0378,03276,020475,0098280,00376740,001184040,000003108105,000006906900,13123110),
(1,29,0406,03654,023751,0118755,00475020,001560780,000004292145,000010015005,20030010),
(1,30,0435,04060,027405,0142506,00593775,002035800,000005852925,000014307150,30045015),
(1,31,0465,04495,031465,0169911,00736281,002629575,000007888725,000020160075,44352165),
(1,32,0496,04960,035960,0201376,00906192,003365856,000010518300,000028048800,64512240),
(1,33,0528,05456,040920,0237336,01107568,004272048,000013884156,000038567100,92561040),
(1,34,0561,05984,046376,0278256,01344904,005379616,000018156204,000052451256,131128140),
(1,35,0595,06545,052360,0324632,01623160,006724520,000023535820,000070607460,183579396),
(1,36,0630,07140,058905,0376992,01947792,008347680,000030260340,000094143280,254186856),
(1,37,0666,07770,066045,0435897,02324784,010295472,000038608020,000124403620,348330136),
(1,38,0703,08436,073815,0501942,02760681,012620256,000048903492,000163011640,472733756),
(1,39,0741,09139,082251,0575757,03262623,015380937,000061523748,000211915132,635745396),
(1,40,0780,09880,091390,0658008,03838380,018643560,000076904685,000273438880,847660528),
(1,41,0820,10660,101270,0749398,04496388,022481940,000095548245,000350343565,1121099408),
(1,42,0861,11480,111930,0850668,05245786,026978328,000118030185,000445891810,1471442973),
(1,43,0903,12341,123410,0962598,06096454,032224114,000145008513,000563921995,1917334783),
(1,44,0946,13244,135751,1086008,07059052,038320568,000177232627,000708930508,2481256778),
(1,45,0990,14190,148995,1221759,08145060,045379620,000215553195,000886163135,3190187286),
(1,46,1035,15180,163185,1370754,09366819,053524680,000260932815,001101716330,4076350421),
(1,47,1081,16215,178365,1533939,10737573,062891499,0000314457495,01362649145,5178066751),
(1,48,1128,17296,194580,1712304,12271512,073629072,0000377348994,01677106640,6540715896),
(1,49,1176,18424,211876,1906884,13983816,085900584,0000450978066,02054455634,8217822536),
(1,50,1225,19600,230300,2118760,15890700,099884400,0000536878650,02505433700,10272278170),
(1,51,1275,20825,249900,2349060,18009460,115775100,0000636763050,03042312350,12777711870),
(1,52,1326,22100,270725,2598960,20358520,133784560,0000752538150,03679075400,15820024220),
(1,53,1378,23426,292825,2869685,22957480,154143080,0000886322710,04431613550,19499099620),
(1,54,1431,24804,316251,3162510,25827165,177100560,0001040465790,05317936260,23930713170),
(1,55,1485,26235,341055,3478761,28989675,202927725,0001217566350,06358402050,29248649430),
(1,56,1540,27720,367290,3819816,32468436,231917400,0001420494075,07575968400,35607051480),
(1,57,1596,29260,395010,4187106,36288252,264385836,0001652411475,08996462475,43183019880),
(1,58,1653,30856,424270,4582116,40475358,300674088,0001916797311,10648873950,52179482355),
(1,59,1711,32509,455126,5006386,45057474,341149446,0002217471399,12565671261,62828356305),
(1,60,1770,34220,487635,5461512,50063860,386206920,0002558620845,14783142660,75394027566),
(1,61,1830,35990,521855,5949147,55525372,436270780,0002944827765,17341763505,90177170226),
(1,62,1891,37820,557845,6471002,61474519,491796152,0003381098545,20286591270,107518933731),
(1,63,1953,39711,595665,7028847,67945521,553270671,0003872894697,23667689815,127805525001),
(1,64,2016,41664,635376,7624512,74974368,621216192,0004426165368,27540584512,151473214816),
(1,65,2080,43680,677040,8259888,82598880,696190560,0005047381560,31966749880,179013799328),
(1,66,2145,45760,720720,8936928,90858768,778789440,0005743572120,37014131440,210980549208),
(1,67,2211,47905,766480,9657648,99795696,869648208,0006522361560,42757703560,247994680648),
(1,68,2278,50116,814385,10424128,109453344,969443904,07392009768,49280065120,290752384208),
(1,69,2346,52394,864501,11238513,119877472,1078897248,8361453672,56672074888,340032449328),
(1,70,2415,54740,916895,12103014,131115985,1198774720,9440350920,65033528560,396704524216),
(1,71,2485,57155,971635,13019909,143218999,1329890705,010639125640,074473879480,461738052776),
(1,72,2556,59640,1028790,13991544,156238908,1473109704,11969016345,085113005120,536211932256),
(1,73,2628,62196,1088430,15020334,170230452,1629348612,13442126049,097082021465,621324937376),
(1,74,2701,64824,1150626,16108764,185250786,1799579064,15071474661,110524147514,718406958841),
(1,75,2775,67525,1215450,17259390,201359550,1984829850,16871053725,125595622175,828931106355),
(1,76,2850,70300,1282975,18474840,218618940,2186189400,18855883575,142466675900,954526728530),
(1,77,2926,73150,1353275,19757815,237093780,2404808340,21042072975,161322559475,1096993404430),
(1,78,3003,76076,1426425,21111090,256851595,2641902120,23446881315,182364632450,1258315963905),
(1,79,3081,79079,1502501,22537515,277962685,2898753715,26088783435,205811513765,1440680596355),
(1,80,3160,82160,1581580,24040016,300500200,3176716400,28987537150,231900297200,1646492110120));


Procedure CSN2COMB(L,N,K :int64;Var DrawBuf);

{ Generates combination for given index and places it in DrawBuf }

Var

Range, Number, Prev, S, K2:int64;

Buf : Array[0..0] Of Byte Absolute DrawBuf;

Begin

Dec(N); Dec(K);

Range:=N;

K2 := K;

While K>=0 Do Begin

S:=0; Prev:=0;

While S<L Do Begin

Prev:=S;

S:=S + Combinations[N,K];

Dec(N);

End;

Number:=Range-N;

Buf[K2-K] := Number;

L:=L-Prev;

N:=Range-Number;

Dec(K)

End;

End;


Function COMB2CSN(Const DrawBuf; Const N,K:integer): int64;

{ Returns index of combination stored in DrawBuf }

Var

Counter: integer;

Index: int64;

Buf : Array[1..1] Of Byte Absolute DrawBuf;

Begin

Index := Combinations[N,K];

For Counter := K Downto 1 Do

If (N - Buf[Counter]) > (K - Counter) Then

Index := Index - Combinations[N - Buf[Counter],(K + 1) - Counter];

Result := Index;

End;

Const

N = 80; { max 80 Liczb}

K = 4; { max 10 skreslen }

Var

Draw : Array[1..K] Of Byte;
NK:int64;


--- wpis edytowano 2020-05-08 19:34 ---

2020-05-08 (19:40)

status 777ch
Data rejestracji: 2005-11-07 00:00:00
Ilość postów: 22655

1386
wpis nr 1 291 345
[ CZCIONKA MONOSPACE ]

sindbad
pisze .........

1 to koza a 12 to byk

i to jest to
.....proste jak rogalik
ale tak tłumaczyć potrafi tylko mistrz

ale to mi nie jest akuratnie potrzebne .........
2020-05-08 (19:59)

status Lottonauta
Data rejestracji: 2012-09-03 00:00:00
Ilość postów: 3147

13559
wpis nr 1 291 357
[ CZCIONKA MONOSPACE ]

Sidbad

Po analizie kodu już co nieco się zorientowałem, o co biega i...
też bym to tak zrobił, czyli w o oparciu o trójkąt Pascala.
Czy to jest za wolne dla ciebie?

Pozdrawiam
Na tą chwilę nie mam pomysłu na coś szybszego dla tak dużej wartości n nad k.
2020-05-08 (20:04)

status Lottonauta
Data rejestracji: 2012-09-03 00:00:00
Ilość postów: 3147

13559
wpis nr 1 291 361
[ CZCIONKA MONOSPACE ]

@777ch

> 1. Potrafisz przełożyć procedury pisane w Vba na C lub C++ --> ?
> 2. Potrafisz przełożyć procedury pisane w paskal object na C lub C++ --> ?


Nie wiem bo to są "patologiczne odnogi" Basia i Pascala
... daj próbkę kodu.
Jak to będzie podobne do standardowego Basia i Pascala to pewnie tak.

Pozdrawiam

--- wpis edytowano 2020-05-08 20:05 ---

2020-05-08 (20:26)

status sindbad
Data rejestracji: 2008-10-13 00:00:00
Ilość postów: 20531

3794
wpis nr 1 291 373
[ CZCIONKA MONOSPACE ]

Lottonauta, sprawdzę czy jest wolne dla mnie i wtedy odpowiem.

LEO, jeśli trzeba rozszyfrować, co procedura ma zrobić to jest trudno, ale jeśli wiesz, co procedura ma zrobić to jest łatwo.
2020-05-08 (20:51)

status 777ch
Data rejestracji: 2005-11-07 00:00:00
Ilość postów: 22655

1386
wpis nr 1 291 388
[ CZCIONKA MONOSPACE ]

Sindbad
ja wiem co ma procedura robić
ale.......
można wykonać zadanie na wiele sposobów
nie koniecznie jak sobie autor.......wykoncepował

Lottonauta
jak pogadamy z fair_play i się zgodzi na udostępnienie
to zamieszczę procedurę do przetłumaczenia
tyle że to jeden krok w .........procesie obliczeń
ale --> ten najważniejszy ....... bo odpowiada za czas sprawdzenia
a czas..........to wszystko......... co mamy

--- wpis edytowano 2020-05-08 20:51 ---

2020-05-08 (21:39)

status 777ch
Data rejestracji: 2005-11-07 00:00:00
Ilość postów: 22655

1386
wpis nr 1 291 409
[ CZCIONKA MONOSPACE ]

function Combination(cz, rz: Cardinal): int64;
var
iz,kfz: Cardinal;
uz, dz: Double;
begin
uz:=cz;kfz:=1;
dz := rz;
for iz := rz-1 downto 1 do
begin
uz:=uz*(cz-kfz);
dz := dz*iz;
kfz:=kfz+1;
end;
Result := Round(uz /dz);

end;






procedure TForm1.Button45Click(Sender: TObject); //farplay sprawdzanie gwar6
var
gwreal:real;
ilegen, i, y, brak,brak6 ,adres :integer;
adr0, adr1, adr2, adr3, adr4, adr5, adr6, a, adres_tmp:integer;
l1, l2, l3, l4, l5, l6 : Byte ;
g, x1, x2, x3, x4, x5, x6, os : Byte ;
pok4:int64;
Freq, TimeStart, TimeEnd: Int64;

begin

clear6fairplay(Sender); //wyzeruj maskę

os := spinedit3.value; // to zmienna dla V
g := spinedit1.value; // to zmienna dla ile skreśleń
ilegen:=spinedit2.Value; //to zmienna dla ilośc kombinacji do sprawdzenia
pok4:= Combination(os,6); // liczba wszystkich kombinacji 6-ek
if os>97 then form1.memo8.Lines.Add('....V=MAX=[97] >dla hit[6] ....przerywam.....');
if os>97 then exit;
if pok4>999999999 then form1.memo8.Lines.Add('....MASKA >9999999 ....przerywam.....');
if pok4>999999999 then exit;

adr0 := Combination(os, 6); // to samo... liczba wszystkich kombinacji 6-ek
brak:=0;
brak6:=0;

if QueryPerformanceFrequency(Freq) then
begin
QueryPerformanceCounter(TimeStart); //odliczamy czas


//-------------------------- zaczynamy zabawę
For y := 1 To ilegen do begin //lecimy od pierwszej kombinacji doostatniej

//-------------------------- jedziemy liczba1
For x1 := 1 To g - 5 do begin //lecimy od 1-ej liczby do ostatniej -5
l1 := tabrand[y][x1]; //mat(y, x1) to tablica tabrand
If (os - l1) > 5 Then begin
adr1 := adr0 - Combination(os - l1, 6) ;//instrukcja adresu->1
end
else
begin
adr1 := adr0 ;
end;//endif

//-------------------------- jedziemy liczba2
For x2 := x1 + 1 To g - 4 do begin //lecimy od 2-ej liczby do ostatniej -4
l2 := tabrand[y][x2]; //mat(y, x2) to tablica tabrand
If (os - l2) > 4 Then begin
adr2 := adr1 - Combination(os - l2, 5) ;//instrukcja adresu->2
end
else
begin
adr2 := adr1;
end;//endif
//-------------------------- jedziemy liczba3
For x3 := x2 + 1 To g - 3 do begin //lecimy od 3-ej liczby do ostatniej -3
l3 := tabrand[y][x3]; //mat(y, x3) to tablica tabrand
If (os - l3) > 3 Then begin
adr3 := adr2 - Combination(os - l3, 4);//instrukcja adresu->3
end
else
begin
adr3 := adr2;
end;//endif
//-------------------------- jedziemy liczba4
For x4 := x3 + 1 To g - 2 do begin //lecimy od 4-ej liczby do ostatniej -2
l4 := tabrand[y][x4];
If (os - l4) > 2 Then begin
adr4 := adr3 - Combination(os - l4, 3);//instrukcja adresu->4
end
else
begin
adr4 := adr3;
end;//endif
//-------------------------- jedziemy liczba5
For x5 := x4 + 1 To g - 1 do begin //lecimy od 5-ej liczby do ostatniej -1
l5 := tabrand[y][x5];
If (os - l5)> 1 Then begin
adr5 := adr4 - Combination(os - l5, 2); //instrukcja adresu->5
end
else
begin
adr5 := adr4;
end;//endif
//-------------------------- jedziemy liczba6
For x6 := x5 + 1 To g do begin //lecimy od 6-ej liczby do ostatniej
l6 := tabrand[y][x6];
adr6 := adr5 - (os - l6);
maska[adr6]:= 1 ;
end;end;end;end;end;end;end;







// no ......teraz braki lecimy
brak := 0 ;
For y := 1 To adr0 do begin
If maska[y] > 0 Then inc(brak);
end;

brak6:=pok4-brak ;

gwreal := (pok4 - brak6) / adr0*100;

//kończymy zatrzymujemy czas i wypisujemy gwarancje ect
QueryPerformanceCounter(TimeEnd);

end;


edit8.Text:=inttostr(brak6) ;
memo6.Lines[0]:=('-- Gwar.6 if [6] --test Fairplay');
memo6.Lines[2]:=('Brak {'+INTTOSTR(brak6) +'}');
memo6.Lines[3]:=('Sprawdzono zbiór = '+inttostr(pok4)+' kombinacji');
memo6.Lines[4]:=('Gwar..[6]= '+floattostr(gwreal)+' %');

memo6.Lines[12]:=('Time calculated : ' +
FloatToStr(((TimeEnd - TimeStart) / 1000)) + ' ms..by fairplay');


memo6.Lines[1]:= 'C('+spinedit3.Text+','+spinedit1.Text+','+spinedit10.Text +','+spinedit4.Text +')='+ floattostr(gwreal)+' % brak[' +inttostr(pok4-brak)+']' ;
end;

memo6.Lines[1]:= 'C('+spinedit3.Text+','+spinedit1.Text+','+spinedit10.Text +','+spinedit4.Text +')='+ floattostr(gwreal)+' % brak[' +inttostr(pok4-brak)+']' ;
end;




Sindbad
możesz to .......przyspieszyć ?
ja w Ciebie --> wierzę
ale w paskalu proszę ....... gdyby się udało......a tak zapewne będzie
bo c niezbyt .......... kumam

--- wpis edytowano 2020-05-08 21:43 ---

2020-05-08 (23:06)

status 777ch
Data rejestracji: 2005-11-07 00:00:00
Ilość postów: 22655

1386
wpis nr 1 291 441
[ CZCIONKA MONOSPACE ]

no gdybyś Sindbad zechciał
przelecieć to z grubsza
mając na uwadze to iż proces
wykonuje się proporcjonalnie
szybciej.. w przypadku wzrostu V i wzrostu k
w stosunku do możliwości
zastosowania odwołania do tablic 6d 🤔
2020-05-09 (21:34)

status sindbad
Data rejestracji: 2008-10-13 00:00:00
Ilość postów: 20531

3794
wpis nr 1 291 640
[ CZCIONKA MONOSPACE ]

Leo, nie chce mi się.

Potrzebne mi szybkie adresowanie kombinacji.

Sprawdziłem naocznie metodę Amadeusa, Dylonga i moją.
Amadeusa najbardziej bezpieczna(szybka).
Dylonga uniwersalna(wolna).
Moja najszybsza(ani bezpieczna ani uniwersalna).

Wszystkie robią to tak samo no, bo inaczej nie idzie, ale różnice widać.





--- wpis edytowano 2020-05-09 21:43 ---

2020-05-10 (02:43)

status 777ch
Data rejestracji: 2005-11-07 00:00:00
Ilość postów: 22655

1386
wpis nr 1 291 685
[ CZCIONKA MONOSPACE ]

Hej Sindbadzie
Rozumiem ,przy okazji dziś
jak to przeczytasz ........
to mi podaj proszę
--> czas weryfikacji 5-ek Multi po [12387-los.]
według Twojej procedury --> tej najszybszej
--> stan na wczoraj

Brak {8420}
Sprawdzono zbiór = 24040016 kombinacji
Gwar..[5]= 99,9649750649084 %
Time calculated : 6994 ms
=> 6,994 Sekund

u Ciebie ?
samo sprawdzenie bez wypisu 5-ek

miłego dnia

--- wpis edytowano 2020-05-10 02:43 ---

| Dodaj wpis w tym temacie | Spis tematów | Wyniki lottoStrona: 1 2 ... 14 15 16 17 18 19
Wyślij wiadomość do admina