1-100 までの裏返しのカードが裏返しの状態で並んでます
2 枚目から 1 枚おき(+2枚目)に最後まで裏返します。
次は 3 枚目から 2 枚おき(+3枚目)に最後まで…繰り返したとき裏のままの番号を答えましょう

プログラマ脳を鍛える数学パズル シンプルで高速なコードが書けるようになる70問
- 作者: 増井敏克
- 出版社/メーカー: 翔泳社
- 発売日: 2015/10/14
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (11件) を見る
出題意図は単純にインデックが 0 開始だってことに騙されないかどうかの問題な気がする。
open_cards = [False for n in range(100)] for step in range(2, 100): index = step - 1 while index < 100: open_cards[index] = not open_cards[index] index += step index = 0 close_indexes = [] for is_opened in open_cards: index += 1 if not is_opened: close_indexes.append(index) print(close_indexes)