Я пытался перебрать вторую часть этой проблемы с помощью cuda.
Если вы не вошли в систему или не выполнили часть 1, во второй части нам нужно найти наименьшее значение для регистра A (остальные регистры изначально установлены в 0), чтобы программа вывела себя. Нам нужно создать quine.
Я новичок в cuda, и вот что я придумал. Через 10 минут программа ничего не выводит и останавливается. Программа корректно работает с образцами данных.
#include
#include
#include
#include
__device__ uintmax_t do_combo(uintmax_t i, uintmax_t A, uintmax_t B, uintmax_t C){
switch(i) {
case 0:
case 1:
case 2:
case 3: return i;
case 4: return A;
case 5: return B;
case 6: return C;
}
return i;
};
__global__ void cuda(){
enum instructions_names {
adv,
bxl,
bst,
jnz,
bxc,
out,
bdv,
cdv
};
uintmax_t instructions[16] = {2,4,1,7,7,5,0,3,4,0,1,7,5,5,3,0};
uintmax_t i_len = 16;
/*uintmax_t instructions[6] = {0,3,5,4,3,0};*/
/*uintmax_t i_len = 6;*/
uintmax_t output[16];
uintmax_t output_len = 0;
uintmax_t step = 10000*(blockIdx.x * blockDim.x + threadIdx.x);
uintmax_t stop = step + 10000;
for (;step < stop; step++) {
output_len = 0;
uintmax_t A = step;
uintmax_t B = 0;
uintmax_t C = 0;
for (uintmax_t i = 0; i < i_len; i+=2) {
if (output_len > 16) return;
switch (instructions[i]) {
case adv: {
/* takes combo operand, divides A by 2^it into B */
A = A >> do_combo(instructions[i+1], A, B, C);
continue;
}
case bxl: {
/* takes literal operand, XORs B and it into B */
B = B ^ instructions[i+1];
continue;
}
case bst: {
/* takes combo operand, modulo 8 into B */
B = do_combo(instructions[i+1], A, B, C) % 8;
continue;
}
case jnz: {
/* takes literal operand, jumps to it if non null */
if (A == 0) continue;
i = instructions[i+1] - 2;
continue;
}
case bxc: {
/* ignores operand, XOR B and C into B */
B = B ^ C;
continue;
}
case out: {
/* takes combo operand, outputs it modulo 8 */
output[output_len++] = do_combo(instructions[i+1], A, B, C) % 8;
continue;
}
case bdv: {
/* takes combo operand, divides A by 2^it into B */
B = A >> do_combo(instructions[i+1], A, B, C);
continue;
}
case cdv: {
/* takes combo operand, divides A by 2^it into C */
C = A >> do_combo(instructions[i+1], A, B, C);
continue;
}
}
}
if (i_len != output_len) return;
for (uintmax_t i = 0; i < i_len; i++) {
if (instructions[i] != output[i]) return;
}
printf("%lu\n", step);
asm("trap;");
}
}
int main(){
unsigned int threads = 1024;
unsigned int all = 300000000000/threads;
cuda();
cudaDeviceSynchronize();
cudaError_t error = cudaGetLastError();
if (error != cudaSuccess) {
printf("CUDA error: %s\n", cudaGetErrorString(error));
}
}
Я пытался спросить в чатгпт, что не так с моим кодом, но он говорит ерунду.
Я пытался перебрать вторую часть этой проблемы с помощью cuda. Если вы не вошли в систему или не выполнили часть 1, во второй части нам нужно найти наименьшее значение для регистра A (остальные регистры изначально установлены в 0), чтобы программа вывела себя. Нам нужно создать quine. Я новичок в cuda, и вот что я придумал. Через 10 минут программа ничего не выводит и останавливается. Программа корректно работает с образцами данных. [code]#include #include #include #include
__device__ uintmax_t do_combo(uintmax_t i, uintmax_t A, uintmax_t B, uintmax_t C){ switch(i) { case 0: case 1: case 2: case 3: return i; case 4: return A; case 5: return B; case 6: return C; } return i; };
uintmax_t instructions[16] = {2,4,1,7,7,5,0,3,4,0,1,7,5,5,3,0}; uintmax_t i_len = 16; /*uintmax_t instructions[6] = {0,3,5,4,3,0};*/ /*uintmax_t i_len = 6;*/ uintmax_t output[16]; uintmax_t output_len = 0; uintmax_t step = 10000*(blockIdx.x * blockDim.x + threadIdx.x); uintmax_t stop = step + 10000; for (;step < stop; step++) { output_len = 0; uintmax_t A = step; uintmax_t B = 0; uintmax_t C = 0; for (uintmax_t i = 0; i < i_len; i+=2) { if (output_len > 16) return; switch (instructions[i]) { case adv: { /* takes combo operand, divides A by 2^it into B */ A = A >> do_combo(instructions[i+1], A, B, C); continue; } case bxl: { /* takes literal operand, XORs B and it into B */ B = B ^ instructions[i+1]; continue; } case bst: { /* takes combo operand, modulo 8 into B */ B = do_combo(instructions[i+1], A, B, C) % 8; continue; } case jnz: { /* takes literal operand, jumps to it if non null */ if (A == 0) continue; i = instructions[i+1] - 2; continue; } case bxc: { /* ignores operand, XOR B and C into B */ B = B ^ C; continue; } case out: { /* takes combo operand, outputs it modulo 8 */ output[output_len++] = do_combo(instructions[i+1], A, B, C) % 8; continue; } case bdv: { /* takes combo operand, divides A by 2^it into B */ B = A >> do_combo(instructions[i+1], A, B, C); continue; } case cdv: { /* takes combo operand, divides A by 2^it into C */ C = A >> do_combo(instructions[i+1], A, B, C); continue; } } } if (i_len != output_len) return; for (uintmax_t i = 0; i < i_len; i++) { if (instructions[i] != output[i]) return; } printf("%lu\n", step); asm("trap;"); } }
int main(){ unsigned int threads = 1024; unsigned int all = 300000000000/threads; cuda(); cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { printf("CUDA error: %s\n", cudaGetErrorString(error)); } } [/code] Я пытался спросить в чатгпт, что не так с моим кодом, но он говорит ерунду.
Я пытался перебрать вторую часть этой проблемы с помощью cuda.
Если вы не вошли в систему или не выполнили часть 1, во второй части нам нужно найти наименьшее значение для регистра A (остальные регистры изначально установлены в 0), чтобы программа...
Я пытался перебрать вторую часть этой проблемы с помощью cuda.
Если вы не вошли в систему или не выполнили часть 1, во второй части нам нужно найти наименьшее значение для регистра A (остальные регистры изначально установлены в 0), чтобы программа...
Я пытался перебрать вторую часть этой проблемы с помощью cuda.
Если вы не вошли в систему или не выполнили часть 1, во второй части нам нужно найти наименьшее значение для регистра A (остальные регистры изначально установлены в 0), чтобы программа...
Поэтому я совсем забыл о появлении кода и пытаюсь помочь своему другу сделать это в этом году. Мои питоны немного подзаржавели, и я пытаюсь соответствовать ее уровню навыков, поэтому не могу использовать многие сложные методы (без лямбда-функций и...