Last active
January 24, 2017 11:22
-
-
Save kuronekomichael/7357e2aad38655adaeeff09a1fdd0eba to your computer and use it in GitHub Desktop.
数学パズル Q.3(page=21)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const N = 100; | |
// 裏返しのカードを100枚生成 | |
const cards = Array.from({length: N}, (_unused, index) => { | |
return { is_reversed: true, number: index + 1}; | |
}); | |
// n枚目から、n+1枚ごとにフリップする(n >= 2) | |
for (let i = 1; i < cards.length; i++) { | |
for (let j = i; j < cards.length; j += (i + 1)) { | |
cards[j].is_reversed = !cards[j].is_reversed; | |
} | |
} | |
// 裏返し状態のカード番号を出力 | |
console.log(cards.filter((card) => card.is_reversed).map((card) => card.number).join(', ')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
問題文の日本語が分かりにくいとおもいました…。
たぶんもうちょっと分かりやすい問題にすると、正解までの時間はすごく短縮されそうな気がします 😓