Skip to content

Instantly share code, notes, and snippets.

@captbaritone
Created November 17, 2012 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captbaritone/4093068 to your computer and use it in GitHub Desktop.
Save captbaritone/4093068 to your computer and use it in GitHub Desktop.
Count binary in Perl
#!/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