Created
April 11, 2019 02:56
-
-
Save ugexe/2fa62c2d498f9e206d693f47e4a231aa to your computer and use it in GitHub Desktop.
Polyglot Perl5/6 hamming numbers
This file contains hidden or 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
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