forked from macton/nintendo-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_01.c
86 lines (72 loc) · 1.45 KB
/
test_01.c
1
2
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
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "rand_ints.h"
void
encode( uint32_t* a, uint32_t* b, int size )
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
b[(i + j) / 32] ^= ( (a[i / 32] >> (i % 32)) & (a[j / 32 + size / 32] >> (j % 32)) & 1 ) << ((i + j) % 32); // Magic centaurian operation
}
}
}
void
print_32b( uint32_t a )
{
for (int i=31;i>=0;i--)
{
printf("%c",a&(1<<i)?'1':'0');
}
}
int
main( void )
{
int test_count = g_RandIntCount-1;
uint32_t* a = g_RandInts;
uint32_t b[ 2 * test_count ];
uint32_t count_a[ 64 ];
uint32_t count_b[ 64 ];
memset(b,0,test_count*2*sizeof(uint32_t));
memset(count_a,0,64*sizeof(uint32_t));
memset(count_b,0,64*sizeof(uint32_t));
for (int i=0;i<test_count;i++)
{
encode( &a[i],&b[i*2],32);
for (int j=0;j<32;j++)
{
if (a[i] & ( 1ULL<<j ))
{
count_a[j]++;
}
}
for (int j=0;j<32;j++)
{
if (a[i+1] & ( 1ULL<<j ))
{
count_a[32+j]++;
}
}
for (int j=0;j<32;j++)
{
if (b[(i*2)+0] & ( 1ULL<<j ))
{
count_b[j]++;
}
}
for (int j=0;j<32;j++)
{
if (b[(i*2)+1] & ( 1ULL<<j ))
{
count_b[32+j]++;
}
}
}
for (int j=0;j<64;j++)
{
printf("%d: %d %d %0.6f\n",j,count_a[j],count_b[j],(float)(count_a[j]*count_b[j])/(float)(count_a[j]*test_count));
}
return 0;
}