- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
void swap(uint8_t *x, uint8_t *y)
{
uint8_t tmp;
tmp = *x;
*x = *y;
*y = tmp;
}
// эту хуйню тоже можно нагенерировать
uint64_t cmp_bits(uint8_t a[restrict 9])
{
return
((uint64_t)(a[0] < a[1]) << 0) |
((uint64_t)(a[0] < a[2]) << 1) |
((uint64_t)(a[0] < a[3]) << 2) |
((uint64_t)(a[0] < a[4]) << 3) |
((uint64_t)(a[0] < a[5]) << 4) |
((uint64_t)(a[0] < a[6]) << 5) |
((uint64_t)(a[0] < a[7]) << 6) |
((uint64_t)(a[0] < a[8]) << 7) |
((uint64_t)(a[1] < a[2]) << 8) |
((uint64_t)(a[1] < a[3]) << 9) |
((uint64_t)(a[1] < a[4]) << 10) |
((uint64_t)(a[1] < a[5]) << 11) |
((uint64_t)(a[1] < a[6]) << 12) |
((uint64_t)(a[1] < a[7]) << 13) |
((uint64_t)(a[1] < a[8]) << 14) |
((uint64_t)(a[2] < a[3]) << 15) |
((uint64_t)(a[2] < a[4]) << 16) |
((uint64_t)(a[2] < a[5]) << 17) |
((uint64_t)(a[2] < a[6]) << 18) |
((uint64_t)(a[2] < a[7]) << 19) |
((uint64_t)(a[2] < a[8]) << 20) |
((uint64_t)(a[3] < a[4]) << 21) |
((uint64_t)(a[3] < a[5]) << 22) |
((uint64_t)(a[3] < a[6]) << 23) |
((uint64_t)(a[3] < a[7]) << 24) |
((uint64_t)(a[3] < a[8]) << 25) |
((uint64_t)(a[4] < a[5]) << 26) |
((uint64_t)(a[4] < a[6]) << 27) |
((uint64_t)(a[4] < a[7]) << 28) |
((uint64_t)(a[4] < a[8]) << 29) |
((uint64_t)(a[5] < a[6]) << 30) |
((uint64_t)(a[5] < a[7]) << 31) |
((uint64_t)(a[5] < a[8]) << 32) |
((uint64_t)(a[6] < a[7]) << 33) |
((uint64_t)(a[6] < a[8]) << 34) |
((uint64_t)(a[7] < a[8]) << 35);
}
void printshit(uint8_t a[restrict 9])
{
size_t i = 0;
while(*a != 4)
{
a++;
i++;
}
printf("arr[%" PRIu64 "] = %zu\n", cmp_bits(a), i);
}
void permute(char *a, size_t l, size_t r)
{
size_t i;
if (l == r)
printshit(a);
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
permute(a, l+1, r);
swap((a+l), (a+i));
}
}
}
int main()
{
uint8_t a[] = {0,1,2,3,4,5,6,7,8};
size_t n = 9;
permute(a, 0, n-1);
return 0;
}