diff options
| author | Augie De Blieck Jr <augiedb@gmail.com> | 2023-10-22 22:04:52 -0400 |
|---|---|---|
| committer | Augie De Blieck Jr <augiedb@gmail.com> | 2023-10-22 22:04:52 -0400 |
| commit | 2ef9e488dd892b37b2bda89f61c75fb2ea20985f (patch) | |
| tree | e1c42586140520c5b897e9bdc61962be82785683 | |
| parent | 1407a3e91e6978a6b6d7685bc138c9e817dc6401 (diff) | |
| download | perlweeklychallenge-club-2ef9e488dd892b37b2bda89f61c75fb2ea20985f.tar.gz perlweeklychallenge-club-2ef9e488dd892b37b2bda89f61c75fb2ea20985f.tar.bz2 perlweeklychallenge-club-2ef9e488dd892b37b2bda89f61c75fb2ea20985f.zip | |
Challenge entry from Augie De Blieck Jr.
| -rw-r--r-- | challenge-239/augiedb/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-239/augiedb/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-239/augiedb/elixir/ch-1.exs | 74 | ||||
| -rw-r--r-- | challenge-239/augiedb/js/ch-1.js | 32 | ||||
| -rw-r--r-- | challenge-239/augiedb/perl/ch-1.pl | 108 | ||||
| -rw-r--r-- | challenge-239/augiedb/python/ch-1.py | 28 |
6 files changed, 244 insertions, 0 deletions
diff --git a/challenge-239/augiedb/blog.txt b/challenge-239/augiedb/blog.txt new file mode 100644 index 0000000000..bcdda7620e --- /dev/null +++ b/challenge-239/augiedb/blog.txt @@ -0,0 +1 @@ +https://variousandsundry.com/same-string-lets-functionalize-this-one/ diff --git a/challenge-239/augiedb/blog1.txt b/challenge-239/augiedb/blog1.txt new file mode 100644 index 0000000000..a380454cdf --- /dev/null +++ b/challenge-239/augiedb/blog1.txt @@ -0,0 +1 @@ +https://variousandsundry.com/same-string-part-deux-now-in-javascript-and-python/ diff --git a/challenge-239/augiedb/elixir/ch-1.exs b/challenge-239/augiedb/elixir/ch-1.exs new file mode 100644 index 0000000000..13a93711ef --- /dev/null +++ b/challenge-239/augiedb/elixir/ch-1.exs @@ -0,0 +1,74 @@ +## +## You are given two arrays of strings. +## +## Write a script to find out if the word created +## by concatenating the array elements is the same. +## +## Example: ("ab", "c") and ("a", "bc") are the same. +## ("ac", "b") and ("ab", "c") are not. +## +## +## LIMITS: +## Only two arrays to compare. +## But they can have as many string parts as they'd like, from 1 to some huge number. +## + +# Two arrays? How about a tuple of lists! + +defmodule SameString do + + def show_inputs({list1, list2}) do + IO.puts "Input: List1 = " + IO.inspect list1 + + IO.puts "Input: List2 = " + IO.inspect list2 + + {list1, list2} + end + + def combine_lists({list1, list2}) do + + string1 = reduce_string(list1) + string2 = reduce_string(list2) + + {string1, string2} + + end + + def reduce_string( list_of_strings ) do + + Enum.reduce(list_of_strings, "", fn characters, acc -> + acc <> characters + end) + + end + + def compare_strings({string1, string1}), do: true + def compare_strings({_, _}), do: false + + def show_output(true), do: IO.puts "Output: True" + def show_output(false), do: IO.puts "Output: False" + + def run_everything(tuple_of_lists) do + + tuple_of_lists + |> show_inputs() + |> combine_lists() + |> compare_strings() + |> show_output() + + end +end + + + + +SameString.run_everything( {["ab", "c"], ["a", "bc"]} ) +IO.puts '' +SameString.run_everything( {["ab", "c"], ["ac", "b"]} ) +IO.puts '' +SameString.run_everything( {["ab", "cd", "e"], ["abcde"]} ) + + + diff --git a/challenge-239/augiedb/js/ch-1.js b/challenge-239/augiedb/js/ch-1.js new file mode 100644 index 0000000000..db15e31cb0 --- /dev/null +++ b/challenge-239/augiedb/js/ch-1.js @@ -0,0 +1,32 @@ +// Same String + +main(["ab", "c"], ["a", "bc"]); +main(["ab", "c"], ["ac", "b"]); +main(["ab", "cd", "e"], ["abcde"]); + + +function main( arr1, arr2 ) { + + console.log('Input 1:') + console.log('@arr1 = (' + arr1 + ')') + console.log('@arr2 = (' + arr2 + ')') + + const arr1_string = combine_list(arr1) + const arr2_string = combine_list(arr2) + + const result = compare_strings(arr1_string, arr2_string) + + console.log('Output: ' + result) + console.log('') + +} + +function combine_list( arr ) { + return arr.reduce((acc, str) => acc + str) +} + +function compare_strings( str1, str2 ) { + return ( str1 == str2 ) ? true : false +} + + diff --git a/challenge-239/augiedb/perl/ch-1.pl b/challenge-239/augiedb/perl/ch-1.pl new file mode 100644 index 0000000000..6bed211ef1 --- /dev/null +++ b/challenge-239/augiedb/perl/ch-1.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl +use warnings; +use strict; + +## +## You are given two arrays of strings. +## +## Write a script to find out if the word created +## by concatenating the array elements is the same. +## +## Example: ("ab", "c") and ("a", "bc") are the same. +## ("ac", "b") and ("ab", "c") are not. +## +## +## LIMITS: +## Only two arrays to compare. +## But they can have as many string parts as they'd like, from 1 to some huge number. +## + +my @arr1 = ("ab", "c"); +my @arr2 = ("a", "bc"); +main(\@arr1, \@arr2); + +@arr1 = ("ab", "c"); +@arr2 = ("ac", "b"); +main(\@arr1, \@arr2); + +@arr1 = ("ab", "cd", "e"); +@arr2 = ("abcde"); +main(\@arr1, \@arr2); + + +sub main { + + my @arr1 = @{ shift() }; + my @arr2 = @{ shift() }; + + show_inputs(\@arr1, \@arr2); + my $combined1 = combine_arrays(\@arr1); + my $combined2 = combine_arrays(\@arr2); + my $results = compare_strings($combined1, $combined2); + show_output( $results ); + +} + +sub show_inputs { + + my @arr1 = @{ shift() }; + my @arr2 = @{ shift() }; + + print 'Input: @arr1 = ' . ( pretty_print_array(\@arr1) ) . "\n"; + print 'Input: @arr2 = ' . ( pretty_print_array(\@arr2) ) . "\n"; + + return; + +} + +sub show_output { + + my $final_results = shift(); + + print "Output: " . $final_results . "\n\n"; + +} + + +sub combine_arrays { + + my @arr = @{ shift() }; + my $combined_string = ''; + + map{ $combined_string .= $_; } @arr; + + return $combined_string; +} + + +sub compare_strings { + + my ($str1, $str2) = @_; + return $str1 eq $str2 ? 'true' : 'false'; + +} + + + +sub pretty_print_array { + + ## Total overkill, but I'm new and over-enthusiastic. + ## In reality, I'd find something on CPAN for this. + + my @array = @{ shift() }; + my $length = scalar @array; + my $count = 1; + + my $pretty_string = "("; + + foreach my $value(@array) { + $pretty_string .= '"' . $value . '"'; + $pretty_string .= ", " if $count < $length; + $count++; + } + + $pretty_string .= ")"; + + return $pretty_string; +} + diff --git a/challenge-239/augiedb/python/ch-1.py b/challenge-239/augiedb/python/ch-1.py new file mode 100644 index 0000000000..e8eb02e859 --- /dev/null +++ b/challenge-239/augiedb/python/ch-1.py @@ -0,0 +1,28 @@ +from functools import reduce + +def show_inputs(arr1, arr2): + print( "Input: @arr1 = ", arr1 ) + print( " @arr2 = ", arr2 ) + +def reduce_string(arr): + return reduce(lambda x, y: x + y, arr) + +def compare_strings(str1, str2): + return "true" if str1 == str2 else "false" + +def show_output(final_answer): + print( "Output: ", final_answer, "\n" ) + +def run_everything(arr1, arr2): + show_inputs(arr1, arr2) + str1 = reduce_string(arr1) + str2 = reduce_string(arr2) + show_output( compare_strings(str1, str2) ) + +## Run process with example data +run_everything(["ab", "c"], ["a", "bc"] ) +run_everything(["ab", "c"], ["ac", "b"] ) +run_everything(["ab", "cd", "e"], ["abcde"] ) + + + |
