This commit is contained in:
2025-12-09 22:45:53 +01:00
parent 222aecb34e
commit 0b575ca524
2 changed files with 1 additions and 28 deletions

Binary file not shown.

View File

@@ -31,18 +31,13 @@ int main(int argc, char* argv[]) {
printf("error: no such file %s\n", inpf);
return 1;
}
printf("first position: %d\n", pos);
// process instructions
char line[9]; // 8 chars + eol
while(fscanf(ptr, "%9s", line) == 1) {
char drc = line[0];
int num = atoi(&line[1]);
printf("%c %d\n", drc, num);
//if (drc == 'R') pos += num;
//if (drc == 'L') pos -= num;
//printf("%c %d\n", drc, num);
if (drc == 'R') {
for(int i = 0; i < num; i++) {
@@ -51,7 +46,6 @@ int main(int argc, char* argv[]) {
} else {
pos += 1;
pos -= 100;
//printf("overflow -=100\n");
}
if (pos == 0) counter++;
}
@@ -68,29 +62,8 @@ int main(int argc, char* argv[]) {
if (pos == 0) counter++;
}
}
while (pos > 99) {
//pos -= 100;
for (int i = 0; i < 100; i++) {
if (pos == 0) counter++;
pos -= 1;
}
}
while (pos < 0){
//pos += 100;
for (int i = 0; i < 100; i++) {
if (pos == 0) counter++;
pos += 1;
}
}
//if (pos == 0) counter++;
printf("current position: %d\n", pos);
printf("counter is: %d\n", counter);
}
//printf("current position: %d\n", pos);
printf("\npassword is: %d\n", counter);
return 0;
}