diff options
| author | Adam Russell <ac.russell@live.com> | 2022-01-01 21:05:08 -0500 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2022-01-01 21:05:08 -0500 |
| commit | b1d244ba716a5e5311c8071967619dec40e4074f (patch) | |
| tree | 73046298d51851cd6f75cc3fef80624a5aaa01c1 | |
| parent | 20668657d4587d0f6d191da8c7f658ae6c949581 (diff) | |
| download | perlweeklychallenge-club-b1d244ba716a5e5311c8071967619dec40e4074f.tar.gz perlweeklychallenge-club-b1d244ba716a5e5311c8071967619dec40e4074f.tar.bz2 perlweeklychallenge-club-b1d244ba716a5e5311c8071967619dec40e4074f.zip | |
initial commit
| -rw-r--r-- | challenge-145/adam-russell/blog.txt | 0 | ||||
| -rw-r--r-- | challenge-145/adam-russell/blog1.txt | 0 | ||||
| -rw-r--r-- | challenge-145/adam-russell/cxx/ch-1.cxx | 25 | ||||
| -rw-r--r-- | challenge-145/adam-russell/cxx/ch-2.cxx | 0 | ||||
| -rw-r--r-- | challenge-145/adam-russell/perl/ch-1.pl | 20 | ||||
| -rw-r--r-- | challenge-145/adam-russell/perl/ch-2.pl | 68 | ||||
| -rw-r--r-- | challenge-145/adam-russell/prolog/ch-1.p | 10 | ||||
| -rw-r--r-- | challenge-145/adam-russell/prolog/ch-2.p | 0 |
8 files changed, 123 insertions, 0 deletions
diff --git a/challenge-145/adam-russell/blog.txt b/challenge-145/adam-russell/blog.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-145/adam-russell/blog.txt diff --git a/challenge-145/adam-russell/blog1.txt b/challenge-145/adam-russell/blog1.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-145/adam-russell/blog1.txt diff --git a/challenge-145/adam-russell/cxx/ch-1.cxx b/challenge-145/adam-russell/cxx/ch-1.cxx new file mode 100644 index 0000000000..d059e70c28 --- /dev/null +++ b/challenge-145/adam-russell/cxx/ch-1.cxx @@ -0,0 +1,25 @@ +#include<vector> +#include<iostream> + +class DotProduct{ + public: + int dot_product(std::vector<int>, std::vector<int>); +}; + +int DotProduct::dot_product(std::vector<int> a, std::vector<int> b){ + if(a.empty() && b.empty()){ + return 0; + } + int s = a.back(); + a.pop_back(); + int t = b.back(); + b.pop_back(); + return s * t + this->dot_product(a, b); +} + +int main(int argc, char** argv){ + DotProduct dp; + std::vector<int> a = {1, 2, 3}; + std::vector<int> b = {4, 5, 6}; + std::cout << dp.dot_product(a, b) << std::endl; +}
\ No newline at end of file diff --git a/challenge-145/adam-russell/cxx/ch-2.cxx b/challenge-145/adam-russell/cxx/ch-2.cxx new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-145/adam-russell/cxx/ch-2.cxx diff --git a/challenge-145/adam-russell/perl/ch-1.pl b/challenge-145/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..167bcd6cc2 --- /dev/null +++ b/challenge-145/adam-russell/perl/ch-1.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +## +# You are given 2 arrays of the same size, @a and @b. +# Write a script to implement the Dot Product. +## +sub dot_product{ + my($s, $t) = @_; + return $s->[0] * $t->[0] if(@{$s} == 1 && @{$t} == 1); + my $u = pop @{$s}; + my $v = pop @{$t}; + return $u * $v + dot_product($s, $t); +} + +MAIN:{ + my(@a, @b); + @a = (1, 2, 3); + @b = (4, 5, 6); + print dot_product(\@a, \@b) . "\n"; +}
\ No newline at end of file diff --git a/challenge-145/adam-russell/perl/ch-2.pl b/challenge-145/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..9f8ba48a44 --- /dev/null +++ b/challenge-145/adam-russell/perl/ch-2.pl @@ -0,0 +1,68 @@ +use strict; +use warnings; +## +# You are given a string $s. +# Write a script to create a Palindromic Tree for $s. +## +use Graph; +use boolean; +use Graph::Easy::Parser; + +use constant EMPTY => 0; +use constant IMAGINARY => -1; + +package EerTreeVertex{ + use Class::Struct; + struct( + start => q/$/, + end => q/$/, + length => q/$/, + suffix => q/EerTreeVertex/, + labelled => q/@/ + ); +} + +sub initialize{ + my $graph = new Graph(refvertexed => true); + my $root_empty = new EerTreeVertex( + length => EMPTY + ); + my $root_imaginary = new EerTreeVertex( + length => IMAGINARY + ); + $graph->add_edge($root_empty, $root_imaginary); + $graph->add_edge($root_imaginary, $root_imaginary); + return $graph; +} + +sub build_tree{ + my($s) = @_; + my @letters = split(//, $s); + my $eertree = initialize; + + return $eertree; +} + +sub eertree{ + my($s) = @_; + return build_tree($s); +} + +sub display_graph{ + my($graph) = @_; + my $s = $graph->stringify(); + my @s = split(/,/, $s); + my @lines; + for my $n (@s){ + my @a = split(/-/, $n); + push @lines, "[ $a[0] ] => [ ]" if @a == 1; + push @lines, "[ $a[0] ] => [ $a[1] ]" if @a > 1; + } + my $parser = new Graph::Easy::Parser(); + my $graph_viz = $parser->from_text(join("", @lines)); + print $graph_viz->as_ascii(); +} + +MAIN:{ + print eertree("redivider"); +}
\ No newline at end of file diff --git a/challenge-145/adam-russell/prolog/ch-1.p b/challenge-145/adam-russell/prolog/ch-1.p new file mode 100644 index 0000000000..1f4936c535 --- /dev/null +++ b/challenge-145/adam-russell/prolog/ch-1.p @@ -0,0 +1,10 @@ +dot_product([], [], DotProduct):- + DotProduct = 0. + +dot_product([A|T0], [B|T1], DotProduct):- + dot_product(T0, T1, DP), + DotProduct is (A * B) + DP. + +main:- + dot_product([1, 2, 3], [4, 5, 6], DotProduct), + write(DotProduct), nl.
\ No newline at end of file diff --git a/challenge-145/adam-russell/prolog/ch-2.p b/challenge-145/adam-russell/prolog/ch-2.p new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/challenge-145/adam-russell/prolog/ch-2.p |
