python mockito arg_that_wqingxiao

偶然间在脉脉上看到了一道头条的算法面试题

按照题目的理解,简单的写了一个html网页

pool
开始
{{index}}
{{index}}

var vm = new Vue({

el: '#vue_det',

data: {

list: [],

i: 0

},

methods: {

details: function () {

return this.site + " - 学的不仅是技术,更是梦想!";

},

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()

}

})

得到了如下效果图

得到如题可以进行开关的示例在最后一个灯特殊处理,链接第一个灯,形成环

经过测试发现

只要从序号0开始,如果打开则跳过,如果是灭灯,则点击i+1

得到如下效果

敲黑板

现在得出的部分结论是

只有随机亮灭灯是一定比例的时候才有可能全部点亮

现在可行的比例为

亮-灭 50-50

亮-灭 51-49

亮-灭 47-53

亮-灭 44-56

亮-灭 42-58

亮-灭 53-47

亮-灭 54-46

而且,还决定于最后一个灯和相邻灯的亮灭大家有什么好想法,可以留下见解讨论下查看原文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值