aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-12-23 19:05:41 +0000
committerGitHub <noreply@github.com>2019-12-23 19:05:41 +0000
commit873df882a7e2c1f0718e1f9206c7f7979e80cb0f (patch)
tree8b32c8364ea55aa3617e58871788a5e926a6cedf
parentb1b9d5071aa120c8594bb2feaa37ac3750c8a052 (diff)
parentcfe9268334182af37f4aeb8e69215b183cf5efa1 (diff)
downloadperlweeklychallenge-club-873df882a7e2c1f0718e1f9206c7f7979e80cb0f.tar.gz
perlweeklychallenge-club-873df882a7e2c1f0718e1f9206c7f7979e80cb0f.tar.bz2
perlweeklychallenge-club-873df882a7e2c1f0718e1f9206c7f7979e80cb0f.zip
Merge pull request #1066 from kolcon/master
Perl solutions LK 040
-rw-r--r--challenge-040/lubos-kolouch/perl5/ch-1.pl35
-rw-r--r--challenge-040/lubos-kolouch/perl5/ch-2.pl43
-rw-r--r--challenge-040/lubos-kolouch/python/ch-1.py20
-rw-r--r--challenge-040/lubos-kolouch/python/ch-2.py29
4 files changed, 127 insertions, 0 deletions
diff --git a/challenge-040/lubos-kolouch/perl5/ch-1.pl b/challenge-040/lubos-kolouch/perl5/ch-1.pl
new file mode 100644
index 0000000000..e880c05e44
--- /dev/null
+++ b/challenge-040/lubos-kolouch/perl5/ch-1.pl
@@ -0,0 +1,35 @@
+#!env perl
+use strict;
+use warnings;
+use feature qw /say/;
+use Data::Dumper;
+
+
+my $array_ref = shift // die 'No arrays passed';
+
+my @arr = $array_ref;
+
+die "Usage ch-1.pl \"[1 2 3 4][5 6 7 8]\"" unless ($arr[0] =~ / ^(\[(. *)+\])+$/msx);
+
+my $arr_size;
+
+my @all_array;
+
+my $i=0;
+for (split /\]/, $arr[0]) {
+ $_ =~ s/\[//g;
+
+ push @{$all_array[$i]}, split / /;
+
+ $arr_size = scalar @{$all_array[$i]} unless $arr_size;
+
+ die "arrays are not of the same size" unless scalar @{$all_array[$i]} == $arr_size;
+ $i++;
+}
+
+for my $key (0..$arr_size-1) {
+ for my $arr (0..scalar @all_array -1) {
+ print $all_array[$arr][$key]." ";
+ }
+ say '';
+}
diff --git a/challenge-040/lubos-kolouch/perl5/ch-2.pl b/challenge-040/lubos-kolouch/perl5/ch-2.pl
new file mode 100644
index 0000000000..40f6d591f9
--- /dev/null
+++ b/challenge-040/lubos-kolouch/perl5/ch-2.pl
@@ -0,0 +1,43 @@
+#!env perl
+use strict;
+use warnings;
+use feature qw /say/;
+use Data::Dumper;
+
+
+my $array_ref = shift // die 'No arrays passed';
+
+my @arr = $array_ref;
+
+die "Usage ch-2.pl \"[10 4 1 8 12 3][0 2 5]\"" unless ($arr[0] =~ / ^(\[(\d+\h*)+\])+$/msx);
+
+my $arr_size;
+
+my @all_array;
+
+my $i=0;
+for (split /\]/, $arr[0]) {
+ $_ =~ s/\[//g;
+
+ push @{$all_array[$i]}, split / /;
+
+ $arr_size = scalar @{$all_array[$i]} unless $arr_size;
+
+ $i++;
+}
+
+my @sort_array;
+
+for (@{$all_array[1]}) {
+ push @sort_array, $all_array[0][$_];
+}
+
+@sort_array = sort {$a <=> $b} @sort_array;
+
+$i=0;
+for (@{$all_array[1]}) {
+ $all_array[0][$all_array[1][$i]] = $sort_array[$i];
+ $i++;
+}
+
+warn Dumper \$all_array[0];
diff --git a/challenge-040/lubos-kolouch/python/ch-1.py b/challenge-040/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..bebdf0e5dc
--- /dev/null
+++ b/challenge-040/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,20 @@
+#!python3
+
+import numpy as np
+import sys
+
+# python ch-1.py "[ I L O V E Y O U ][ 2 4 0 3 2 0 1 9 ][ ! ? £ $ % ^ & * ]"
+
+assert len(sys.argv) == 2
+
+arr = np.empty(0)
+arr1 = np.array(sys.argv[1].split(' ]'))
+
+for elem in arr1[:-1]:
+ arr = np.append(arr, elem[2:].split(' '))
+
+arr = np.reshape(arr, (len(arr1)-1, int(len(arr)/(len(arr1)-1))))
+arr = np.rot90(arr, 3)
+arr = np.flip(arr, 1)
+
+print(arr)
diff --git a/challenge-040/lubos-kolouch/python/ch-2.py b/challenge-040/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..3c0a6706bb
--- /dev/null
+++ b/challenge-040/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,29 @@
+#!python3
+
+import numpy as np
+import sys
+
+# python ch-2.py "[ 10, 4, 1, 8, 12, 3 ][ 0, 2, 5 ]"
+
+assert len(sys.argv) == 2
+
+arr1 = np.empty(0, int)
+arr2 = np.empty(0, int)
+arr = np.array(sys.argv[1].replace('[', '').replace(' ', '').split(']'))
+
+arr1 = arr[0].split(',')
+arr2 = arr[1].split(',')
+
+arr_sort = np.empty(0, int)
+
+for key in arr2:
+ arr_sort = np.append(arr_sort, int(arr1[int(key)]))
+
+arr_sort = np.sort(arr_sort)
+
+i = -1
+for key in arr2:
+ i += 1
+ arr1[int(key)] = arr_sort[i]
+
+print(arr1)