Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions challenge-203/jaldhar-h-vyas/perl/ch-1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/perl
use 5.030;
use warnings;

sub combinations {
my @list = @{$_[0]};
my $length = $_[1];

if ($length <= 1) {
return map [$_], @list;
}

my @combos;

for (my $i = 0; $i + $length <= scalar @list; $i++) {
my $val = $list[$i];
my @rest = @list[$i + 1 .. $#list];
for my $c (combinations(\@rest, $length - 1)) {
push @combos, [$val, @{$c}] ;
}
}

return @combos;
}

my @args = @ARGV;
my @quadruplets;

for my $combo (combinations(\@args, 4)) {
my @sorted = sort {$a <=> $b} @{$combo};
if ($sorted[0] + $sorted[1] + $sorted[2] == $sorted[3]) {
push @quadruplets, \@sorted;
}
}

say scalar @quadruplets;
39 changes: 39 additions & 0 deletions challenge-203/jaldhar-h-vyas/perl/ch-2.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/perl
use 5.038;
use warnings;
use File::Find;
use File::Spec;

my ($source, $target) = @ARGV;
if (@ARGV != 2) {
die "Usage: $0 source_dir target_dir\n";
}

unless (-d $target) {
mkdir $target;
}

my @dirs;

find(
{
wanted => sub {
if (-d) {
push @dirs, $File::Find::name;
}
},
no_chdir => 1,
},
$source
);

for my $dir (@dirs) {
if ($dir eq $source) {
next;
}

my $relPath = File::Spec->abs2rel($dir, $source);
my $newDir = File::Spec->catdir($target, $relPath);

mkdir $newDir;
}
16 changes: 16 additions & 0 deletions challenge-203/jaldhar-h-vyas/raku/ch-1.raku
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/raku

sub MAIN(
*@args
) {
my @quadruplets;

for @args.combinations(4) -> $combo {
my @sorted = @$combo.sort({$^a <=> $^b});
if @sorted[0] + @sorted[1] + @sorted[2] == @sorted[3] {
@quadruplets.push(@sorted);
}
}

@quadruplets.elems.say;
}
25 changes: 25 additions & 0 deletions challenge-203/jaldhar-h-vyas/raku/ch-2.raku
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/raku
use File::Find;

sub MAIN(
Str $source, #= source directory path
Str $target #= target directory path
) {
my $sio = $source.IO;
my $tio = $target.IO;

unless $tio.d {
mkdir $target;
}

my @dirs = find(dir => $sio, type => 'dir');

for @dirs -> $dir {

my $relPath = $dir.relative($sio);
my $newDir = $tio.add($relPath);

mkdir $newDir;
}
}