Today’s puzzle is tricky! I mean trickle-y. It is each astir streams.
The root of the puzzle is simply a ‘streaming algorithm’, which is simply a benignant of process successful machine subject that analyses information arsenic it arrives successful a stream, alternatively than waiting for the information to beryllium stored successful a memory.
The archetypal streaming algorithms were devised successful the 1980s. The thought down them was to get an wide readout of incoming information arsenic accelerated arsenic possible, utilizing arsenic small representation arsenic possible. Since information streams are ubiquitous successful the integer satellite – telephone calls, recognition paper transactions and Netflix movies, for example, are each information streams – this benignant of algorithm is too.
You are astir to conscionable 1 of the astir important aboriginal streaming algorithms. Well, you are if you lick today’s puzzle. Buffering now!
The large ballot brainteaser
An predetermination is held betwixt candidates A, B, C and D. You are fixed a acceptable of 100 completed ballot papers and your occupation is to enactment retired whether immoderate of the candidates has an wide majority, i.e. won 51 oregon much votes. If a campaigner has done so, you indispensable accidental who it is.
But there’s a catch. You are not allowed to number the ballot papers. That is, you are not allowed to usage numbers successful immoderate way. You can’t constitute thing down, nor are you allowed to support way of the tally successful your memory. Instead you volition person to devise a clever strategy that involves making instant decisions astir each ballot insubstantial erstwhile you spot it.
All you are allowed to bash is to determination the papers betwixt 3 piles connected a table. The starting position, arsenic illustrated below, has each the papers successful a stack connected the archetypal pile. The ballot papers are look up, truthful you tin ever spot which campaigner has received a ballot connected the ballot insubstantial astatine the apical of the pile. There are 2 different positions for piles, but arsenic yet they are empty.
There are lone two options to start. You determination the apical ballot connected Pile 1 to either Pile 2 oregon Pile 3. For your adjacent determination you tin bash the aforesaid again, oregon you tin determination the ballot that is connected either Pile 2 oregon Pile 3 to different pile. And truthful on. At immoderate signifier each you tin bash is to determination the ballot insubstantial that is astatine the apical of 1 heap to the apical of different pile.
Your task is to find a strategy that tells you if 1 campaigner has an wide bulk (i.e 51 oregon much votes) simply by shifting ballot papers betwixt piles. Can you bash it?
As is often the case, it is adjuvant to simplify the occupation to spot if it gives america immoderate insights. Let’s see the lawsuit erstwhile determination are lone 2 candidates, A and B.
A elemental strategy is arsenic follows: if we spot A atop the archetypal pile, we enactment it connected the 2nd pile, and if we spot B atop the archetypal pile, we enactment it connected the 3rd pile. After 100 moves, the archetypal heap volition beryllium empty, the 2nd heap volition person each the As and the 3rd heap each the Bs. We tin present enactment retired which heap has the astir ballots by placing them alternately backmost connected the archetypal pile. If determination are immoderate ballots near connected the 2nd heap astatine the end, past A has astatine slightest 51 votes, and if determination are immoderate ballots near connected the 3rd pile, past B does. Call this the “two-group strategy”.
Now effort scaling up to 4 candidates, A, B, C and D. One mode to bash it would beryllium to usage the 2 radical strategy with the candidates divided into 2 coalitions, accidental A&B vs C&D. If 1 of the coalitions has much than 51 votes, we past bash the 2 radical strategy doubly much – erstwhile for each subordinate of the winning coalition. This strategy works, but it is not precise efficient: it relies connected moving papers betwixt piles astatine slightest 500 times, arsenic good arsenic keeping tracks of coalitions. There is simply a overmuch quicker way. Can you find it?
I’ll beryllium backmost astatine 5pm UK with a solution and a discussion. PLEASE NO SPOILERS alternatively sermon your favourite streaming services.
If you are wondering what moving ballot papers has got to bash with streaming, here’s the analogy. Each ballot insubstantial is simply a portion of incoming data. You are not allowed to count, which is analogous to not being capable to usage a representation to store information. Instead, you indispensable marque an instant determination astir what to bash arsenic soon arsenic each portion of information arrives, with the anticipation that precise rapidly you tin larn immoderate wide spot of the full stream: whether oregon not determination is simply a bulk value, and if determination is, what it is.
Today’s puzzle was devised by Pierre Chardaire, a retired machine scientist.
I acceptable a puzzle present each 2 weeks connected a Monday. I’m ever connected the look-out for large puzzles. If you would similar to suggest one, email me.
I springiness schoolhouse talks astir maths and puzzles (online and successful person). If your schoolhouse is funny delight get successful touch.