Skip to main content
  1. Posts/

Light Switches

·1 min·
Table of Contents

A Practical Guide To Quantitative Finance Interviews 收录了一些量化面试中的经典题目. 本文介绍的是来自第二章的「Light Switches」.

Light Switches #

Problem #

There is a light bulb inside a room and four switches outside.All switches are currentlyat off state and only one switch controls the light bulb. You may turn any number of switches on or off any number of times you want. How many times do you need to gointo the room to figure out which switch controls the light bulb?

Solution #

解决重点在于二进制. 官方给的解答如下: 灯泡有亮灭的状态, 除此之外亮的时间长了会发热, 又有冷热两种状态. 打开开关 1 和 2, 过一段时间后关闭 2 打开 3, 然后立刻进入房间中查看灯泡.

  • 亮, 热: 开关 1
  • 亮, 冷: 开关 3
  • 灭, 热: 开关 2
  • 灭, 冷: 开关 4