Skip to content

Instantly share code, notes, and snippets.

@Zaur-Lumanov
Created May 28, 2020 18:09
Show Gist options
  • Save Zaur-Lumanov/b86fa44f2bde412a5de869dd551f05ab to your computer and use it in GitHub Desktop.
Save Zaur-Lumanov/b86fa44f2bde412a5de869dd551f05ab to your computer and use it in GitHub Desktop.
Решение задачки (НУ Я ЖЕ СТУДЕНТ!!)
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