Thinking on a “Momo” Headline Algorithm Question

  javascript, python

I accidentally saw a headline algorithm question on the pulse

clipboard.png

According to the understanding of the topic, I simply wrote an html webpage

<!  DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <title>pool</title>
 <meta name="viewport" content="width=device-width, initial-scale=1">
 </head>
 <body>
 <div id="vue_det">
 <div @click="SmartChange(0)" style="width:40px;  height:40px;  Background:#fff "> start < /div >
 <div class="pool" v-for="(item, index) in list">
 <div @click="change(index)" v-if="item" style="width:40px;  height:40px;  background:#999;  float:left">{{index}}</div>
 <div @click="change(index)" v-if="!  item" style="width:40px;  height:40px;  background:#fff;  float:left">{{index}}</div>
 </div>
 </div>
 
 <script src="https://cdn.bootcss.com/vue/2.6.4/vue.js"></script>
 <script>
 var vm = new Vue({
 el: '#vue_det',
 data: {
 list: [],
 i: 0
 },
 methods: {
 details: function () {
 Return this.site+"-what you learn is not only technology, but also dreams!"  ;
 },
 change (index) {
 // console.log(index)
 if (index === 99) {
 this.list[0] = !  this.list[0]
 this.list[98] = !  this.list[98]
 this.list[99] = !  this.list[99]
 } else if (index === 0) {
 this.list[0] = !  this.list[0]
 this.list[1] = !  this.list[1]
 this.list[99] = !  this.list[99]
 } else {
 // console.log('222')
 this.list[index] = !  this.list[index]
 this.list[index - 1] = !  this.list[index - 1]
 this.list[index + 1] = !  this.list[index + 1]
 }
 // console.log(this.list)
 this.list = JSON.parse(JSON.stringify(this.list))
 },
 SmartChange (index) {
 if (this.i === 99) {
 return false
 }
 if (this.list[this.i] === true) {
 this.i = this.i + 1
 setTimeout(() => {
 this.SmartChange()
 }, 10);
 } else {
 this.change(this.i + 1)
 setTimeout(() => {
 this.SmartChange()
 }, 10);
 }
 //   console.log('222222222',this.i)
 },
 go () {
 for (let index = 1;   index < 101;  index++) {
 this.list.push(Math.random() > 0.5 ?  true : false)
 }
 console.log(this.list)
 let a = 0, b = 0
 this.list.map(val => {
 if (val) {
 a++
 } else {
 b++
 }
 })
 console.log(a, b)
 }
 },
 created () {
 this.go()
 }
 })
 </script>
 </body>
 </html>

The following effect diagram is obtained

clipboard.png

图片描述

Get an example of the switch that can be made according to the question.

In the last lamp special treatment, link the first lamp to form a ring.

After testing, it was found that
As long as it starts from serial number 0, skip if it is on, and click i+1 if it is off.
The following results are obtained

图片描述

Knock on the blackboard

Now part of the conclusion is
Only when the random on/off lights are in a certain proportion can they all be turned on.

Now the feasible ratio is
On-Off 50-50
On-Off 51-49
On-Off 47-53
On-Off 44-56
On-Off 42-58
On-Off 53-47
On-Off 54-46

In addition, it is also decided by the turn-on and turn-off of the last lamp and the adjacent lamps.

Do you have any good ideas that you can leave for discussion?