aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-203/chicagoist/README.md1
-rw-r--r--challenge-203/chicagoist/perl/.gitignore2
-rw-r--r--challenge-203/chicagoist/perl/ch-1.pl35
-rw-r--r--challenge-203/chicagoist/perl/ch-2.pl38
4 files changed, 76 insertions, 0 deletions
diff --git a/challenge-203/chicagoist/README.md b/challenge-203/chicagoist/README.md
new file mode 100644
index 0000000000..a94f5853a8
--- /dev/null
+++ b/challenge-203/chicagoist/README.md
@@ -0,0 +1 @@
+Solution by Chicagoist
diff --git a/challenge-203/chicagoist/perl/.gitignore b/challenge-203/chicagoist/perl/.gitignore
new file mode 100644
index 0000000000..ca71208fb7
--- /dev/null
+++ b/challenge-203/chicagoist/perl/.gitignore
@@ -0,0 +1,2 @@
+/.gitignore
+/.idea \ No newline at end of file
diff --git a/challenge-203/chicagoist/perl/ch-1.pl b/challenge-203/chicagoist/perl/ch-1.pl
new file mode 100644
index 0000000000..39b8b899d3
--- /dev/null
+++ b/challenge-203/chicagoist/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+use v5.10;
+use strict;
+use warnings FATAL => 'all';
+our $VERSION = '0.01';
+
+sub specialQuadruplets
+{
+ my (@nums) = @_;
+ my $count = 0;
+
+ for (my $x = 0; $x <= $#nums - 3; $x++)
+ {
+ for (my $y = $x + 1; $y <= $#nums - 2; $y++)
+ {
+ for (my $z = $y + 1; $z <= $#nums - 1; $z++)
+ {
+ for (my $d = $z + 1; $d <= $#nums; $d++)
+ {
+ if ($nums[$x] + $nums[$y] + $nums[$z] == $nums[$d])
+ {
+ $count++;
+ }
+ }
+ }
+ }
+ }
+ return $count;
+}
+
+
+use Test::More tests => 3;
+ok specialQuadruplets(1, 2, 3, 6) == 1;
+ok specialQuadruplets((1, 1, 1, 3, 5)) == 4;
+ok specialQuadruplets(3, 3, 6, 4, 5) == 0;
diff --git a/challenge-203/chicagoist/perl/ch-2.pl b/challenge-203/chicagoist/perl/ch-2.pl
new file mode 100644
index 0000000000..d00f8fa3d2
--- /dev/null
+++ b/challenge-203/chicagoist/perl/ch-2.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+use v5.10;
+use strict;
+use warnings FATAL => 'all';
+our $VERSION = '0.01';
+
+use File::Path qw(make_path);
+use File::Copy;
+use File::Basename;
+
+my $source = '/a/b/c';
+my $target = '/x/y';
+
+sub cpDir
+{
+ my ($src, $dst) = @_;
+
+ opendir my $dir, $src or die "Cannot open directory: $!";
+ while (my $file = readdir $dir)
+ {
+ next if ($file eq "." || $file eq "..");
+ my $srcPath = "$src/$file";
+ my $dstPath = "$dst/$file";
+
+ if (-d $srcPath)
+ {
+ make_path($dstPath) unless -e $dstPath;
+ cpDir($srcPath, $dstPath);
+ } elsif (-f $srcPath)
+ {
+ # Skip files
+ }
+ }
+ closedir $dir;
+}
+
+cpDir($source, $target);
+