Thursday, June 16, 2011

Unhappy Magic Flowers and Binary

Binary is a number system where each digit can only take one of two values: zero or one. Binary is used within computers, because it allows the computer to encode information in a series of switches that are either on (1) or off (0). Each digit of binary represents a power of two. The first (right-most) digit represents the 1's place, the second digit represents the 2's place, the third represents the 4's place, and so forth. For example, the binary number 10110 = 1*2^4 + 0*2^3 + 1*2^2 + 1*2^1 + 0*2^0 = 22 in decimal.

The deliveryman paused outside of Marcus's house. He stood transfixed, staring at the flowers. After two minutes, Marcus finally went outside to see what the problem was.

"Your flowers have changed since yesterday." observed the deliveryman. "I am sure that the one on the right was red yesterday. Today it is blue."

"No. Those are the same flowers." responded Marcus. "Some of them are just sulking today. Stupid flowers."

"Sulking? Do flowers sulk?" the delivery man asked.

"These flowers do. They are, of course, magic. If there is not enough rain, they sulk. It is quite aggravating really. It is not as though they are not getting water. I water them every day. Yet, they still insist on sulking when there is no rain. It appears that the water I give them is not good enough for them."

"Huh?" The deliveryman looked most confused. He looked back and forth between Marcus and the flowers.

"They sulk by changing to blue. Roses are supposed to be red. That is why so many poems start out that way. But, they insist on telling me how long it has been since it rained." Marcus gestured angrily at the roses as he spoke.

"They talk to you?" The deliveryman took a step back away from Marcus. He looked as though he was ready to run.

"Of course not. They simply change color." Marcus sighed.

"And, that tells you how long it has been without rain?"

"Well…" started Marcus. "They used to all change color together after three days without rain. A sort of mass protest. But, then they started to organize. They want to let me know exactly how unhappy they are. So, now they count the days."

"But… only two are blue. It has not rained all week." observed the deliveryman.

"Nine days to be exact." corrected Marcus after looking at the flowers. "They use binary."


"Binary. Red flowers are zero and blue flowers are one." Marcus added.

The deliveryman did not look as though he was following. But, at least he did not look like he was about to run away anymore.

"Binary?" prompted Marcus. "Each flower represents a different digit, and thus a different power of two. The rightmost flower means one (2^0), the one next to it means two (2^1), the one next to that means four (2^2), and so forth. Add up the numbers represented by the blue flowers and you get the total number of days. Right now only first (2^0 = 1) and fourth (2^3 = 8) flowers are blue, so it has been 2^0 + 2^3 = 1 + 8 = 9 days."

The deliveryman looked. Sure enough, the five flowers across Marcus's porch were: Red Blue Red Red Blue (or 01001).

"Why do they use binary?" asked the deliveryman.

"They tried to spell out the numbers on their petals and they got too confused. So they had to settle for each flower being either all red or all blue. It turns out that flowers are not that smart. Binary is a simple enough system for them. If they were smart enough for anything else, do you think they would be complaining to me about the rain? There is nothing I can do!" Marcus shouted the last part directly at the flowers.

"But, how do they work together?" The more absurd the story got, the more interested the deliveryman became. He took a step forward towards the flowers.

"It is really quite simple for them to count in binary. When it rains, they are all happy and turn red. It is like reseting the counter to 00000. I like those days a lot." started Marcus.

"Then, each morning all of the flowers wake up and decide what color they are going to be for the whole day. If it has not rained, they increase the count.

After 1 day they are: Red Red Red Red Blue (00001 = 1)

After 2 days they are: Red Red Red Blue Red (00010 = 2)

After 3 days they are: Red Red Red Blue Blue (00011 = 2 + 1 = 3)

After 4 days they are: Red Red Blue Red Red (00100 = 4)

After 5 days they are: Red Red Blue Red Blue (00101 = 4 + 1 = 5)

And so on.

"You see, each flower looks to its right in order to decide what to do. If its right-hand neighbor changes from blue to red (1 to 0), then the flower flips its own color. I like to think of it as passing along the unhappiness. Basically, if its neighbor is changing from blue to red then the sullenness is rolling over to the current flower. If it is red, then it becomes blue. And if it is blue, it becomes red and passes the sullenness further down the line. This keeps happening until one of the flowers does not change from blue to red."

The deliveryman thought about it. "What if a flower changes from red to blue (0 to 1)?"

"Its neighbor does nothing. Didn't I just say that?" Marcus was impatient. He felt like he was talking to one of his apprentices. "Think about it the way you would counting with numbers 0-9. When you hit 9, you roll the first digit back to 0 and increment the next digit to 1. That next digit stays where it is until its right-hand neighbor switches from 9 to 0 again. You don't count 10, 11, 12, 23. Do you? NO! You wait until the digit to your right rolls over. Only here there are exactly two options 0 and 1, so things roll over more frequently."

"What about the right-most flower?" asked the deliveryman. "How does it know what to do?"

"Ah. THAT ONE IS THE INSTIGATOR! I am sure that he is the one that started it. Every morning there is no rain, he flips. He is the one that starts the process off. Red to blue to red to blue to..."

"And that system always works?" interrupted the deliveryman.

Marcus tore his attention away from the right-most flower. He suddenly wondered how the discussion had gone from a rant about magic flowers to counting in binary. Did the deliveryman not have any other deliveries? For that matter, where was the delivery for Marcus?

"Yes. They already counted out nine days, haven't they?" answered Marcus flippantly.

Then, seeing the look of interest on the deliveryman's face, Marcus returned to his teaching tone. "Imagine that these three flowers were blue." explained Marcus as he pointed to the first three flowers. "That would be 1 + 2 + 4 = 7 days without rain. The next day the first flower (1) switches to red, so the second flower (2) switches to red, so the third flower (4) switches to red, so the fourth flower (8) switches to blue. Then they would show 8 days without rain. The count effectively gets pushed down into the fourth flower."

The deliveryman looked impressed. Marcus could not understand why. The flowers were really very annoying.

"So tomorrow they will be: Red Blue Red Blue Red (01010)?" asked the deliveryman.

"Probably. But, I really hope that it just rains." responded Marcus with a sigh.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.