Skip to content

Instantly share code, notes, and snippets.

@ugexe
Created April 11, 2019 02:56
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 ugexe/2fa62c2d498f9e206d693f47e4a231aa to your computer and use it in GitHub Desktop.
Save ugexe/2fa62c2d498f9e206d693f47e4a231aa to your computer and use it in GitHub Desktop.
Polyglot Perl5/6 hamming numbers
my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) };
my $numbers_tried = 0;
my $numbers_found = 0;
NUMBERS: while ($numbers_found != @ARGV[0]) {
$numbers_tried++;
my $state = $numbers_tried;
while ($state != 1) {
if ($state % 2 == 0) {
$state /= 2;
}
elsif ($state % 3 == 0) {
$state /= 3;
}
elsif ($state % 5 == 0) {
$state /= 5;
}
else {
next NUMBERS;
}
}
$numbers_found++;
print("$numbers_tried\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment