Last active
April 25, 2020 13:56
-
-
Save davorg/aa81954372c454984f5674b8099a8103 to your computer and use it in GitHub Desktop.
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/perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
my $target = 92; | |
my @prices = (35, 46, 19, 7, 41, 27); | |
# If we have command-line arguments | |
if (@ARGV) { | |
# Get the first argument as the target | |
$target = shift; | |
} | |
# If we still have command-line arguments | |
if (@ARGV) { | |
# Use them as the list of numbers | |
@prices = @ARGV; | |
} | |
for my $x (@prices) { | |
for my $y (@prices) { | |
for my $z (@prices) { | |
next if $x == $y or $x == $z or $y == $z; | |
if ($x + $y + $z == $target) { | |
say "The answer is $x + $y + $z = ", $x + $y + $z; | |
exit; | |
} | |
} | |
} | |
} | |
say "There is no solution."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment