aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2023-07-08 12:33:49 +0200
committerLubos Kolouch <lubos@kolouch.net>2023-07-08 12:33:49 +0200
commit393d8f7b2cc5cb6fa63fd185b730a61173e452a4 (patch)
tree241f38bc2d9f556c2392ff351d55129f45978252
parent3599200121ce36f3e5f6560835fc3d1ba22961e4 (diff)
downloadperlweeklychallenge-club-393d8f7b2cc5cb6fa63fd185b730a61173e452a4.tar.gz
perlweeklychallenge-club-393d8f7b2cc5cb6fa63fd185b730a61173e452a4.tar.bz2
perlweeklychallenge-club-393d8f7b2cc5cb6fa63fd185b730a61173e452a4.zip
feat(challenge-145/lubos-kolouch/perl,python/): Challenge 145 LK Perl Python
-rw-r--r--challenge-145/lubos-kolouch/perl/ch-1.pl15
-rw-r--r--challenge-145/lubos-kolouch/perl/ch-2.pl23
-rw-r--r--challenge-145/lubos-kolouch/python/ch-1.py11
-rw-r--r--challenge-145/lubos-kolouch/python/ch-2.py21
4 files changed, 70 insertions, 0 deletions
diff --git a/challenge-145/lubos-kolouch/perl/ch-1.pl b/challenge-145/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..927bca97b6
--- /dev/null
+++ b/challenge-145/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+
+sub dot_product {
+ my ( $a, $b ) = @_;
+ my $dot_product = 0;
+ for my $i ( 0 .. $#$a ) {
+ $dot_product += $a->[$i] * $b->[$i];
+ }
+ return $dot_product;
+}
+
+my @a = ( 1, 2, 3 );
+my @b = ( 4, 5, 6 );
+print dot_product( \@a, \@b ); # Output: 32
diff --git a/challenge-145/lubos-kolouch/perl/ch-2.pl b/challenge-145/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..a148ba5490
--- /dev/null
+++ b/challenge-145/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+sub palindromic_tree {
+ my ($s) = @_;
+ my @result;
+ for my $i ( 0 .. length($s) - 1 ) {
+ for my $j ( $i + 1 .. length($s) ) {
+ my $substring = substr $s, $i, $j - $i;
+ if ( $substring eq reverse $substring ) {
+ push @result, $substring;
+ }
+ }
+ }
+ return \@result;
+}
+
+my $s = 'redivider';
+print join( " ", @{ palindromic_tree($s) } ),
+ "\n"; # Output: r redivider e edivide d divid i ivi v
+
+$s = 'deific';
+print join( " ", @{ palindromic_tree($s) } ), "\n"; # Output: d e i ifi f c
diff --git a/challenge-145/lubos-kolouch/python/ch-1.py b/challenge-145/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..bcd2e57de6
--- /dev/null
+++ b/challenge-145/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def dot_product(a, b):
+ return sum(x * y for x, y in zip(a, b))
+
+
+a = [1, 2, 3]
+b = [4, 5, 6]
+print(dot_product(a, b)) # Output: 32
diff --git a/challenge-145/lubos-kolouch/python/ch-2.py b/challenge-145/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..7a9584b223
--- /dev/null
+++ b/challenge-145/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+def palindromic_tree(s):
+ result = []
+ for i in range(len(s)):
+ for j in range(i + 1, len(s) + 1):
+ substring = s[i:j]
+ if substring == substring[::-1]:
+ result.append(substring)
+ return result
+
+
+s = "redivider"
+print(
+ palindromic_tree(s)
+) # Output: ['r', 'redivider', 'e', 'edivide', 'd', 'divid', 'i', 'ivi', 'v']
+
+s = "deific"
+print(palindromic_tree(s)) # Output: ['d', 'e', 'i', 'ifi', 'f', 'c']