aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-333/ysth/perl/ch-1.pl27
-rw-r--r--challenge-333/ysth/perl/ch-2.pl15
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-333/ysth/perl/ch-1.pl b/challenge-333/ysth/perl/ch-1.pl
new file mode 100644
index 0000000000..d36337a1b7
--- /dev/null
+++ b/challenge-333/ysth/perl/ch-1.pl
@@ -0,0 +1,27 @@
+use 5.040; # for true and false
+
+sub straight_line(@coordinates) {
+ if (@coordinates < 4 || @coordinates % 2) {
+ return @coordinates == 2;
+ }
+
+ my ($x0,$y0,$x1,$y1) = splice @coordinates, 0, 4;
+ # need to find a different second point to define the line
+ while ($x1 == $x0 && $y1 == $y0) {
+ ($x1,$y1) = splice @coordinates, 0, 2 or last;
+ }
+ while (my ($x,$y) = splice @coordinates, 0, 2) {
+ return false if ($y-$y0)*($x1-$x0) != ($x-$x0)*($y1-$y0);
+ }
+ return true;
+}
+
+sub main() {
+ my @inputs = @ARGV;
+
+ say straight_line(@inputs) ? 'true' : 'false';
+
+ return;
+}
+
+main() unless caller;
diff --git a/challenge-333/ysth/perl/ch-2.pl b/challenge-333/ysth/perl/ch-2.pl
new file mode 100644
index 0000000000..e623142e6c
--- /dev/null
+++ b/challenge-333/ysth/perl/ch-2.pl
@@ -0,0 +1,15 @@
+use 5.036;
+
+sub duplicate_zeros(@inputs) {
+ (map $_ || ($_,$_), @inputs)[0..$#inputs]
+}
+
+sub main() {
+ my @inputs = @ARGV;
+
+ say join ' ', duplicate_zeros(@inputs);
+
+ return;
+}
+
+main() unless caller;