A small brain teaser for a weekend - 2 bit door counter. lazarus / 8-Other ---------------------------------------------------------------------- ArtLogi · 2016-01-23 00:55 Brainteasers size depends, it might be small or a bit bigger for someone else. Anyway. You have a door lets say a computer labs door, there is one door (if too simple make two door implementation, where another door and sensors are identical). That one door have lightbeam sensors, there is 2 ( two ) and only 2 of them in that door. They both are bolted to the nonmoving frame of the door at weist hight and beams are horizontally at same level. Like said they are installed side by side and lightbeams have 5 millimeter offset to each other (they are what they are, no physical solutions hacks here). Beams of those sensor go through the doorway so when someone walks from the door they both get interruption at somepoint. They both are boolean sensors one bit for each, so you have two bits of sensor information total( on/off, no serial data). When beam is blocked (person in the way) it gives TRUE. Make a program (no HW interfacing needs to implement of course, ie two tickboxes can act as a lightbeam sensors) that will keep track how many peoples are inside the room and total all time visitors. Program also needs to count which min and max speed the visitors have  gone through the doorway. Now to not make it too easy there is this one professor who usually stops middle of the doorway, when he are leaving or coming inside, starts to speak someone and stays there blocking both beams x minutes and then return at the same direction where he were coming never leaving the lab or never coming inside. The counter must still count correctly. EDIT: Sorry I did forget to mention one thing about the profs behavior. At times while stopped  smalltalk at middle of the doorway he actually continues where he were heading and will leave or enter the room. If you make two door implementation, the prof. use both and the sensors are identical on both. All four sensors are connected to same program. Don't post a solution right away, give others the enjoyment. ---------------------------------------------------------------------- Bart · 2016-01-23 10:52 Nice one! If the professor blocks the beams, but does not block the door, then to me it would seem this cannot be resolved, since any number of people then can pass the door in any direction, nnoticed by the sensors? The same argment can be made for 2 or more people passing the sensors with less than 5 mm of clearance. Whilst I agree, the nex one is nitpicking, given that the initial state of the room is not provided by you, the program can not determine how many people are there, only how many entered or left the room  Bart ---------------------------------------------------------------------- ArtLogi · 2016-01-23 12:24 This just shows how hard it is to write a good instructions.    Start condition is empty. People are not overlapping and the door is so narrow that professor blocks the whole path and moves away if someone needs to enter or leave the lab. Also there is no short growd who will walk below nor long folks who jump over... Like I said no physical hacks.  Some boolean logics, how many ifs do you need. ---------------------------------------------------------------------- Bart · 2016-01-23 13:20 OK, thanks for the clarification. However: Now, when I walk hand in hand with my girlfriend in or out of the door (one in front of the other), and our hands are in the right height, then we will only trigger the signals once. If we do this when walking in, but not when walking out the system will crash, or give erroneous large answers, since undoubtedly whomever implemented it, did not use a signed data type for the "number of people in the room" variable, because the managers told them that there could never be such a thing as a negative amount of persons, so they should use an unsigned integer, so they could count more persons inside the room (the room is big) and using a 32-bit unsigned integer was cheaper than using a 64-bit signed integer. So: Q1: can we pass the door holding hands? Q2: are managers involved? If either of the questions is answered with "yes", then the puzzle cannot be solved. Bart ---------------------------------------------------------------------- ArtLogi · 2016-01-23 13:45 Q1: No, the door needs both hands to be operated Q2: Yes, but it is you that manage yourself. There is also UPS to keep it running if power gridd falls off. ---------------------------------------------------------------------- engkin · 2016-01-23 14:00 I would use two bytes (the lower five bits of each byte, actually) one byte for each sensor to keep track of the last five "activities" (where each sensor activity is recorded in one bit, recent activity in the lowest bit). Denoting outer sensor as OS (not confused with Operating System) and the inner sensor as IS (  ) When a person enters the room the sensors pass through the following sequences 01100 on OS. That is OS = 12 00110 on IS. IS = 6 Where 0 means nothing is blocking the sensor and 1 the sensor is blocked. When a person leaves the room the values are reversed: IS = 12, and OS = 6 ---------------------------------------------------------------------- Bart · 2016-01-23 14:02 Assuming both answers to my questions in my post above are "no", then: Build a simulator program, where we see "people" randomly entering or leaving the room: People are represented by a rectangle, it's width being 90% of the width of the door (no person is so obese that his/her width is smaller than his/her "front to back").The professor has a different color than all other persons.People cannot enter/leave the door sidewaysPeople leaving the room will disappear of the screen (so you need not bother about them)People entering the door will appear 'out of nowhere", just a little bit outside the door.Because of the Pauli exclusion principle, people cannotoccupy the smaespace.[The simulation does not require that the entire room is visible to the viewer./li] Nobody walks faster than Usain Bolt when passing the door.No more than 65536 persons can ever be inside the room (your simulation does not require there to ever be that amount of people though). Anybody trying to enter the room in this situation will be evaporated before he/she triggersany sensor.If you run the simulator indefinately, at some point in time there will be >= 10 persons inside the room.The simulator will show at all times:The state of both sensors.The number of persons inside the room.The number of persons that entered the room since the program started (AKA total number of visitors).The number of persons that left the room since the program started.The average walking speed of the last person entering/leaving (it is unknown wether the person has a constant speed when walking, so adjust for that).The presence or absence of the professor (since the viewers may be colorblind). Bart ---------------------------------------------------------------------- Bart · 2016-01-23 14:04 Quote from: engkin on January 23, 2016, 03:00:50 pmI would use two bytes (the lower five bits of each byte, actually) Read the instruction: the sensors only provide 2 bit of infromation,1 bit for each sensor. It's a state machine I guess. Bart ---------------------------------------------------------------------- engkin · 2016-01-23 14:10 Quote from: Bart on January 23, 2016, 03:04:13 pmQuote from: engkin on January 23, 2016, 03:00:50 pmI would use two bytes (the lower five bits of each byte, actually) Read the instruction: the sensors only provide 2 bit of infromation,1 bit for each sensor. That's why I would use two bytes. ---------------------------------------------------------------------- ArtLogi · 2016-01-23 15:40 @Bart: QuoteNo more than 65536 persons can ever be inside the room That is incorrect, there can be as many persons in that room that you have memory of your computer, the brainteaser didn't say anything about the inner construction, so with two integers you can have 65536 * 65536 persons inside the room. (Can not actually remember if that is correct value for integer, but close). Another words you are a bit sidetrack. For a quick look engkin seems on the other hand be in the right track... I have no solution directly front of me, but I have the sequence somewhere handwritten in piece of paper from the past it took two pints of beer back then and the implementation is still propably in that Mutsubishe logic at the top of the labs door. ---------------------------------------------------------------------- marcov · 2016-01-23 16:01 The principle is roughly the same as a quadrature encoder. First, don't sample on time based, but only register a modification if the state of a sensor changes. (in reality with a debounce circuit). That kills the complexity of the timeline; A state of 0 on both sensors restarts building of the mask. Then one going in is (assuming sensor 1 is on the outside, and on the inside) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 1:    011002:    00110   and going outside is Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 1:    00110  2:    01100 The professor comes from the inside, hits both sensors, but leaves the outside most before the innermost. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 1: 00100  2: 01110  Of course that could be inverse also when the same behaviour is from the hallway side (e.g. looking in, but not entering) So, professor like bitcount(1)<>bitcount(2) -> ignoreinside  is bitpattern 2>bitpattern 1 and (bitcount(1)=bitcount2)outside is bitpattern 2