Ali Technical Salon Discussion Questions

Source: Internet
Author: User

Original topic:

There is a building, there are many rooms in the building, each room has a lamp and a switch, this switch can control the lamp, in addition to each room also has two different color LED lights

There is a remote control, there are two buttons on the remote control, each button controls all rooms of an LED light.

Similar to Tetris, when each room light is lit, as a block, please design a method using the remote control a block of the whereabouts of the process.

In addition to intelligent communication equipment, the tool is optional, the whereabouts of the block is only related to the time, each room by a person to control the lights open and close, downstairs there is a person to use the remote control

Analysis:

This topic is really more complicated, but we can see two videos:
Living in a dorm building: http://v.youku.com/v_show/id_XMzg0MTUwMTI=.html

Dorm Building play Tetris: http://v.youku.com/v_show/id_XMTAyMjk4Mjg0.html

The technical solution given here cannot be too complicated, it must be simple, and everyone in the room can understand what they are doing.

For this topic can be analyzed: because the block drop is only related to the time, then assume that the block drops once per second, so that you can use a clock (stopwatch) to record the current block on the first layer, so you need to configure a clock for each room.
Since there can only be one room light on each time, so if using the remote control of the next light, the last light must be dimmed, so the building can be placed in a coordinate system, and then to each room corresponding to a coordinate system of the horizontal and vertical coordinates.
Since the design of the scheme must be simple and feasible, everyone in the room should be able to understand, so set the variable can not be too much.

According to the above analysis, the design is as follows: The room of the upper left corner of the Wendy is set to the origin of the plane coordinate system (O), each room width and length is 1, then the top-level room coordinates from left to right are (0,0), (0,1), (0,2), and so on, the penultimate room coordinates from left to right (1,0), ( (), etc...
For a high 3-storey Wendy with 4 rooms per floor, the coordinates of each room are shown in the following figure:


Assuming that at the beginning, the coordinates for (0,0) room lights, set a global variable m to record the current switch in the horizontal axis, assuming that the LED lights in each room is divided into two, then the left led light once m minus 1, when it is 0 o'clock, continue to light the left led light, m value unchanged, The LED on the right is lit once m plus 1, when M is the width of the Wendy minus 1 o'clock (that is, the maximum of the horizontal axis), continue to light the right LED lights, the M value is unchanged, all the room people recorded this m value.

Block per second to drop a layer, so in the No. 0 second to the first 1 seconds, the room number ordinate 0 of the room in a tense state, when the M value and their horizontal axis at the same time, bright lights, otherwise off the lights. For each room in the building, the second value of the clock and its own ordinate the same, m-value and their horizontal axis at the same time, lights, or lights off.

This way the people downstairs can control the drop of a block simply by using the remote controller.

With the topic of the exchange of some, the original intention is not required to use the program to achieve, but to examine the ability of people to do the program, the purpose is to let everyone put the computer world logic, extend to the real world. Indeed, from the real world to the computer world needs abstraction, this part is done well, this is a kind of ability, in turn, if the computer world logic applied to the real world, then things in the real world will become easy, which may be all things are figured out this way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.