You might be a nerd if: You write a perl script to count sheep for you…
… in binary.
I couldn’t seep last night, so I decided to count sheep. Counting reminded me of the time my brother mentioned that one could count in binary on ones fingers. That sounded pleasantly meditative, so I set my brain to work on figuring out how one might do that. Before long I had counted quite high, and was fascinated by the way the system worked. Naturally my brain wandered to: “how might a computer do this simple task?” By now I had completely lost interest in sleep, so I sneaked out of bed, turned on the laptop and cranked out a little application to count in binary for me. I was then a free to go back to sleep, having automated the tedious task of counting sheep.
The code follows:
(Excuse: I am very new to Perl and did not have internet access at the time I wrote this, so my reference resources were limited.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #!/usr/bin/env perl # Counts in binary # The array of digets, starting with the least significant @binary = (0); while(@binary < 79){ $i = 0; $found = 0; # Until we find a 0 while($found == 0){ # if its a 0 if(@binary[$i] == 0){ #set it to one @binary[$i] = 1; # Set all previous digets back to 0 $j = 0; while($j < $i){ @binary[$j] = 0; $j++; } $found = 1; } $i++; } $k = @binary; # Print the digets in the correct order while($k >= 0){ print "@binary[$k]"; $k--; } print "\n"; sleep(1); } |
I remember someone teaching me how to count binary on one hand. I thought I learned it in high school. Did you teach me?