ParlamenT P ParlamenT Регистрация 18 Дек 2013 Сообщения 99 Репутация 0 Спасибо 0 Монет 0 3 Май 2025 #1 Помогите с python пожалуйста, нужно сделать код для этой задачи, нейросети не помогают
warface1111 W warface1111 Регистрация 18 Дек 2013 Сообщения 78 Репутация 0 Спасибо 1 Монет 0 3 Май 2025 #2 def solve_chips(N): operations = [] def move: if n == 1: operations.append(1) else: move(n - 1) operations.append move(n - 1) move(N) return operations N = int(input()) operations = solve_chips(N) print(' '.join(map(str, operations)))
def solve_chips(N): operations = [] def move: if n == 1: operations.append(1) else: move(n - 1) operations.append move(n - 1) move(N) return operations N = int(input()) operations = solve_chips(N) print(' '.join(map(str, operations)))
ыввы Ы ыввы Регистрация 8 Ноя 2013 Сообщения 92 Репутация 0 Спасибо 0 Монет 0 3 Май 2025 #3 они обиделись на тебя?
kypa5 K kypa5 Регистрация 8 Авг 2013 Сообщения 76 Репутация 0 Спасибо 0 Монет 0 3 Май 2025 #4 Ща проверь: def solve(): n = int(input()) cells = [0] * n actions = [] def print_state(): print(f"Cells: {cells}" print(f"Actions: {actions}" def place_chip(cell_index): cells[cell_index] = 1 actions.append(cell_index + 1) def remove_chip(cell_index): cells[cell_index] = 0 actions.append(-(cell_index + 1)) def find_leftmost_chip_index(): for i in range: if cells == 1: return i return -1 if n == 1: place_chip(0) elif n == 2: place_chip(0) place_chip(1) elif n == 3: place_chip(0) place_chip(1) remove_chip(0) place_chip(2) place_chip(0) elif n == 4: place_chip(0) place_chip(1) remove_chip(0) place_chip(2) place_chip(0) place_chip(3) remove_chip(2) else: print("За отведенное количество ходов решение не найдено" return if all(cells): print(*actions) else: print("За отведенное количество ходов решение не найдено" solve()
Ща проверь: def solve(): n = int(input()) cells = [0] * n actions = [] def print_state(): print(f"Cells: {cells}" print(f"Actions: {actions}" def place_chip(cell_index): cells[cell_index] = 1 actions.append(cell_index + 1) def remove_chip(cell_index): cells[cell_index] = 0 actions.append(-(cell_index + 1)) def find_leftmost_chip_index(): for i in range: if cells == 1: return i return -1 if n == 1: place_chip(0) elif n == 2: place_chip(0) place_chip(1) elif n == 3: place_chip(0) place_chip(1) remove_chip(0) place_chip(2) place_chip(0) elif n == 4: place_chip(0) place_chip(1) remove_chip(0) place_chip(2) place_chip(0) place_chip(3) remove_chip(2) else: print("За отведенное количество ходов решение не найдено" return if all(cells): print(*actions) else: print("За отведенное количество ходов решение не найдено" solve()