aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-182/lubos-kolouch/perl/ch-1.pl19
-rw-r--r--challenge-182/lubos-kolouch/perl/ch-2.pl25
-rw-r--r--challenge-182/lubos-kolouch/python/ch-1.py10
-rw-r--r--challenge-182/lubos-kolouch/python/ch-2.py23
4 files changed, 77 insertions, 0 deletions
diff --git a/challenge-182/lubos-kolouch/perl/ch-1.pl b/challenge-182/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..a9401e81e8
--- /dev/null
+++ b/challenge-182/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+sub max_index {
+ my @lst = @_;
+ my $max = $lst[0];
+ my $index = 0;
+ for my $i ( 1 .. $#lst ) {
+ if ( $lst[$i] > $max ) {
+ $max = $lst[$i];
+ $index = $i;
+ }
+ }
+ return $index;
+}
+
+print max_index( 5, 2, 9, 1, 7, 6 ); # Output: 2
+print "\n";
+print max_index( 4, 2, 3, 1, 5, 0 ); # Output: 4
diff --git a/challenge-182/lubos-kolouch/perl/ch-2.pl b/challenge-182/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..295bd547c8
--- /dev/null
+++ b/challenge-182/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use List::Util qw/all/;
+
+sub common_path {
+ my @paths = @_;
+
+ my @parts = map { [ split '/', $_ ] } @paths;
+
+ my @common;
+ for my $i ( 0 .. $#{ $parts[0] } ) {
+ my $part = $parts[0][$i];
+ last unless all { $_->[$i] eq $part } @parts;
+ push @common, $part;
+ }
+
+ return join '/', @common;
+}
+
+my @paths = (
+ "/a/b/c/1/x.pl", "/a/b/c/d/e/2/x.pl",
+ "/a/b/c/d/3/x.pl", "/a/b/c/4/x.pl",
+ "/a/b/c/d/5/x.pl"
+);
+print common_path(@paths), "\n"; # Output: /a/b/c
diff --git a/challenge-182/lubos-kolouch/python/ch-1.py b/challenge-182/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..373f34c2c8
--- /dev/null
+++ b/challenge-182/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def max_index(lst):
+ return lst.index(max(lst))
+
+
+print(max_index([5, 2, 9, 1, 7, 6])) # Output: 2
+print(max_index([4, 2, 3, 1, 5, 0])) # Output: 4
diff --git a/challenge-182/lubos-kolouch/python/ch-2.py b/challenge-182/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..2ebe227ab7
--- /dev/null
+++ b/challenge-182/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def common_path(paths):
+ paths = [path.split("/") for path in paths]
+ common = []
+ for items in zip(*paths):
+ if all(item == items[0] for item in items):
+ common.append(items[0])
+ else:
+ break
+ return "/".join(common)
+
+
+paths = [
+ "/a/b/c/1/x.pl",
+ "/a/b/c/d/e/2/x.pl",
+ "/a/b/c/d/3/x.pl",
+ "/a/b/c/4/x.pl",
+ "/a/b/c/d/5/x.pl",
+]
+print(common_path(paths)) # Output: /a/b/c