Skip to content

Added the task of Josephus#16

Open
cutenti wants to merge 5 commits intomainfrom
6_counting_cycle_list
Open

Added the task of Josephus#16
cutenti wants to merge 5 commits intomainfrom
6_counting_cycle_list

Conversation

@cutenti
Copy link
Owner

@cutenti cutenti commented Dec 24, 2025

No description provided.

printf("Killed sicarium of number %d\n", currSicarium->data);
toKillNumber = currSicarium->data;
currSicarium = currSicarium->next;
kill(list, toKillNumber);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет, так не пойдёт. Нужно воспользоваться тем, что список циклический, а не вычислять заранее индекс нужного элемента.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что это значит?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно замкнуть список в кольцо, а потом ходить по нему и на каждом k-м шаге убивать воина. А Вы сначала отдельно вычисляете индекс воина, которого нужно убить, а затем ищете его в списке.
Да ещё не по индексу, а по значению. А если будет несколько воинов с одинаковым значением?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а смысл от войнов с одинаковым значением? их значение - их изначальный номер, их индекс. а иначе как запомнить, какой был номер у выжившего война?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Конечно, в этой задаче смысла от воинов с одинаковым значением никакого. Просто, удалять элементы списка по значению, когда можно получить указатель -- не самая лучшая идея.

Comment on lines 92 to 102
prevSicarium->next = currSicarium->next;

list->count--;
toKill = currSicarium;
currSicarium = currSicarium->next;

if (prevSicarium == list->tail) {
list->head = toKill->next;
} else if (toKill == list->tail) {
list->tail = prevSicarium;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет, всё ещё не то. Вы просто скопировали код из kill сюда. А надо сделать так: в цикле идти по списку (в явном виде, не просто увеличивать счётчик), и на нужном шаге удалять элемент. Подсказка: правильная реализация занимает строчек 5, без вызова каких-либо функций.

@cutenti cutenti force-pushed the 6_counting_cycle_list branch from 3c24bb1 to 4dd27df Compare December 25, 2025 21:47
Comment on lines +80 to +98
while (list->count > 1) {
k++;

if (k == m) {
toKill = list->head;

list->tail->next = list->head->next;

list->count--;
list->head = list->head->next;

free(toKill);

k = 0;
continue;
}
list->tail = list->head;
list->head = list->head->next;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень необычное решение. У Вас получилось, что сикарии не воспользовались считалочкой, а начали водить хоровод вокруг револьвера, который на каждом m-м шаге стреляет в одно и то же место, как в детской игре со стульчиками.
Пусть будет +1 балл за изобретательность

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants