diff options
| -rw-r--r-- | challenge-145/lubos-kolouch/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-145/lubos-kolouch/perl/ch-2.pl | 23 | ||||
| -rw-r--r-- | challenge-145/lubos-kolouch/python/ch-1.py | 11 | ||||
| -rw-r--r-- | challenge-145/lubos-kolouch/python/ch-2.py | 21 |
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'] |
