From b1d244ba716a5e5311c8071967619dec40e4074f Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sat, 1 Jan 2022 21:05:08 -0500 Subject: initial commit --- challenge-145/adam-russell/blog.txt | 0 challenge-145/adam-russell/blog1.txt | 0 challenge-145/adam-russell/cxx/ch-1.cxx | 25 ++++++++++++ challenge-145/adam-russell/cxx/ch-2.cxx | 0 challenge-145/adam-russell/perl/ch-1.pl | 20 ++++++++++ challenge-145/adam-russell/perl/ch-2.pl | 68 ++++++++++++++++++++++++++++++++ challenge-145/adam-russell/prolog/ch-1.p | 10 +++++ challenge-145/adam-russell/prolog/ch-2.p | 0 8 files changed, 123 insertions(+) create mode 100644 challenge-145/adam-russell/blog.txt create mode 100644 challenge-145/adam-russell/blog1.txt create mode 100644 challenge-145/adam-russell/cxx/ch-1.cxx create mode 100644 challenge-145/adam-russell/cxx/ch-2.cxx create mode 100644 challenge-145/adam-russell/perl/ch-1.pl create mode 100644 challenge-145/adam-russell/perl/ch-2.pl create mode 100644 challenge-145/adam-russell/prolog/ch-1.p create mode 100644 challenge-145/adam-russell/prolog/ch-2.p diff --git a/challenge-145/adam-russell/blog.txt b/challenge-145/adam-russell/blog.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-145/adam-russell/blog1.txt b/challenge-145/adam-russell/blog1.txt new file mode 100644 index 0000000000..e69de29bb2 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 +#include + +class DotProduct{ + public: + int dot_product(std::vector, std::vector); +}; + +int DotProduct::dot_product(std::vector a, std::vector 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 a = {1, 2, 3}; + std::vector 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 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 -- cgit