Skip to content

Instantly share code, notes, and snippets.

@thepeopleseason
Last active January 13, 2020 17:19
Show Gist options
  • Save thepeopleseason/3de35b1f8242ecc0211754bf7cecd47b to your computer and use it in GitHub Desktop.
Save thepeopleseason/3de35b1f8242ecc0211754bf7cecd47b to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
my $lines =<<'END';
44 - 44
44 / 44
sqrt(4) * 4**0 * 4/4
(sqrt(4) + 4**0) * 4/4
4 * 4/4 * 4 ** 0
(4 + 4 ** 0) * 4/4
(4 + sqrt(4)) * 4/4
(4 + sqrt(4) + 4 ** 0) * 4 ** 0
(4 + 4) * 4/4
(4 + 4 + 4 ** 0) * 4 ** 0
(4 + 4 + sqrt(4)) * 4 ** 0
4/.4 + 4/4
(4 + 4 + 4) * 4 ** 0
4 + 4 + 4 + 4 ** 0
4 + 4 + 4 + sqrt(4)
4 * 4 - 4/4
4 * 4 * 4/4
(4 * 4 + 4 ** 0) * 4 ** 0
(4 * 4 + sqrt(4)) * 4 ** 0
4 * 4 + sqrt(4) + 4 ** 0
(4 * 4 + 4) * 4 ** 0
4 * 4 + 4 + 4 ** 0
4 * 4 + 4 + sqrt(4)
(fact(4) - 4 ** 0) * 4/4
4 * 4 + 4 + 4
(fact(4) + 4 ** 0) * 4/4
(fact(4) + sqrt(4)) * 4/4
fact(4) + sqrt(4) + 4/4
(fact(4) + sqrt(4) + sqrt(4)) * 4 ** 0
fact(4) + 4 + 4/4
fact(4) + 4/.4 - 4
fact(4) + 4 + 4 - 4 ** 0
4 * 4 * 4 / sqrt(4)
fact(4) + 4 + 4 + 4 ** 0
fact(4) + 4 + 4 + sqrt(4)
(fact(4) + 4/.4 + 4 ** 0)
4 * 4/.4 - 4
fact(4) + 4 **0 + fact(4) / sqrt(4)
fact(4) + 4/.4 + 4
4 * 4/.4 - 4 ** 0
fact(4) + fact(4) - 4 - 4
44 - sqrt(4) - 4 ** 0
(44 - sqrt(4)) * 4 ** 0
44 - 4/4
44 * 4/4
44 + 4/4
(44 + sqrt(4)) * 4 ** 0
44 + 4 - 4 ** 0
fact(4) * sqrt(4) * 4/4
fact(4) * sqrt(4) + 4/4
(fact(4) * sqrt(4) + sqrt(4)) * 4 ** 0
fact(4) * sqrt(4) + 4 - 4 ** 0
(fact(4) * sqrt(4) + 4) * 4 ** 0
fact(4) * sqrt(4) + 4 + 4 ** 0
fact(4) * sqrt(4) + 4 + sqrt(4)
44 /.4 / sqrt(4)
(fact(4) / .4 - 4) * 4 ** 0
fact(4) / .4 - sqrt(4) - 4 ** 0
(fact(4) / .4 - sqrt(4)) * 4 ** 0
(fact(4) / .4 - 4 ** 0) * 4 ** 0
fact(4) / .4 * 4/4
(fact(4) / .4 + 4 ** 0) * 4 ** 0
4 * 4 * 4 - sqrt(4)
4 * 4 * 4 - 4 ** 0
4 * 4 * 4 * 4 ** 0
4 * 4 * 4 + 4 ** 0
4 * 4 * 4 + sqrt(4)
(fact(4) + sqrt(4)) / .4 + sqrt(4)
fact(4) / .4 + 4 + 4
(fact(4) - 4 ** 0) * (4 - 4 ** 0)
fact(4) * (4 - 4 ** 0) - sqrt(4)
fact(4) * (4 - 4 ** 0) - 4 ** 0
fact(4) * (4 - 4 ** 0) * 4 ** 0
fact(4) * (4 - 4 ** 0) + 4 ** 0
fact(4) * (4 - 4 ** 0) + sqrt(4)
(fact(4) + 4 ** 0) * (4 - 4 ** 0)
fact(4) / .4 + 4 * 4
(4 - 4 ** 0) ** 4 - 4
(fact(4) + sqrt(4)) * (sqrt(4) + 4 ** 0)
(4 - 4 ** 0) ** 4 - sqrt(4)
(4 + 4) / .4 * 4
(4 - 4 ** 0) ** 4 * 4 ** 0
(4 - 4 ** 0) ** 4 + 4 ** 0
(4 - 4 ** 0) ** 4 + sqrt(4)
(fact(4) + 4) * (sqrt(4) + 4 ** 0)
(4 - 4 ** 0) ** 4 + 4
fact(4) * 4 - (4/.4)
44 * sqrt(4) - 4 ** 0
44 * sqrt(4) * 4 ** 0
44 * sqrt(4) + 4 ** 0
44 * sqrt(4) + sqrt(4)
fact(4) * 4 - 4 - 4 ** 0
fact(4) * 4 - sqrt(4) - sqrt(4)
fact(4) * 4 - sqrt(4) - 4 ** 0
(fact(4) * 4 - sqrt(4)) * 4 ** 0
(fact(4) * 4 - 4 ** 0) * 4 ** 0
fact(4) * 4 * 4/4
(fact(4) * 4 + 4 ** 0) * 4 ** 0
(fact(4) * 4 + sqrt(4)) * 4 ** 0
fact(4) * 4 + sqrt(4) + 4 ** 0
fact(4) * 4 + sqrt(4) + sqrt(4)
fact(4) * 4 + 4 + 4 ** 0
fact(4) * 4 + 4 + sqrt(4)
END
my $counter = 0;
for (split(/\n/, $lines)) {
my $count = () = $_ =~ /4/g;
my $result = eval $_;
print $result, ":\t$count\t", $result == $counter, "\t", $_, "\n";
$counter++;
}
sub fact {
my $n = shift;
my $acc = 1;
$acc *= $_ for 2..$n;
return $acc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment