| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 
 |  
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
//#include <iostream.h> //pour cout
typedef struct  {
                     int  n,  x, y;
                }statetype;  // définir ma propre type de variable
bool domR (statetype s) // faire un test sur le nombre aléatoire (n) 
{
    if  (!((s.n/2) % 2) ==1)
        return(true);
    else
        return(false);
}
bool R (statetype s, statetype sprime) // Le sprime est un nom de variable de type statetype . ici j'ai ecrit dans ce procédure la condition que les sorties(x,y) de chaque programme sur chaque n doit la verifier.
{
    if   ( s.n== pow(sprime.x,2)- pow(sprime.y,2) && 0<= sprime.y <= sprime.x)
{
 
        return(true);
}
    else
        return(false);
}
 
bool oracle (statetype s,  statetype sprime)
          {  return ! domR(s) || R(s,sprime) ;
 }                                       
 
 
 
void p1()
{unsigned int n, x, y; 
{unsigned int r;
x=0; y=0; r=0; 
while (r<n) {r=r+2*x+1; x=x+1;}}}
 
 
void p2() 
{unsigned  int n, x, y; // input/output variables
{unsigned  int r; x=0; r=0;
while (r<n) {r=r+2*x+1; x=x+1;}
   if (r>n) {y=0; while (r>n) {r=r-2*y-1; y=y+1;}}}}
 
 
 
void p3() 
{unsigned int n, x, y; // input/output variables
{unsigned int r; x=0; r=0; 
while (r<n) {r=r+2*x+1; x=x+1;}
while (r>n) {int rsave; y=0; rsave=r;
while (r>n) {r=r-2*y-1; y=y+1;}
   if (r<n) {r=rsave+2*x+1; x=x+1;}}}}
 
 
   //------------------------------------------------------------------
int randomgeneration(int n)
{
    int partSize   = 1 + (n == RAND_MAX ? 0 : (RAND_MAX - n) / (n + 1));
    int maxUsefull = partSize * n + (partSize - 1);
    int draw;
 
    do {
        draw = rand();
    } while (draw > maxUsefull);
 
    return draw / partSize;
}
//---------------------------------------------------------------------
void tesdriver(int testdatasize)
{int c1=0; // compteur qui s'incrémente chaque fois que les résultats fourni par le programme satisfait la condition qui est exprimée dans le procedure bool R(N=x2-y2)et (0<=y<x)
int c2=0;
int c3=0;
 
int testindex=1; 
 
while (testindex <= testdatasize)
{
 
statetype inits,s, sprime;  
 
inits.n=randomgeneration(10000);
 
//P1 
 
s=inits;
p1();
if (oracle(inits,s)) {c1=c1+1;}
printf("n : %d \t" , inits);
printf("counter p1 : %d \t" , c1);
 
 
// P2
 
s=inits;
p2();
if (oracle(inits,s)) {c2=c2+1;}
printf("n : %d \t" , inits);                                    
printf("counter p2 : %d \t" , c2);
 
 
//P3
s=inits;
p3();
if (oracle(inits,s)) {c3=c3+1;}
printf("n : %d \t" , inits);                                
printf("counter p3 : %d \t" , c3);
 
testindex ++;
 
}
 
//printf("\nc1=%d\t",c1);
//printf("c2=%d\t",c2);
//printf("c3=%d\t",c3);
//printf("reliability of p1 : %f \t" , float (c1)/float (testdatasize));
cout << "reliability of p1 : " << float (c1)/ float(testdatasize) << endl ; // calcul de realiabilité 
//printf("reliability of p2 : %f \t" , float (c2)/float (testdatasize));
cout << " reliability of p2 : " << float (c2)/ float(testdatasize) << endl ;
//printf("reliability of p3 : %f \t" , float (c3)/float (testdatasize));
cout << " reliability of p3 : " << float (c3)/ float(testdatasize)  << endl ;
}
int main()
{
    tesdriver(4000);
} | 
Partager