Created
November 17, 2012 03:33
-
-
Save captbaritone/4093068 to your computer and use it in GitHub Desktop.
Count binary in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment