From 5c645bce1bb78104f8f9ecc2905f5a8a1a326104 Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Thu, 6 Jul 2023 07:50:09 -0500 Subject: Week 224 task 1 solution --- challenge-224/bob-lied/perl/ch-1.pl | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 challenge-224/bob-lied/perl/ch-1.pl diff --git a/challenge-224/bob-lied/perl/ch-1.pl b/challenge-224/bob-lied/perl/ch-1.pl new file mode 100644 index 0000000000..4531f80102 --- /dev/null +++ b/challenge-224/bob-lied/perl/ch-1.pl @@ -0,0 +1,63 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-1.pl Perl Weekly Challenge 224 Task 1 Special Notes +#============================================================================= +# Copyright (c) 2023, Bob Lied +#============================================================================= +# You are given two strings, $source and $target. +# Write a script to find out if using the characters (only once) from source, +# a target string can be created. +# Example 1 Input: $source = "abc" $target = "xyz" +# Output: false + +# Example 2 Input: $source = "scriptinglanguage" $target = "perl" +# Output: true + +# Example 3 Input: $source = "aabbcc" $target = "abc" +# Output: true +#============================================================================= + +use v5.36; + +use builtin qw/true false/; no warnings "experimental::builtin"; + +use Getopt::Long; +my $Verbose = 0; +my $DoTest = 0; + +GetOptions("test" => \$DoTest, "verbose" => \$Verbose); +exit(!runTest()) if $DoTest; + +sub usage() { "Usage: $0 source target" } + +do { say STDERR usage(); exit 1 } unless @ARGV == 2; + +say specialNotes(@ARGV); + +sub specialNotes($source, $target) +{ + for my $char ( split(//, $target) ) + { + if ( my $atPosition = index($source, $char) < 0 ) + { + return "false"; + } + else + { + substr($source, $atPosition, 1) = ""; + } + } + return "true"; +} + +sub runTest +{ + use Test2::V0; + + is( specialNotes("abc", "xyz"), "false", "Example 1"); + is( specialNotes("scriptinhlanguage", "perl"), "true", "Example 2"); + is( specialNotes("aabbcc", "abc"), "true", "Example 3"); + + done_testing; +} -- cgit From 8412e1a7dddd883535ff2f33bbf6613729fa107b Mon Sep 17 00:00:00 2001 From: "Jaldhar H. Vyas" Date: Sun, 9 Jul 2023 23:57:42 -0400 Subject: Challenge 224 by Jaldhar H. Vyas. --- challenge-224/jaldhar-h-vyas/blog.txt | 1 + challenge-224/jaldhar-h-vyas/perl/ch-1.pl | 20 +++++++++++ challenge-224/jaldhar-h-vyas/perl/ch-2.pl | 51 +++++++++++++++++++++++++++++ challenge-224/jaldhar-h-vyas/raku/ch-1.sh | 3 ++ challenge-224/jaldhar-h-vyas/raku/ch-2.raku | 48 +++++++++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 challenge-224/jaldhar-h-vyas/blog.txt create mode 100755 challenge-224/jaldhar-h-vyas/perl/ch-1.pl create mode 100755 challenge-224/jaldhar-h-vyas/perl/ch-2.pl create mode 100755 challenge-224/jaldhar-h-vyas/raku/ch-1.sh create mode 100755 challenge-224/jaldhar-h-vyas/raku/ch-2.raku diff --git a/challenge-224/jaldhar-h-vyas/blog.txt b/challenge-224/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..ac44b6425e --- /dev/null +++ b/challenge-224/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2021/07/perl_weekly_challenge_week_224.html diff --git a/challenge-224/jaldhar-h-vyas/perl/ch-1.pl b/challenge-224/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..731b3e16ee --- /dev/null +++ b/challenge-224/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub makeBag { + my ($string) = @_; + my %bag; + + for my $c (split //, $string) { + $bag{$c}++; + } + + return %bag; +} + +my ($source, $target) = @ARGV; +my %s = makeBag($source); +my %t = makeBag($target); + +say 0+(scalar grep { !exists $s{$_} || $s{$_} < $t{$_} } keys %t) ? 'false' : 'true'; diff --git a/challenge-224/jaldhar-h-vyas/perl/ch-2.pl b/challenge-224/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..cf22cedb7f --- /dev/null +++ b/challenge-224/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub isValid { + my ($num) = @_; + return length $num < 2 || substr($num, 0, 1) != '0'; +} + +sub checkAddition { + my ($res, $a, $b, $c) = @_; + if (!isValid($a) || !isValid($b)) { + return undef; + } + my $sum = $a + $b; + + if ($sum eq $c) { + push @{$res}, $sum; + return 1; + } + + if (length $c <= length $sum || $sum != substr($c, 0, length $sum)) { + return undef; + } else { + push @{$res}, $sum; + + return checkAddition($res, $b, $sum, substr($c, length $sum)); + } +} + +sub additiveSequence { + my ($n) = @_; + my @res; + my $l = length $n; + + for my $i (1 .. int($l / 2) + 1) { + for my $j (1 .. int(($l - $i) / 2) + 1) { + if (checkAddition(\@res, substr($n, 0, $i), substr($n, $i, $j), substr($n, $i + $j))) { + unshift @res, substr($n, $i, $j); + unshift @res, substr($n, 0, $i); + return @res; + } + } + } + + return (); +} + +my $num = shift @ARGV; +my @seq = additiveSequence($num); +say scalar @seq > 0 ? 'true' : 'false'; diff --git a/challenge-224/jaldhar-h-vyas/raku/ch-1.sh b/challenge-224/jaldhar-h-vyas/raku/ch-1.sh new file mode 100755 index 0000000000..4c9aa26edc --- /dev/null +++ b/challenge-224/jaldhar-h-vyas/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e 'say bag(@*ARGS[1].comb) ⊆ bag(@*ARGS[0].comb);' $@ diff --git a/challenge-224/jaldhar-h-vyas/raku/ch-2.raku b/challenge-224/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..78447eee03 --- /dev/null +++ b/challenge-224/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,48 @@ +#!/usr/bin/raku + +sub isValid($num) { + return $num.chars < 2 || $num.substr(0, 1) != '0'; +} + +sub checkAddition(@res, $a, $b, $c) { + if !isValid($a) || !isValid($b) { + return False; + } + my $sum = $a + $b; + + if $sum == $c { + @res.push($sum); + return True; + } + + if $c.chars <= $sum.chars || $sum != $c.substr(0, $sum.chars) { + return False; + } else { + @res.push($sum); + + return checkAddition(@res, $b, $sum, $c.substr($sum.chars)); + } +} + +sub additiveSequence($n) { + my @res; + my $l = $n.chars; + + for 1 .. $l div 2 + 1 -> $i { + for 1 .. ($l - $i) div 2 + 1 -> $j { + if checkAddition(@res, $n.substr(0, $i), $n.substr($i, $j), $n.substr($i + $j)) { + @res.unshift($n.substr($i, $j)); + @res.unshift($n.substr(0, $i)); + return @res; + } + } + } + + return (); +} + +sub MAIN( + $string where { $string.chars > 2 && $string ~~ /^ <[0 .. 9]>+ $/ }, +) { + say additiveSequence($string).elems > 0; +} -- cgit From 183bf7cb7c553eeb6ace11666c8df7dab74b596e Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Sun, 9 Jul 2023 23:46:47 -0600 Subject: Solve PWC 225 --- challenge-225/wlmb/blog.txt | 1 + challenge-225/wlmb/perl/ch-1.pl | 12 ++++++++++++ challenge-225/wlmb/perl/ch-2.pl | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 challenge-225/wlmb/blog.txt create mode 100755 challenge-225/wlmb/perl/ch-1.pl create mode 100755 challenge-225/wlmb/perl/ch-2.pl diff --git a/challenge-225/wlmb/blog.txt b/challenge-225/wlmb/blog.txt new file mode 100644 index 0000000000..a61c88b2ab --- /dev/null +++ b/challenge-225/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2023/07/09/PWC225/ diff --git a/challenge-225/wlmb/perl/ch-1.pl b/challenge-225/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..6f9a7b3e1b --- /dev/null +++ b/challenge-225/wlmb/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +# Perl weekly challenge 225 +# Task 1: Max Words +# +# See https://wlmb.github.io/2023/07/09/PWC225/#task-1-max-words +use v5.36; +use List::Util qw(max); +die <<~"FIN" unless @ARGV; + Usage: $0 S1 [S2...] + to count the maximum number of space separated words in sentences S1 S2... + FIN +say join "\n", @ARGV, " -> ", max map {0+@{[split " "]}} @ARGV; diff --git a/challenge-225/wlmb/perl/ch-2.pl b/challenge-225/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..1235a9fa7b --- /dev/null +++ b/challenge-225/wlmb/perl/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +# Perl weekly challenge 225 +# Task 2: Left Right Sum Diff +# +# See https://wlmb.github.io/2023/07/09/PWC225/#task-2-left-right-sum-diff +use v5.36; +use List::Util qw(reductions); +die <<~"FIN" unless @ARGV; + Usage: $0 N1 [N2...] + to find the differences of the right and left sums of the list of + numbers N1 N2... + FIN +my @input= (0, @ARGV, 0); +my $last_index=@input-3; +my ($left, $right) = map {[reductions {$a+$b} @$_]} + [@input[0..$last_index]], [((reverse @input)[0..$last_index])]; +my @output = map {abs($left->[$_] - $right->[-$_-1])} 0..$last_index; +say "@ARGV -> @output"; -- cgit From 77465447ff12a5654bd88f85ae81cbabc0a1359c Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Sun, 9 Jul 2023 23:49:19 -0700 Subject: Robbie Hatley's solutions to The Weekly Challenge 225. --- challenge-225/robbie-hatley/blog.txt | 1 + challenge-225/robbie-hatley/perl/ch-1.pl | 104 +++++++++++++++++++++ challenge-225/robbie-hatley/perl/ch-2.pl | 156 +++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 challenge-225/robbie-hatley/blog.txt create mode 100755 challenge-225/robbie-hatley/perl/ch-1.pl create mode 100755 challenge-225/robbie-hatley/perl/ch-2.pl diff --git a/challenge-225/robbie-hatley/blog.txt b/challenge-225/robbie-hatley/blog.txt new file mode 100644 index 0000000000..ff96bb5c35 --- /dev/null +++ b/challenge-225/robbie-hatley/blog.txt @@ -0,0 +1 @@ +https://hatley-software.blogspot.com/2023/07/robbie-hatleys-solutions-to-weekly_9.html \ No newline at end of file diff --git a/challenge-225/robbie-hatley/perl/ch-1.pl b/challenge-225/robbie-hatley/perl/ch-1.pl new file mode 100755 index 0000000000..bd54fccf75 --- /dev/null +++ b/challenge-225/robbie-hatley/perl/ch-1.pl @@ -0,0 +1,104 @@ +#! /bin/perl -CSDA + +=pod + +-------------------------------------------------------------------------------------------------------------- +COLOPHON: +This is a 110-character-wide Unicode UTF-8 Perl-source-code text file with hard Unix line breaks ("\x0A"). +¡Hablo Español! Говорю Русский. Björt skjöldur. ॐ नमो भगवते वासुदेवाय. 看的星星,知道你是爱。麦藁雪、富士川町、山梨県。 + +-------------------------------------------------------------------------------------------------------------- +TITLE BLOCK: +ch-1.pl +Solutions in Perl for The Weekly Challenge 225-1. +Written by Robbie Hatley on Sunday July 9, 2023. + +-------------------------------------------------------------------------------------------------------------- +PROBLEM DESCRIPTION: +Task 1: Max Words +Submitted by: Mohammad S Anwar +Given a list of sentences, write a script to find the maximum word count of the sentences of the list. + +Example 1: +Input: + @list = + ( + "Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference." + ); +Output: 8 + +Example 2: +Input: + @list = + ( + "The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members.", + ); +Output: 7 + +-------------------------------------------------------------------------------------------------------------- +PROBLEM NOTES: +This is just a matter of using split to parse the sentences of each list to words, then counting the words, +then using List::Util 'max' to find the maximum word count of any sentence in the list. Something like this: +my $max = max map {scalar split /[ .]+/, $_} @sentences; + +-------------------------------------------------------------------------------------------------------------- +IO NOTES: +Input is via either built-in variables or via @ARGV. If using @ARGV, provide one argument which must be a +double-quoted array of arrays of single-quoted sentences in proper Perl syntax, apostrophes escaped, like so: +./ch-1.pl "(['I go.', 'She ran home.', 'I ate seven hot dogs.'],['She sat.', 'I didn\'t sit.'])" + +Output is to STDOUT and will be each list of sentences, followed by max word count. + +=cut + +# ------------------------------------------------------------------------------------------------------------ +# PRELIMINARIES: +use v5.36; +use strict; +use warnings; +use utf8; +use Sys::Binmode; +use Time::HiRes 'time'; +use List::Util 'max'; +$"=', '; + +# ------------------------------------------------------------------------------------------------------------ +# MAIN BODY OF PROGRAM: + +# Start timer: +my $t0 = time; + +# Default inputs: +my @lists = +( + [ + "Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference.", + ], + [ + "The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members.", + ], +); + +# Non-default inputs: +if (@ARGV) {@lists = eval($ARGV[0]);} + +# Main loop: +for my $sentences (@lists) { + my $max = max map {scalar split /[ .]+/, $_} @$sentences; + say ''; + say 'Sentences:'; + say for @$sentences; + say "Max word count = $max"; +} + +# Determine and print execution time: +my $µs = 1000000 * (time - $t0); +printf("\nExecution time was %.3fµs.\n", $µs); diff --git a/challenge-225/robbie-hatley/perl/ch-2.pl b/challenge-225/robbie-hatley/perl/ch-2.pl new file mode 100755 index 0000000000..67248944d2 --- /dev/null +++ b/challenge-225/robbie-hatley/perl/ch-2.pl @@ -0,0 +1,156 @@ +#! /bin/perl -CSDA + +=pod + +-------------------------------------------------------------------------------------------------------------- +COLOPHON: +This is a 110-character-wide Unicode UTF-8 Perl-source-code text file with hard Unix line breaks ("\x0A"). +¡Hablo Español! Говорю Русский. Björt skjöldur. ॐ नमो भगवते वासुदेवाय. 看的星星,知道你是爱。麦藁雪、富士川町、山梨県。 + +-------------------------------------------------------------------------------------------------------------- +TITLE BLOCK: +ch-2.pl +Solutions in Perl for The Weekly Challenge 225-2. +Written by Robbie Hatley on Sunday July 9, 2023. + +-------------------------------------------------------------------------------------------------------------- +PROBLEM DESCRIPTION: +Task 2: Left Right Sum Diff +Submitted by: Mohammad S Anwar +You are given an array of integers, @ints. +Write a script to return the left right sum diff array as shown below: +@ints = (a, b, c, d, e) +@left = ( 0, a, (a+b), (a+b+c), (a+b+c+d) ) +@right = ( (b+c+d+e), (c+d+e), (d+e), e, 0 ) +@left_right_sum_diff = +( + | 0 - (b+c+d+e) |, + | a - (c+d+e) |, + | (a+b) - (d+e) |, + | (a+b+c) - e |, + | (a+b+c+d) - 0 |, +) + +Example 1: +Input: @ints = (10, 4, 8, 3) +Output: (15, 1, 11, 22) +@left = (0, 10, 14, 22) +@right = (15, 11, 3, 0) +@left_right_sum_diff = ( |0-15|, |10-11|, |14-3|, |22-0|) + = (15, 1, 11, 22) + +Example 2: +Input: @ints = (1) +Output: (0) +@left = (0) +@right = (0) +@left_right_sum_diff = ( |0-0| ) = (0) + +Example 3: +Input: @ints = (1, 2, 3, 4, 5) +Output: (14, 11, 6, 1, 19) +@left = (0, 1, 3, 6, 10) +@right = (14, 12, 9, 5, 0) +@left_right_sum_diff = ( |0-14|, |1-12|, |3-9|, |6-5|, |10-0|) + = (14, 11, 6, 1, 10) + +-------------------------------------------------------------------------------------------------------------- +PROBLEM NOTES: +This is just a matter of making subs to compute "left" and "right" sequences of partial sums of as defined +by this problem (which is NOT the way math textbooks define "sequence of partial sums", by the way), +then computing the array of absolute values of index-wise differences between @left and @right. + +-------------------------------------------------------------------------------------------------------------- +IO NOTES: +Input is via either built-in variables or via @ARGV. If using @ARGV, provide one argument which must be a +single-quoted array of arrays of integers in proper Perl syntax, like so: +./ch-2.pl '([13,0,96,-8,3],[11,2,6,4,-83,-42])' + +Output is to STDOUT and will be each input array, followed by the corresponding Left-Right Sum-Diff Array. + +=cut + +# ------------------------------------------------------------------------------------------------------------ +# PRELIMINARIES: +use v5.36; +use strict; +use warnings; +use utf8; +use Sys::Binmode; +use Time::HiRes 'time'; +$"=', '; + +# ------------------------------------------------------------------------------------------------------------ +# SUBROUTINES: +sub lsps ($aref) { # "lsps" = "Left Sequence of Partial Sums" + my $size = scalar @$aref; + my @lsps = (); + for ( my $i = 0 ; $i < $size ; ++$i ) { + my $term = 0; + for ( my $j = 0 ; $j < $i ; ++$j ) { + $term += $$aref[$j]; + } + push @lsps, $term; + } + return @lsps +} + +sub rsps ($aref) { # "rsps" = "Right Sequence of Partial Sums" + my $size = scalar @$aref; + my @lsps = (); + for ( my $i = 0 ; $i < $size ; ++$i ) { + my $term = 0; + for ( my $j = $i+1 ; $j < $size ; ++$j ) { + $term += $$aref[$j]; + } + push @lsps, $term; + } + return @lsps +} + +sub diff ($aref1, $aref2) { # "diff" = "difference of sequences" + my $size1 = scalar @$aref1; + my $size2 = scalar @$aref2; + if ($size1 != $size2) { + die "Error in sub \"dos\": arrays not same size!\n$!\n"; + } + my @diffs; + for ( my $i = 0 ; $i < $size1 ; ++$i ) { + push @diffs, abs($$aref1[$i]-$$aref2[$i]); + } + return @diffs; +} + +# ------------------------------------------------------------------------------------------------------------ +# MAIN BODY OF PROGRAM: + +# Start timer: +my $t0 = time; + +# Default inputs: +my @arrays = +( + [10, 4, 8, 3], + [1], + [1, 2, 3, 4, 5], +); + +# Non-default inputs: +if (@ARGV) {@arrays = eval($ARGV[0]);} + +# Main loop: +for my $aref (@arrays) { + my @lsps = lsps($aref); + my @rsps = rsps($aref); + my @diff = diff(\@lsps, \@rsps); + say ''; + say "array = (@$aref)"; + say "lsps = (@lsps)"; + say "rsps = (@rsps)"; + say "diff = (@diff)"; +} + +# Determine and print execution time: +my $µs = 1000000 * (time - $t0); +printf("\nExecution time was %.3fµs.\n", $µs); +exit 0; -- cgit From 04ae72384683dc2f1a8b056b01719187c20e16a4 Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Sun, 9 Jul 2023 23:57:53 -0700 Subject: minor corrections to my 225 solutions --- challenge-225/robbie-hatley/perl/ch-1.pl | 2 +- challenge-225/robbie-hatley/perl/ch-2.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-225/robbie-hatley/perl/ch-1.pl b/challenge-225/robbie-hatley/perl/ch-1.pl index bd54fccf75..cbcca1f25a 100755 --- a/challenge-225/robbie-hatley/perl/ch-1.pl +++ b/challenge-225/robbie-hatley/perl/ch-1.pl @@ -101,4 +101,4 @@ for my $sentences (@lists) { # Determine and print execution time: my $µs = 1000000 * (time - $t0); -printf("\nExecution time was %.3fµs.\n", $µs); +printf("\nExecution time was %.0fµs.\n", $µs); diff --git a/challenge-225/robbie-hatley/perl/ch-2.pl b/challenge-225/robbie-hatley/perl/ch-2.pl index 67248944d2..9c49ef8bab 100755 --- a/challenge-225/robbie-hatley/perl/ch-2.pl +++ b/challenge-225/robbie-hatley/perl/ch-2.pl @@ -152,5 +152,5 @@ for my $aref (@arrays) { # Determine and print execution time: my $µs = 1000000 * (time - $t0); -printf("\nExecution time was %.3fµs.\n", $µs); +printf("\nExecution time was %.0fµs.\n", $µs); exit 0; -- cgit From 22729a1a175e2811ab2c47e496c766513c757ef9 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 10 Jul 2023 08:08:07 +0000 Subject: Challenge 225 Solutions (Raku) --- challenge-225/mark-anderson/raku/ch-1.raku | 15 +++++++++++++++ challenge-225/mark-anderson/raku/ch-2.raku | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 challenge-225/mark-anderson/raku/ch-1.raku create mode 100644 challenge-225/mark-anderson/raku/ch-2.raku diff --git a/challenge-225/mark-anderson/raku/ch-1.raku b/challenge-225/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..847f907e52 --- /dev/null +++ b/challenge-225/mark-anderson/raku/ch-1.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku +use Test; + +is max-words(("Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference.")), 8; + +is max-words(("The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members.")), 7; + +sub max-words($list) +{ + $list>>.words>>.elems.max +} diff --git a/challenge-225/mark-anderson/raku/ch-2.raku b/challenge-225/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..33d6f3983b --- /dev/null +++ b/challenge-225/mark-anderson/raku/ch-2.raku @@ -0,0 +1,14 @@ +#!/usr/bin/env raku +use Test; + +is-deeply left-right-sum-diff((10,4,8,3)), (15,1,11,22); +is-deeply left-right-sum-diff((1)), (0,); +is-deeply left-right-sum-diff((1,2,3,4,5)), (14,11,6,1,10); + +sub left-right-sum-diff($list) +{ + my $left = [\+] (0, |$list[0..*-2]); + my $right = ([\+] (0, |$list.reverse[0..*-2])).reverse; + + ($left >>-<< $right)>>.abs +} -- cgit From 1aa9e0e155ec5dd01700666f85453eb7e0f16521 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 10 Jul 2023 08:23:26 +0000 Subject: Challenge 225 Solutions (Raku) --- challenge-225/mark-anderson/raku/ch-2.raku | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-225/mark-anderson/raku/ch-2.raku b/challenge-225/mark-anderson/raku/ch-2.raku index 33d6f3983b..ce183f3e99 100644 --- a/challenge-225/mark-anderson/raku/ch-2.raku +++ b/challenge-225/mark-anderson/raku/ch-2.raku @@ -7,8 +7,8 @@ is-deeply left-right-sum-diff((1,2,3,4,5)), (14,11,6,1,10); sub left-right-sum-diff($list) { - my $left = [\+] (0, |$list[0..*-2]); - my $right = ([\+] (0, |$list.reverse[0..*-2])).reverse; + my $left = [\+] (0, |$list[^(*-1)]); + my $right = ([\+] (0, |$list.reverse[^(*-1)])).reverse; ($left >>-<< $right)>>.abs } -- cgit From f32913a30ea8e46548e1e4335c15dd49d9b02c61 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 10 Jul 2023 09:38:50 +0000 Subject: Challenge 225 Solutions (Raku) --- challenge-225/mark-anderson/raku/ch-2.raku | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/challenge-225/mark-anderson/raku/ch-2.raku b/challenge-225/mark-anderson/raku/ch-2.raku index ce183f3e99..d5113ee5db 100644 --- a/challenge-225/mark-anderson/raku/ch-2.raku +++ b/challenge-225/mark-anderson/raku/ch-2.raku @@ -5,10 +5,12 @@ is-deeply left-right-sum-diff((10,4,8,3)), (15,1,11,22); is-deeply left-right-sum-diff((1)), (0,); is-deeply left-right-sum-diff((1,2,3,4,5)), (14,11,6,1,10); -sub left-right-sum-diff($list) +multi left-right-sum-diff($n) { - my $left = [\+] (0, |$list[^(*-1)]); - my $right = ([\+] (0, |$list.reverse[^(*-1)])).reverse; + my $list = (0, |$n, 0); + + my $left = [\+] $list[^(*-2)]; + my $right = ([\+] $list[$list.end...2]).reverse; ($left >>-<< $right)>>.abs } -- cgit From 40a12d1d83d5c7a31f99d785214d7ce8e2318959 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 10 Jul 2023 09:41:20 +0000 Subject: Challenge 225 Solutions (Raku) --- challenge-225/mark-anderson/raku/ch-2.raku | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-225/mark-anderson/raku/ch-2.raku b/challenge-225/mark-anderson/raku/ch-2.raku index d5113ee5db..42eb41f162 100644 --- a/challenge-225/mark-anderson/raku/ch-2.raku +++ b/challenge-225/mark-anderson/raku/ch-2.raku @@ -5,7 +5,7 @@ is-deeply left-right-sum-diff((10,4,8,3)), (15,1,11,22); is-deeply left-right-sum-diff((1)), (0,); is-deeply left-right-sum-diff((1,2,3,4,5)), (14,11,6,1,10); -multi left-right-sum-diff($n) +sub left-right-sum-diff($n) { my $list = (0, |$n, 0); -- cgit From 0d641baa00e5f20a56f474a0c02f2806cdf9317c Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 10 Jul 2023 10:20:27 +0000 Subject: Challenge 225 Solutions (Raku) --- challenge-225/mark-anderson/raku/ch-2.raku | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/challenge-225/mark-anderson/raku/ch-2.raku b/challenge-225/mark-anderson/raku/ch-2.raku index 42eb41f162..f6a86c16bb 100644 --- a/challenge-225/mark-anderson/raku/ch-2.raku +++ b/challenge-225/mark-anderson/raku/ch-2.raku @@ -5,6 +5,11 @@ is-deeply left-right-sum-diff((10,4,8,3)), (15,1,11,22); is-deeply left-right-sum-diff((1)), (0,); is-deeply left-right-sum-diff((1,2,3,4,5)), (14,11,6,1,10); +sub infix:($a, $b) +{ + abs $a - $b +} + sub left-right-sum-diff($n) { my $list = (0, |$n, 0); @@ -12,5 +17,5 @@ sub left-right-sum-diff($n) my $left = [\+] $list[^(*-2)]; my $right = ([\+] $list[$list.end...2]).reverse; - ($left >>-<< $right)>>.abs + $left >>diff-abs<< $right } -- cgit From ef95427490fc6f52da98cb1dbabc31e844619523 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 10 Jul 2023 13:45:41 +0000 Subject: Challenge 225 Solutions (Raku) --- challenge-225/mark-anderson/raku/ch-2.raku | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/challenge-225/mark-anderson/raku/ch-2.raku b/challenge-225/mark-anderson/raku/ch-2.raku index f6a86c16bb..d2a831657f 100644 --- a/challenge-225/mark-anderson/raku/ch-2.raku +++ b/challenge-225/mark-anderson/raku/ch-2.raku @@ -5,10 +5,7 @@ is-deeply left-right-sum-diff((10,4,8,3)), (15,1,11,22); is-deeply left-right-sum-diff((1)), (0,); is-deeply left-right-sum-diff((1,2,3,4,5)), (14,11,6,1,10); -sub infix:($a, $b) -{ - abs $a - $b -} +sub infix:<|-|>($a, $b) { abs $a - $b } sub left-right-sum-diff($n) { @@ -17,5 +14,5 @@ sub left-right-sum-diff($n) my $left = [\+] $list[^(*-2)]; my $right = ([\+] $list[$list.end...2]).reverse; - $left >>diff-abs<< $right + $left >>|-|<< $right } -- cgit From 54a9e6263da63d4fce1c6e3b15051774daf8ea42 Mon Sep 17 00:00:00 2001 From: Andreas Vögele Date: Mon, 10 Jul 2023 09:16:27 +0200 Subject: Challenge 225 by Andreas Vögele MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- challenge-225/andreas-voegele/kotlin/ch-1.kts | 27 ++++++++++++++++++++++ challenge-225/andreas-voegele/kotlin/ch-2.kts | 23 +++++++++++++++++++ challenge-225/andreas-voegele/perl/ch-1.pl | 27 ++++++++++++++++++++++ challenge-225/andreas-voegele/perl/ch-2.pl | 33 +++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100755 challenge-225/andreas-voegele/kotlin/ch-1.kts create mode 100755 challenge-225/andreas-voegele/kotlin/ch-2.kts create mode 100755 challenge-225/andreas-voegele/perl/ch-1.pl create mode 100755 challenge-225/andreas-voegele/perl/ch-2.pl diff --git a/challenge-225/andreas-voegele/kotlin/ch-1.kts b/challenge-225/andreas-voegele/kotlin/ch-1.kts new file mode 100755 index 0000000000..8f99122e31 --- /dev/null +++ b/challenge-225/andreas-voegele/kotlin/ch-1.kts @@ -0,0 +1,27 @@ +#!/usr/bin/env kotlin + +/* + * You are given a list of sentences. A sentence is a list of words that are + * separated by a single space with no leading or trailing spaces. Write a + * script to find out the maximum number of words that appear in a single + * sentence. + */ + +fun maxWords(vararg sentences: String): Int = + sentences.maxOfOrNull { it.split(' ').size } ?: 0 + +println( + maxWords( + "Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference." + ) +) + +println( + maxWords( + "The Weekly Challenge.", + "Kotlin is the most interesting guest language.", + "Team PWC has over 300 members." + ) +) diff --git a/challenge-225/andreas-voegele/kotlin/ch-2.kts b/challenge-225/andreas-voegele/kotlin/ch-2.kts new file mode 100755 index 0000000000..a8674c28c7 --- /dev/null +++ b/challenge-225/andreas-voegele/kotlin/ch-2.kts @@ -0,0 +1,23 @@ +#!/usr/bin/env kotlin + +/* + * You are given an array of integers. For each element calculate the the + * sums of the elements to the left and right. Return the differences between + * these sums. + */ + +fun leftRightSumDiff(ints: IntArray): IntArray { + val differences = IntArray(ints.size) + var leftSum = 0 + var rightSum = ints.sum() + ints.forEachIndexed { i, n -> + rightSum -= n + differences[i] = Math.abs(leftSum - rightSum) + leftSum += n + } + return differences +} + +println(leftRightSumDiff(intArrayOf(10, 4, 8, 3)).contentToString()) +println(leftRightSumDiff(intArrayOf(1)).contentToString()) +println(leftRightSumDiff(intArrayOf(1, 2, 3, 4, 5)).contentToString()) diff --git a/challenge-225/andreas-voegele/perl/ch-1.pl b/challenge-225/andreas-voegele/perl/ch-1.pl new file mode 100755 index 0000000000..51438b7327 --- /dev/null +++ b/challenge-225/andreas-voegele/perl/ch-1.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +# You are given a list of sentences. A sentence is a list of words that are +# separated by a single space with no leading or trailing spaces. Write a +# script to find out the maximum number of words that appear in a single +# sentence. + +use 5.036; +use utf8; + +use List::Util qw(max); + +sub max_words (@sentences) { + return max 0, map { scalar split } @sentences; +} + +say max_words( + 'Perl and Raku belong to the same family.', + 'I love Perl.', + 'The Perl and Raku Conference.' +); + +say max_words( + 'The Weekly Challenge.', + 'Kotlin is the most interesting guest language.', + 'Team PWC has over 300 members.' +); diff --git a/challenge-225/andreas-voegele/perl/ch-2.pl b/challenge-225/andreas-voegele/perl/ch-2.pl new file mode 100755 index 0000000000..760eba70ee --- /dev/null +++ b/challenge-225/andreas-voegele/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +# You are given an array of integers. For each element calculate the the sums +# of the elements to the left and right. Return the differences between these +# sums. + +use 5.036; +use utf8; + +use experimental qw(builtin for_list); + +use builtin qw(indexed); +use List::Util qw(sum0); + +sub left_right_sum_diff (@ints) { + my @differences; + my $left_sum = 0; + my $right_sum = sum0 @ints; + for my ($i, $n) (indexed @ints) { + $right_sum -= $n; + $differences[$i] = abs $left_sum - $right_sum; + $left_sum += $n; + } + return @differences; +} + +sub format_array (@array) { + return '(' . join(', ', @array) . ')'; +} + +say format_array(left_right_sum_diff(10, 4, 8, 3)); +say format_array(left_right_sum_diff(1)); +say format_array(left_right_sum_diff(1, 2, 3, 4, 5)); -- cgit From 8e2b8846bba0cfe40014305a690daceb23e206e2 Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Mon, 10 Jul 2023 11:37:46 -0400 Subject: Week 225 --- challenge-225/zapwai/perl/ch-1.pl | 12 ++++++++++++ challenge-225/zapwai/perl/ch-2.pl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 challenge-225/zapwai/perl/ch-1.pl create mode 100644 challenge-225/zapwai/perl/ch-2.pl diff --git a/challenge-225/zapwai/perl/ch-1.pl b/challenge-225/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..79c7ae9c82 --- /dev/null +++ b/challenge-225/zapwai/perl/ch-1.pl @@ -0,0 +1,12 @@ +use v5.30; +my @list = ("Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."); +my $max = 0; +for my $sent (@list) { + my @L = split(" ", $sent); + my $c = @L; + $max = $c if ($c > $max); +} +say "Input: \@list = @list"; +say "Output: $max"; diff --git a/challenge-225/zapwai/perl/ch-2.pl b/challenge-225/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..5a75e90c27 --- /dev/null +++ b/challenge-225/zapwai/perl/ch-2.pl @@ -0,0 +1,30 @@ +use v5.30; +my @ints = (10, 4, 8, 3); +#my @ints = (1,2,3,4,5); +my @left = left(@ints); +my @right = right(@ints); +my @diff; +push @diff, abs $left[$_] - $right[$_] for (0 .. $#left); +say "Input: \@ints = @ints"; +say "Output: @diff"; +say "\t\@left = @left"; +say "\t\@right = @right"; +say "\t\@diff = @diff"; +sub left { + my @ints = @_; + pop @ints; + my @R = (0); + foreach (@ints) { + push @R, $R[-1] + $_; + } + return @R; +} +sub right { + my @ints = @_; + shift @ints; + my @R = (0); + foreach (reverse @ints) { + unshift @R, $R[0] + $_; + } + return @R; +} -- cgit From df8e942514dd66e8eab4d1a4946140b58a57f996 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Mon, 10 Jul 2023 18:37:40 +0200 Subject: feat(challenge-225/lubos-kolouch/perl,python/): Challenge 225 LK Perl Python --- challenge-225/lubos-kolouch/perl/ch-1.pl | 24 ++++++++++++++++++++++++ challenge-225/lubos-kolouch/perl/ch-2.pl | 23 +++++++++++++++++++++++ challenge-225/lubos-kolouch/python/ch-1.py | 16 ++++++++++++++++ challenge-225/lubos-kolouch/python/ch-2.py | 19 +++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 challenge-225/lubos-kolouch/perl/ch-1.pl create mode 100644 challenge-225/lubos-kolouch/perl/ch-2.pl create mode 100644 challenge-225/lubos-kolouch/python/ch-1.py create mode 100644 challenge-225/lubos-kolouch/python/ch-2.py diff --git a/challenge-225/lubos-kolouch/perl/ch-1.pl b/challenge-225/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..99803d2ae3 --- /dev/null +++ b/challenge-225/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use strict; +use warnings; + +sub max_words { + my @list = @_; + my $max_count = 0; + + foreach my $sentence (@list) { + my $word_count = scalar( split( /\s+/, $sentence ) ); + $max_count = $word_count if $word_count > $max_count; + } + + return $max_count; +} + +# testing +my @list = ( + "Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference." +); + +print max_words(@list), "\n"; # should print 8 diff --git a/challenge-225/lubos-kolouch/perl/ch-2.pl b/challenge-225/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..6a8219b87f --- /dev/null +++ b/challenge-225/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +use List::Util qw(sum); + +sub left_right_sum_diff { + my @ints = @_; + my @left = map { $_ > 0 ? sum( @ints[ 0 .. $_ - 1 ] ) : 0 } ( 0 .. $#ints ); + my @right = map { $_ < $#ints ? sum( @ints[ $_ + 1 .. $#ints ] ) : 0 } + ( 0 .. $#ints ); + return [ map { abs( $left[$_] - $right[$_] ) } ( 0 .. $#ints ) ]; +} + +# testing +my @ints = ( 10, 4, 8, 3 ); +print join( ", ", @{ left_right_sum_diff(@ints) } ), + "\n"; # should print "15, 1, 11, 22" + +@ints = (1); +print join( ", ", @{ left_right_sum_diff(@ints) } ), "\n"; # should print "0" + +@ints = ( 1, 2, 3, 4, 5 ); +print join( ", ", @{ left_right_sum_diff(@ints) } ), + "\n"; # should print "14, 11, 6, 1, 10" diff --git a/challenge-225/lubos-kolouch/python/ch-1.py b/challenge-225/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..6826ff1a30 --- /dev/null +++ b/challenge-225/lubos-kolouch/python/ch-1.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +def max_words(lst): + return max(len(sentence.split()) for sentence in lst) + + +# testing +list = [ + "Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference.", +] + +print(max_words(list)) # should print 8 diff --git a/challenge-225/lubos-kolouch/python/ch-2.py b/challenge-225/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..18ed09f29b --- /dev/null +++ b/challenge-225/lubos-kolouch/python/ch-2.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +def left_right_sum_diff(ints): + left = [sum(ints[:i]) for i in range(len(ints))] + right = [sum(ints[i + 1 :]) for i in range(len(ints))] + return [abs(l - r) for l, r in zip(left, right)] + + +# testing +ints = [10, 4, 8, 3] +print(left_right_sum_diff(ints)) # should print [15, 1, 11, 22] + +ints = [1] +print(left_right_sum_diff(ints)) # should print [0] + +ints = [1, 2, 3, 4, 5] +print(left_right_sum_diff(ints)) # should print [14, 11, 6, 1, 10] -- cgit From d0829f697ac3fa9a5791db99ff1686b1acecc4c9 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Mon, 10 Jul 2023 18:50:43 +0200 Subject: feat(challenge-165/lubos-kolouch/perl,python/): Challenge 165 LK Perl Python --- challenge-165/lubos-kolouch/perl/ch-1.pl | 42 ++++++++++++++++++++ challenge-165/lubos-kolouch/perl/ch-2.pl | 63 ++++++++++++++++++++++++++++++ challenge-165/lubos-kolouch/python/ch-1.py | 39 ++++++++++++++++++ challenge-165/lubos-kolouch/python/ch-2.py | 61 +++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+) create mode 100644 challenge-165/lubos-kolouch/perl/ch-1.pl create mode 100644 challenge-165/lubos-kolouch/perl/ch-2.pl create mode 100644 challenge-165/lubos-kolouch/python/ch-1.py create mode 100644 challenge-165/lubos-kolouch/python/ch-2.py diff --git a/challenge-165/lubos-kolouch/perl/ch-1.pl b/challenge-165/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..e4435d5723 --- /dev/null +++ b/challenge-165/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,42 @@ +use strict; +use warnings; +use XML::Writer; +use IO::File; + +my $output = IO::File->new(">output.svg"); +my $writer = XML::Writer->new( OUTPUT => $output ); + +$writer->startTag( + "svg", + 'xmlns' => "http://www.w3.org/2000/svg", + 'version' => "1.1" +); + +my @points = ( [ 53, 10 ], [ 23, 30 ] ); +my @lines = ( [ 53, 10, 23, 30 ] ); + +foreach my $point (@points) { + $writer->emptyTag( + "circle", + 'cx' => $point->[0], + 'cy' => $point->[1], + 'r' => "1", + 'stroke' => "black", + 'fill' => "black" + ); +} + +foreach my $line (@lines) { + $writer->emptyTag( + "line", + 'x1' => $line->[0], + 'y1' => $line->[1], + 'x2' => $line->[2], + 'y2' => $line->[3], + 'stroke' => "black" + ); +} + +$writer->endTag("svg"); +$writer->end(); +$output->close(); diff --git a/challenge-165/lubos-kolouch/perl/ch-2.pl b/challenge-165/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..da4d09cc65 --- /dev/null +++ b/challenge-165/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,63 @@ +use strict; +use warnings; +use Statistics::LineFit; + +my @points = ( + [ 333, 129 ], + [ 39, 189 ], + [ 140, 156 ], + [ 292, 134 ], + [ 393, 52 ], + [ 160, 166 ], + [ 362, 122 ], + [ 13, 193 ], + [ 341, 104 ], + [ 320, 113 ], + [ 109, 177 ], + [ 203, 152 ], + [ 343, 100 ], + [ 225, 110 ], + [ 23, 186 ], + [ 282, 102 ], + [ 284, 98 ], + [ 205, 133 ], + [ 297, 114 ], + [ 292, 126 ], + [ 339, 112 ], + [ 327, 79 ], + [ 253, 136 ], + [ 61, 169 ], + [ 128, 176 ], + [ 346, 72 ], + [ 316, 103 ], + [ 124, 162 ], + [ 65, 181 ], + [ 159, 137 ], + [ 212, 116 ], + [ 337, 86 ], + [ 215, 136 ], + [ 153, 137 ], + [ 390, 104 ], + [ 100, 180 ], + [ 76, 188 ], + [ 77, 181 ], + [ 69, 195 ], + [ 92, 186 ], + [ 275, 96 ], + [ 250, 147 ], + [ 34, 174 ], + [ 213, 134 ], + [ 186, 129 ], + [ 189, 154 ], + [ 361, 82 ], + [ 363, 89 ] +); + +my ( $x, $y ) = map { + [ map { $_->[$_] } @points ] +} 0, 1; +my $lineFit = Statistics::LineFit->new(); +$lineFit->setData( $x, $y ) or die "Invalid data"; +my ( $intercept, $slope ) = $lineFit->coefficients(); + +print "Line of Best Fit: y = $slope * x + $intercept\n"; diff --git a/challenge-165/lubos-kolouch/python/ch-1.py b/challenge-165/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..158b541b3b --- /dev/null +++ b/challenge-165/lubos-kolouch/python/ch-1.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import xml.etree.ElementTree as ET + + +def generate_svg(points, lines): + svg = ET.Element("svg", xmlns="http://www.w3.org/2000/svg", version="1.1") + + for point in points: + circle = ET.SubElement( + svg, + "circle", + cx=str(point[0]), + cy=str(point[1]), + r="1", + stroke="black", + fill="black", + ) + + for line in lines: + line = ET.SubElement( + svg, + "line", + x1=str(line[0]), + y1=str(line[1]), + x2=str(line[2]), + y2=str(line[3]), + stroke="black", + ) + + tree = ET.ElementTree(svg) + tree.write("output.svg") + + +# testing +points = [(53, 10), (23, 30)] +lines = [(53, 10, 23, 30)] +generate_svg(points, lines) diff --git a/challenge-165/lubos-kolouch/python/ch-2.py b/challenge-165/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..7f82af7731 --- /dev/null +++ b/challenge-165/lubos-kolouch/python/ch-2.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import numpy as np + +points = [ + (333, 129), + (39, 189), + (140, 156), + (292, 134), + (393, 52), + (160, 166), + (362, 122), + (13, 193), + (341, 104), + (320, 113), + (109, 177), + (203, 152), + (343, 100), + (225, 110), + (23, 186), + (282, 102), + (284, 98), + (205, 133), + (297, 114), + (292, 126), + (339, 112), + (327, 79), + (253, 136), + (61, 169), + (128, 176), + (346, 72), + (316, 103), + (124, 162), + (65, 181), + (159, 137), + (212, 116), + (337, 86), + (215, 136), + (153, 137), + (390, 104), + (100, 180), + (76, 188), + (77, 181), + (69, 195), + (92, 186), + (275, 96), + (250, 147), + (34, 174), + (213, 134), + (186, 129), + (189, 154), + (361, 82), + (363, 89), +] + +x, y = zip(*points) +A = np.vstack([x, np.ones(len(x))]).T +m, c = np.linalg.lstsq(A, y, rcond=None)[0] + +print(f"Line of Best Fit: y = {m}x + {c}") -- cgit From a5f6057bc0293d12abb6ad6864a72196fa417d6e Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Mon, 10 Jul 2023 18:56:53 +0200 Subject: feat(challenge-166/lubos-kolouch/perl,python/): Challenge 166 LK Perl Python --- challenge-166/lubos-kolouch/perl/ch-1.pl | 37 ++++++++++++++++++++++++++++++ challenge-166/lubos-kolouch/perl/ch-2.pl | 20 ++++++++++++++++ challenge-166/lubos-kolouch/python/ch-1.py | 27 ++++++++++++++++++++++ challenge-166/lubos-kolouch/python/ch-2.py | 29 +++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 challenge-166/lubos-kolouch/perl/ch-1.pl create mode 100644 challenge-166/lubos-kolouch/perl/ch-2.pl create mode 100644 challenge-166/lubos-kolouch/python/ch-1.py create mode 100644 challenge-166/lubos-kolouch/python/ch-2.py diff --git a/challenge-166/lubos-kolouch/perl/ch-1.pl b/challenge-166/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..4e526699d0 --- /dev/null +++ b/challenge-166/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,37 @@ +use strict; +use warnings; + +sub hex_words { + my ($dictionary_path) = @_; + my %hex_map = + ( "o" => "0", "l" => "1", "i" => "1", "s" => "5", "t" => "7" ); + my $valid_chars = "abcdef" . join( "", values %hex_map ); + my @words; + + open my $fh, '<', $dictionary_path or die $!; + while ( my $line = <$fh> ) { + chomp $line; + $line = lc $line; + if ( 2 <= length($line) + && length($line) <= 8 + && $line =~ m/^[${valid_chars}]+$/ ) + { + $line =~ s/(.)/exists($hex_map{$1}) ? $hex_map{$1} : $1/eg; + push @words, "0x$line"; + } + } + close $fh; + + return @words; +} + +# path to dictionary file +my $dictionary_path = "../../../data/dictionary.txt"; + +# get hex words +my @hex_words = hex_words($dictionary_path); + +# print hex words +for my $word (@hex_words) { + print "$word\n"; +} diff --git a/challenge-166/lubos-kolouch/perl/ch-2.pl b/challenge-166/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..fe9d266b86 --- /dev/null +++ b/challenge-166/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +use File::Slurp; + +my @dirs = ( 'dir_a', 'dir_b', 'dir_c' ); +my %all_files; + +foreach my $dir (@dirs) { + my @files = read_dir($dir); + foreach my $file (@files) { + push @{ $all_files{$file} }, $dir; + } +} + +foreach my $file ( keys %all_files ) { + if ( scalar @{ $all_files{$file} } != scalar @dirs ) { + print "$file is missing in ", + join( ", ", grep { not $_ ~~ @{ $all_files{$file} } } @dirs ), "\n"; + } +} diff --git a/challenge-166/lubos-kolouch/python/ch-1.py b/challenge-166/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..fef9376358 --- /dev/null +++ b/challenge-166/lubos-kolouch/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +def hex_words(dictionary_path): + hex_map = {"o": "0", "l": "1", "i": "1", "s": "5", "t": "7"} + valid_chars = set("abcdef" + "".join(hex_map.values())) + words = [] + + with open(dictionary_path, "r") as f: + for line in f: + word = line.strip().lower() + if 2 <= len(word) <= 8 and set(word).issubset(valid_chars): + words.append("0x" + "".join(hex_map.get(c, c) for c in word)) + + return words + + +# path to dictionary file +dictionary_path = "../../../data/dictionary.txt" + +# get hex words +hex_words = hex_words(dictionary_path) + +# print hex words +for word in hex_words: + print(word) diff --git a/challenge-166/lubos-kolouch/python/ch-2.py b/challenge-166/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..48996dd42e --- /dev/null +++ b/challenge-166/lubos-kolouch/python/ch-2.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os + + +def k_directory_diff(dirs): + all_files = set() + dir_files = {} + + for directory in dirs: + files = set(os.listdir(directory)) + all_files |= files + dir_files[directory] = files + + missing_files = {f: [] for f in all_files} + + for directory, files in dir_files.items(): + for file in all_files: + if file not in files: + missing_files[file].append(directory) + + for file, directories in missing_files.items(): + if directories: + print(file, "is missing in", ", ".join(directories)) + + +dirs = ["dir_a", "dir_b", "dir_c"] +k_directory_diff(dirs) -- cgit From 915f4dbe1a96292fe827655daf19ab8a47a5a607 Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Mon, 10 Jul 2023 19:17:40 -0400 Subject: DAJ #225 --- challenge-225/dave-jacoby/perl/ch-1.pl | 37 ++++++++++++++++++++++++++++++++++ challenge-225/dave-jacoby/perl/ch-2.pl | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 challenge-225/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-225/dave-jacoby/perl/ch-2.pl diff --git a/challenge-225/dave-jacoby/perl/ch-1.pl b/challenge-225/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..4f23081193 --- /dev/null +++ b/challenge-225/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +my @examples = ( + [ + "Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference." + ], + [ + "The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members." + ] +); + +for my $example (@examples) { + my $max = max_words( $example->@* ); + my $input = join ",\n\t\t", map { qq{"$_"} } $example->@*; + say <<~"END"; + Input: \@list = ($input) + Output: $max + END +} + +sub max_words ( @list ) { + my $max = 0; + for my $sentence (@list) { + my @sentence = split /\ /, $sentence; + my $length = scalar @sentence; + $max = $length > $max ? $length : $max; + } + return $max; +} diff --git a/challenge-225/dave-jacoby/perl/ch-2.pl b/challenge-225/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..adf1965b83 --- /dev/null +++ b/challenge-225/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +use List::Util qw{ sum }; + +my @examples = ( [ 10, 4, 8, 3 ], [1], [ 1, 2, 3, 4, 5 ], ); + +for my $e (@examples) { + my @example = $e->@*; + my @output = left_right_sum_diff(@example); + my $output = join ', ', @output; + my $input = join ', ', $e->@*; + say <<~"END"; + Input: \@ints = ($input) + Output: ($output) + END +} + +sub left_right_sum_diff( @ints ) { + my @left_ints = ( 0, @ints ); + my @right_ints = ( @ints, 0 ); + my @out; + + my $top = -1 + scalar @left_ints; + for my $i ( 0 .. -1 + scalar @ints ) { + my $k = 1 + $i; + my $left = sum( @left_ints[ 0 .. $i ] ); + my $right = sum( map { $right_ints[$_] } $k .. $top ); + push @out, abs( $left - $right ); + } + return @out; +} -- cgit From e7cbcbef554ad48ae88b8921dda46f0c16a148db Mon Sep 17 00:00:00 2001 From: Thomas Köhler Date: Tue, 11 Jul 2023 09:33:54 +0200 Subject: Add solution 225 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Köhler --- challenge-225/jeanluc2020/blog-1.txt | 1 + challenge-225/jeanluc2020/blog-2.txt | 1 + challenge-225/jeanluc2020/perl/ch-1.pl | 54 ++++++++++++++++++++ challenge-225/jeanluc2020/perl/ch-2.pl | 93 ++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 challenge-225/jeanluc2020/blog-1.txt create mode 100644 challenge-225/jeanluc2020/blog-2.txt create mode 100755 challenge-225/jeanluc2020/perl/ch-1.pl create mode 100755 challenge-225/jeanluc2020/perl/ch-2.pl diff --git a/challenge-225/jeanluc2020/blog-1.txt b/challenge-225/jeanluc2020/blog-1.txt new file mode 100644 index 0000000000..a5f935d5e7 --- /dev/null +++ b/challenge-225/jeanluc2020/blog-1.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-225-1.html diff --git a/challenge-225/jeanluc2020/blog-2.txt b/challenge-225/jeanluc2020/blog-2.txt new file mode 100644 index 0000000000..fb76c73620 --- /dev/null +++ b/challenge-225/jeanluc2020/blog-2.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-225-2.html diff --git a/challenge-225/jeanluc2020/perl/ch-1.pl b/challenge-225/jeanluc2020/perl/ch-1.pl new file mode 100755 index 0000000000..6b26da959b --- /dev/null +++ b/challenge-225/jeanluc2020/perl/ch-1.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-225/#TASK1 +# +# Task 1: Max Words +# ================= +# +# You are given a list of sentences, @list. +# +## A sentence is a list of words that are separated by a single space with no leading or trailing spaces. +# +# +# Write a script to find out the maximum number of words that appear in a single sentence. +# +## Example 1 +## +## Input: @list = ("Perl and Raku belong to the same family.", +## "I love Perl.", +## "The Perl and Raku Conference.") +## Output: 8 +# +## Example 2 +## +## Input: @list = ("The Weekly Challenge.", +## "Python is the most popular guest language.", +## "Team PWC has over 300 members.") +## Output: 7 +# +############################################################ +## +## discussion +## +############################################################ +# +# Split all sentences into their single words and count. Keep +# the maximum. + +use strict; +use warnings; + +max_words("Perl and Raku belong to the same family.", "I love Perl.", "The Perl and Raku Conference."); +max_words("The Weekly Challenge.", "Python is the most popular guest language.", "Team PWC has over 300 members."); + +sub max_words { + my @list = @_; + print "Input: \@list = (\"" . join("\",\n \"",@list) . "\")\n"; + my $max = 0; + foreach my $sentence (@list) { + my @words = split / /, $sentence; + my $count = scalar(@words); + $max = $count if $count > $max; + } + print "Output: $max\n"; +} + diff --git a/challenge-225/jeanluc2020/perl/ch-2.pl b/challenge-225/jeanluc2020/perl/ch-2.pl new file mode 100755 index 0000000000..ce01c087cc --- /dev/null +++ b/challenge-225/jeanluc2020/perl/ch-2.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-225/#TASK2 +# +# Task 2: Left Right Sum Diff +# Submitted by: Mohammad S Anwar +# +# You are given an array of integers, @ints. +# +# Write a script to return left right sum diff array as shown below: +# +# @ints = (a, b, c, d, e) +# +# @left = (0, a, (a+b), (a+b+c)) +# @right = ((c+d+e), (d+e), e, 0) +# @left_right_sum_diff = ( | 0 - (c+d+e) |, +# | a - (d+e) |, +# | (a+b) - e |, +# | (a+b+c) - 0 | ) +# +## +## WARNING: this explaination isn't entirely correct. As per +## https://leetcode.com/problems/left-and-right-sum-differences/ +## it would make more sense to have an additional element +## (a+b+c+d) at the end of @left and ((b+c+d+e) at the beginning +## of @right, which also the examples demonstrate: +## +# +## Example 1: +## +## Input: @ints = (10, 4, 8, 3) +## Output: (15, 1, 11, 22) +## +## @left = (0, 10, 14, 22) +## @right = (15, 11, 3, 0) +## +## @left_right_sum_diff = ( |0-15|, |10-11|, |14-3|, |22-0|) +## = (15, 1, 11, 22) +# +## Example 2: +## +## Input: @ints = (1) +## Output: (0) +## +## @left = (0) +## @right = (0) +## +## @left_right_sum_diff = ( |0-0| ) = (0) +# +## Example 3: +## +## Input: @ints = (1, 2, 3, 4, 5) +## Output: (14, 11, 6, 1, 19) +## +## @left = (0, 1, 3, 6, 10) +## @right = (14, 12, 9, 5, 0) +## +## @left_right_sum_diff = ( |0-14|, |1-12|, |3-9|, |6-5|, |10-0|) +## = (14, 11, 6, 1, 10) +# +############################################################ +## +## discussion +## +############################################################ +# +# First, calculate @left and @right, then calculate the +# @left_right_sum_diff + +use strict; +use warnings; + +left_right_sum_diff(10, 4, 8, 3); +left_right_sum_diff(1); +left_right_sum_diff(1, 2, 3, 4, 5); + +sub left_right_sum_diff { + my @ints = @_; + print "Input: (" . join(", ", @ints) . ")\n"; + my ($current_left, $current_right) = (0, 0); + my @left = (); + my @right = (); + foreach my $index (0..$#ints) { + push @left, $current_left; + $current_left += $ints[$index]; + unshift @right, $current_right; + $current_right += $ints[ $#ints - $index ]; + } + my @left_right_sum_diff = (); + foreach my $index (0..$#ints) { + $left_right_sum_diff[$index] = abs($left[$index] - $right[$index]); + } + print "Output: (" . join(", ", @left_right_sum_diff) . ")\n"; +} -- cgit From 2b586bbcfa9f30c6f6548aaadddd665b2d80198f Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 11 Jul 2023 09:52:16 +0100 Subject: - Added solutions by Robert DiCicco. - Added solutions by Laurent Rosenfeld. - Added solutions by Ulrich Rieke. - Added solutions by Jaldhar H. Vyas. - Added solutions by W. Luis Mochan. - Added solutions by Robbie Hatley. - Added solutions by Mark Anderson. - Added solutions by David Ferrone. - Added solutions by Andreas Voegele. - Added solutions by Lubos Kolouch. - Added solutions by Thomas Kohler. --- challenge-225/eric-cheung/python/ch-1.py | 8 + challenge-225/eric-cheung/python/ch-2.py | 19 + challenge-225/laurent-rosenfeld/blog.txt | 1 + challenge-225/laurent-rosenfeld/perl/ch-1.pl | 25 + challenge-225/laurent-rosenfeld/raku/ch-1.raku | 21 + challenge-225/robert-dicicco/julia/ch-1.jl | 51 + challenge-225/robert-dicicco/perl/ch-1.pl | 55 + challenge-225/robert-dicicco/python/ch-1.py | 39 + challenge-225/robert-dicicco/raku/ch-1.raku | 47 + challenge-225/robert-dicicco/ruby/ch-1.rb | 44 + challenge-225/ulrich-rieke/cpp/ch-1.cpp | 42 + challenge-225/ulrich-rieke/cpp/ch-2.cpp | 78 + challenge-225/ulrich-rieke/haskell/ch-1.hs | 32 + challenge-225/ulrich-rieke/haskell/ch-2.hs | 33 + challenge-225/ulrich-rieke/perl/ch-1.pl | 27 + challenge-225/ulrich-rieke/perl/ch-2.pl | 60 + challenge-225/ulrich-rieke/raku/ch-1.raku | 15 + challenge-225/ulrich-rieke/raku/ch-2.raku | 56 + challenge-225/ulrich-rieke/rust/ch-1.rs | 26 + challenge-225/ulrich-rieke/rust/ch-2.rs | 58 + stats/pwc-challenge-165.json | 413 ++-- stats/pwc-challenge-166.json | 447 ++-- stats/pwc-challenge-224.json | 518 ++++ stats/pwc-current.json | 379 +-- stats/pwc-language-breakdown-summary.json | 54 +- stats/pwc-language-breakdown.json | 2989 ++++++++++++------------ stats/pwc-leaders.json | 764 +++--- stats/pwc-summary-1-30.json | 110 +- stats/pwc-summary-121-150.json | 128 +- stats/pwc-summary-151-180.json | 40 +- stats/pwc-summary-181-210.json | 34 +- stats/pwc-summary-211-240.json | 34 +- stats/pwc-summary-241-270.json | 34 +- stats/pwc-summary-271-300.json | 24 +- stats/pwc-summary-31-60.json | 116 +- stats/pwc-summary-61-90.json | 116 +- stats/pwc-summary-91-120.json | 124 +- stats/pwc-summary.json | 682 +++--- 38 files changed, 4391 insertions(+), 3352 deletions(-) create mode 100755 challenge-225/eric-cheung/python/ch-1.py create mode 100755 challenge-225/eric-cheung/python/ch-2.py create mode 100644 challenge-225/laurent-rosenfeld/blog.txt create mode 100644 challenge-225/laurent-rosenfeld/perl/ch-1.pl create mode 100644 challenge-225/laurent-rosenfeld/raku/ch-1.raku create mode 100644 challenge-225/robert-dicicco/julia/ch-1.jl create mode 100644 challenge-225/robert-dicicco/perl/ch-1.pl create mode 100644 challenge-225/robert-dicicco/python/ch-1.py create mode 100644 challenge-225/robert-dicicco/raku/ch-1.raku create mode 100644 challenge-225/robert-dicicco/ruby/ch-1.rb create mode 100644 challenge-225/ulrich-rieke/cpp/ch-1.cpp create mode 100644 challenge-225/ulrich-rieke/cpp/ch-2.cpp create mode 100644 challenge-225/ulrich-rieke/haskell/ch-1.hs create mode 100644 challenge-225/ulrich-rieke/haskell/ch-2.hs create mode 100644 challenge-225/ulrich-rieke/perl/ch-1.pl create mode 100644 challenge-225/ulrich-rieke/perl/ch-2.pl create mode 100644 challenge-225/ulrich-rieke/raku/ch-1.raku create mode 100644 challenge-225/ulrich-rieke/raku/ch-2.raku create mode 100644 challenge-225/ulrich-rieke/rust/ch-1.rs create mode 100644 challenge-225/ulrich-rieke/rust/ch-2.rs create mode 100644 stats/pwc-challenge-224.json diff --git a/challenge-225/eric-cheung/python/ch-1.py b/challenge-225/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..f0095f08e1 --- /dev/null +++ b/challenge-225/eric-cheung/python/ch-1.py @@ -0,0 +1,8 @@ + +## arrWordList = ["Perl and Raku belong to the same family.", "I love Perl.", "The Perl and Raku Conference."] ## Example 1 +arrWordList = ["The Weekly Challenge.", "Python is the most popular guest language.", "Team PWC has over 300 members."] ## Example 2 + +arrWordLen = [len(wordLoop.split()) for wordLoop in arrWordList] +nMaxWordLen = max(arrWordLen) + +print (nMaxWordLen) diff --git a/challenge-225/eric-cheung/python/ch-2.py b/challenge-225/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..64e98389f4 --- /dev/null +++ b/challenge-225/eric-cheung/python/ch-2.py @@ -0,0 +1,19 @@ + +## arrInt = [10, 4, 8, 3] ## Example 1 +## arrInt = [1] ## Example 2 +arrInt = [1, 2, 3, 4, 5] ## Example 3 + +arrLeft = [0] +arrRight = [0] + +for nIndx in range(len(arrInt) - 1): + arrLeft.append(arrLeft[-1] + arrInt[nIndx]) + arrRight.append(arrRight[-1] + arrInt[len(arrInt) - nIndx - 1]) + +arrRight.reverse() + +arrLeftRightSumDiff = [abs(arrLeft[nIndx] - arrRight[nIndx]) for nIndx in range(len(arrLeft))] + +## print (arrLeft) +## print (arrRight) +print (arrLeftRightSumDiff) diff --git a/challenge-225/laurent-rosenfeld/blog.txt b/challenge-225/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..81e5655f24 --- /dev/null +++ b/challenge-225/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/07/perl-weekly-challenge-225-max-words.html diff --git a/challenge-225/laurent-rosenfeld/perl/ch-1.pl b/challenge-225/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..fa083ef410 --- /dev/null +++ b/challenge-225/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,25 @@ +use strict; +use warnings; +use feature 'say'; + +sub max_words { + my $max = 0; + for my $sentence (@_) { + my $cw = scalar split /\s+/, $sentence; + $max = $cw if $cw > $max; + } + return $max; +} + +my @tests = ( + ["The quick brown fox jumps over the lazy dog", + "Lorem ipsum dolor sit amet"], + ["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]); +for my $test (@tests) { + say max_words @$test; +} diff --git a/challenge-225/laurent-rosenfeld/raku/ch-1.raku b/challenge-225/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..fa6cf6a104 --- /dev/null +++ b/challenge-225/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,21 @@ +sub max-words (@sentences) { + my $max = 0; + for @sentences -> $sentence { + my $cw = $sentence.words.elems; + $max = $cw if $cw > $max; + } + return $max; +} + +my @tests = + ("The quick brown fox jumps over the lazy dog", + "Lorem ipsum dolor sit amet"), + ("Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."), + ("The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."); +for @tests -> @test { + say max-words @test; +} diff --git a/challenge-225/robert-dicicco/julia/ch-1.jl b/challenge-225/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..806b68291f --- /dev/null +++ b/challenge-225/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,51 @@ +#!/usr/bin/env julia +#= +----------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-07-10 +Challenge 225 Task 1 Max Words ( Julia ) +----------------------------------- +=# + +using Printf + +lists = [["Perl and Raku belong to the same family.", + "I love Perl.", + "The Perl and Raku Conference."], + ["The Weekly Challenge.", + "Python is the most popular guest language.", + "Team PWC has over 300 members."]] + +max_num = 0 + +for lst in lists + global max_num + @printf("Input: @list = %s\n",lst) + cnt = 1 + sz = length(lst) + while cnt < sz + words = split(lst[cnt]) + ln = length(words) + if ln > max_num +