Created
May 28, 2020 18:09
-
-
Save Zaur-Lumanov/b86fa44f2bde412a5de869dd551f05ab to your computer and use it in GitHub Desktop.
Решение задачки (НУ Я ЖЕ СТУДЕНТ!!)
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
class Fan { | |
constructor(levels) { | |
this.levels = levels | |
this.level = 1 | |
} | |
change() { | |
if (this.level < this.levels) { | |
++this.level | |
} else { | |
this.level = 0 | |
} | |
} | |
} | |
const check = clicks => { | |
const fans = [] | |
for (let i = 1; i <= 5; ++i) { | |
fans.push(new Fan(i)) | |
} | |
for (let i = 0; i < clicks; ++i) { | |
fans.forEach(fan => fan.change()) | |
} | |
return (fans.map(fan => fan.level)) | |
} | |
let levels = 0 | |
while (true) { | |
++levels | |
const result = check(levels) | |
const sum = result.reduce((a, b) => a + b) | |
if (!sum) { | |
console.log(`Для гарантированного отключения вентилятора надо нажать на кнопку ${levels} раз.`) | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment