From faaf5da6ddf7066c65990dc6d78cf2a0405473c7 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 23 Oct 2023 06:06:12 +0000 Subject: Challenge 240 (Perl and Raku) --- challenge-240/mark-anderson/perl/ch-1.pl | 14 ++++++++++++++ challenge-240/mark-anderson/perl/ch-2.pl | 9 +++++++++ challenge-240/mark-anderson/raku/ch-1.raku | 11 +++++++++++ challenge-240/mark-anderson/raku/ch-2.raku | 7 +++++++ 4 files changed, 41 insertions(+) create mode 100644 challenge-240/mark-anderson/perl/ch-1.pl create mode 100644 challenge-240/mark-anderson/perl/ch-2.pl create mode 100644 challenge-240/mark-anderson/raku/ch-1.raku create mode 100644 challenge-240/mark-anderson/raku/ch-2.raku diff --git a/challenge-240/mark-anderson/perl/ch-1.pl b/challenge-240/mark-anderson/perl/ch-1.pl new file mode 100644 index 0000000000..9abad2e64e --- /dev/null +++ b/challenge-240/mark-anderson/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl +use List::Util qw/all zip/; +use experimental qw/signatures/; +use Test2::V0; +plan 3; + +ok acronym([qw/Perl Python Pascal/], 'ppp'); +ok not acronym([qw/Perl Raku/], 'rp'); +ok acronym([qw/Oracle Awk C/], 'oac'); + +sub acronym($arr, $ck) +{ + all { uc $_->[1] eq substr $_->[0], 0, 1 } zip $arr, [split //, $ck] +} diff --git a/challenge-240/mark-anderson/perl/ch-2.pl b/challenge-240/mark-anderson/perl/ch-2.pl new file mode 100644 index 0000000000..604c5ea8ba --- /dev/null +++ b/challenge-240/mark-anderson/perl/ch-2.pl @@ -0,0 +1,9 @@ +#!/usr/bin/env perl +use experimental qw/signatures/; +use Test2::V0; +plan 2; + +is build_array([0,2,1,5,3,4]), [0,1,2,4,5,3]; +is build_array([5,0,1,2,3,4]), [4,5,0,1,2,3]; + +sub build_array($arr) { [ @$arr[@$arr] ] } diff --git a/challenge-240/mark-anderson/raku/ch-1.raku b/challenge-240/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..10e7e3f8c7 --- /dev/null +++ b/challenge-240/mark-anderson/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku +use Test; + +ok acronym(, 'ppp'); +nok acronym(, 'rp'); +ok acronym(, 'oac'); + +sub acronym(@a, $ck) +{ + so all map { .[0].starts-with(.[1].uc) }, (@a Z $ck.comb) +} diff --git a/challenge-240/mark-anderson/raku/ch-2.raku b/challenge-240/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..f29aa6dd17 --- /dev/null +++ b/challenge-240/mark-anderson/raku/ch-2.raku @@ -0,0 +1,7 @@ +#!/usr/bin/env raku +use Test; + +is-deeply build-array(<0 2 1 5 3 4>), <0 1 2 4 5 3>; +is-deeply build-array(<5 0 1 2 3 4>), <4 5 0 1 2 3>; + +sub build-array(@a) { @a[@a] } -- cgit From 5cf3df190eb2f2d740cb0941c20fc002e679f2a1 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 23 Oct 2023 07:19:33 +0000 Subject: w240 - Task 1 & 2 --- challenge-240/perlboy1967/perl/ch1.pl | 34 ++++++++++++++++++++++++++++++++++ challenge-240/perlboy1967/perl/ch2.pl | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 challenge-240/perlboy1967/perl/ch1.pl create mode 100755 challenge-240/perlboy1967/perl/ch2.pl diff --git a/challenge-240/perlboy1967/perl/ch1.pl b/challenge-240/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..6110e5f796 --- /dev/null +++ b/challenge-240/perlboy1967/perl/ch1.pl @@ -0,0 +1,34 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 240 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-240 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Acronym +Submitted by: Mohammad S Anwar + +You are given two arrays of strings and a check string. + +Write a script to find out if the check string is the acronym of the words +in the given array. + +=cut + +use v5.32; +use common::sense; +use feature 'signatures'; + +use Test2::V0; + +sub acronym ($string,@words) { + lc($string) eq join('',map {lc substr($_,0,1)} @words) ? 1 : 0; +} + +is(acronym('ppp','Perl','Python','Pascal'),1); +is(acronym('rp','Perl','Raku'),0); +is(acronym('oac','Oracle','Awk','C'),1); + +done_testing; diff --git a/challenge-240/perlboy1967/perl/ch2.pl b/challenge-240/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..076ee54424 --- /dev/null +++ b/challenge-240/perlboy1967/perl/ch2.pl @@ -0,0 +1,33 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 240 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-240 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Build Array +Submitted by: Mohammad S Anwar + +You are given an array of integers. + +Write a script to create an array such that +new[i] = old[old[i]] where 0 <= i < new.length. + +=cut + +use v5.32; +use common::sense; +use feature 'signatures'; + +use Test2::V0; + +sub buildArray (@int) { + [map { $int[$int[$_]] } (0 .. scalar(@_) - 1)]; +} + +is(buildArray(0,2,1,5,3,4),[0,1,2,4,5,3]); +is(buildArray(5,0,1,2,3,4),[4,5,0,1,2,3]); + +done_testing; -- cgit From e9a5b83f479fe855d1fecf211c71e2279e73220e Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 23 Oct 2023 07:29:25 +0000 Subject: Task 2 - Make use of variable as declared in signature --- challenge-240/perlboy1967/perl/ch2.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-240/perlboy1967/perl/ch2.pl b/challenge-240/perlboy1967/perl/ch2.pl index 076ee54424..89727b06df 100755 --- a/challenge-240/perlboy1967/perl/ch2.pl +++ b/challenge-240/perlboy1967/perl/ch2.pl @@ -24,7 +24,7 @@ use feature 'signatures'; use Test2::V0; sub buildArray (@int) { - [map { $int[$int[$_]] } (0 .. scalar(@_) - 1)]; + [map { $int[$int[$_]] } (0 .. scalar(@int) - 1)]; } is(buildArray(0,2,1,5,3,4),[0,1,2,4,5,3]); -- cgit From 4362180cf0db3936681e859449d44e550797c7f4 Mon Sep 17 00:00:00 2001 From: pme Date: Mon, 23 Oct 2023 10:28:59 +0200 Subject: challenge-240 --- challenge-240/peter-meszaros/perl/ch-1.pl | 56 +++++++++++++++++++++++++++++++ challenge-240/peter-meszaros/perl/ch-2.pl | 45 +++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100755 challenge-240/peter-meszaros/perl/ch-1.pl create mode 100755 challenge-240/peter-meszaros/perl/ch-2.pl diff --git a/challenge-240/peter-meszaros/perl/ch-1.pl b/challenge-240/peter-meszaros/perl/ch-1.pl new file mode 100755 index 0000000000..cf0264fe0d --- /dev/null +++ b/challenge-240/peter-meszaros/perl/ch-1.pl @@ -0,0 +1,56 @@ +#!/usr/bin/env perl +# +# You are given two arrays of strings and a check string. +# +# Write a script to find out if the check string is the acronym of the words in +# the given array. +# Example 1 +# +# Input: @str = ("Perl", "Python", "Pascal") +# $chk = "ppp" +# Output: true +# +# Example 2 +# +# Input: @str = ("Perl", "Raku") +# $chk = "rp" +# Output: false +# +# Example 3 +# +# Input: @str = ("Oracle", "Awk", "C") +# $chk = "oac" +# Output: true +# + +use strict; +use warnings; +use feature qw/fc/; +use Test::More; +use Data::Dumper; + +my $cases = [ + [["Perl", "Python", "Pascal"], "ppp"], + [["Perl", "Raku"], "rp"], + [["Oracle", "Awk", "C"], "oac"], +]; + +sub acronym +{ + my ($l, $chk) = @{$_[0]}; + + my @chk = split('', $chk); + for my $str (@$l) { + return 0 if fc(substr($str, 0, 1)) ne fc(shift @chk); + } + return 1; +} + +is(acronym($cases->[0]), 1, '[["Perl", "Python", "Pascal"], "ppp"]'); +is(acronym($cases->[1]), 0, '[["Perl", "Raku"], "rp"]'); +is(acronym($cases->[2]), 1, '[["Oracle", "Awk", "C"], "oac"]'); +done_testing(); + +exit 0; + + diff --git a/challenge-240/peter-meszaros/perl/ch-2.pl b/challenge-240/peter-meszaros/perl/ch-2.pl new file mode 100755 index 0000000000..d8f0d4b88d --- /dev/null +++ b/challenge-240/peter-meszaros/perl/ch-2.pl @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +# +# You are given an array of integers. +# +# Write a script to create an array such that new[i] = old[old[i]] where +# 0 <= i < new.length. +# +# Example 1 +# +# Input: @int = (0, 2, 1, 5, 3, 4) +# Output: (0, 1, 2, 4, 5, 3) +# +# Example 2 +# +# Input: @int = (5, 0, 1, 2, 3, 4) +# Output: (4, 5, 0, 1, 2, 3) +# + +use strict; +use warnings; +use Test::More; +use Data::Dumper; + +my $cases = [ + [0, 2, 1, 5, 3, 4], + [5, 0, 1, 2, 3, 4], +]; + +sub build_array +{ + my $old = shift; + + my @ret; + for (my $i=0; $i < @$old; ++$i) { + push @ret, $old->[$old->[$i]]; + } + + return \@ret; +} + +is_deeply(build_array($cases->[0]), [0, 1, 2, 4, 5, 3], '[0, 2, 1, 5, 3, 4]'); +is_deeply(build_array($cases->[1]), [4, 5, 0, 1, 2, 3], '[5, 0, 1, 2, 3, 4]'); +done_testing(); + +exit 0; -- cgit From 6faadf48fd6d3a75d13792b44281d869c3121350 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 23 Oct 2023 11:01:35 +0200 Subject: Add solutions to 240: Acronym & Build Array by E. Choroba --- challenge-240/e-choroba/perl/ch-1.pl | 14 ++++++++++++++ challenge-240/e-choroba/perl/ch-2.pl | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 challenge-240/e-choroba/perl/ch-1.pl create mode 100755 challenge-240/e-choroba/perl/ch-2.pl diff --git a/challenge-240/e-choroba/perl/ch-1.pl b/challenge-240/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..382939d4e7 --- /dev/null +++ b/challenge-240/e-choroba/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub acronym($chk, @str) { + $chk eq lc join "", map substr($_, 0, 1), @str +} + +use Test::More tests => 3; + +ok acronym("ppp", "Perl", "Python", "Pascal"), 'Example 1'; +ok ! acronym("rp", "Perl", "Raku"), 'Example 2'; +ok acronym("oac", "Oracle", "Awk", "C"), 'Example 3'; diff --git a/challenge-240/e-choroba/perl/ch-2.pl b/challenge-240/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..e2b270e773 --- /dev/null +++ b/challenge-240/e-choroba/perl/ch-2.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub build_array(@int) { [@int[@int]] } + +use Test2::V0; +plan 2; + +is build_array(0, 2, 1, 5, 3, 4), [0, 1, 2, 4, 5, 3], 'Example 1'; +is build_array(5, 0, 1, 2, 3, 4), [4, 5, 0, 1, 2, 3], 'Example 2'; -- cgit From 8aba261f4fe1a17e6bf2d66c015b4da72a02fd58 Mon Sep 17 00:00:00 2001 From: Michael Firkins Date: Mon, 23 Oct 2023 20:04:52 +1100 Subject: pwc240 solution in python --- challenge-240/pokgopun/python/ch-1.py | 50 +++++++++++++++++++++++++++++++++++ challenge-240/pokgopun/python/ch-2.py | 43 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 challenge-240/pokgopun/python/ch-1.py create mode 100644 challenge-240/pokgopun/python/ch-2.py diff --git a/challenge-240/pokgopun/python/ch-1.py b/challenge-240/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..ea9ff578d9 --- /dev/null +++ b/challenge-240/pokgopun/python/ch-1.py @@ -0,0 +1,50 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-240/ +""" + +Task 1: Acronym + +Submitted by: [52]Mohammad S Anwar + __________________________________________________________________ + + You are given two arrays of strings and a check string. + + Write a script to find out if the check string is the acronym of the + words in the given array. + +Example 1 + +Input: @str = ("Perl", "Python", "Pascal") + $chk = "ppp" +Output: true + +Example 2 + +Input: @str = ("Perl", "Raku") + $chk = "rp" +Output: false + +Example 3 + +Input: @str = ("Oracle", "Awk", "C") + $chk = "oac" +Output: true + +Task 2: Build Array +""" +### solution by pokgopun@gmail.com + +def isAbbrv(tup, abbrv): + return abbrv.lower()=="".join( + tuple( + map(lambda x: x[0], tup + ) + ) + ).lower() + +for (strings, abbrv), res in { + (("Perl", "Python", "Pascal"),"ppp"): True, + (("Perl", "Raku"), "rp"): False, + (("Oracle", "Awk", "C"),"oac"): True, + }.items(): + print(isAbbrv(strings, abbrv)==res) + diff --git a/challenge-240/pokgopun/python/ch-2.py b/challenge-240/pokgopun/python/ch-2.py new file mode 100644 index 0000000000..f49f73f9cc --- /dev/null +++ b/challenge-240/pokgopun/python/ch-2.py @@ -0,0 +1,43 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-240/ +""" + +Task 2: Build Array + +Submitted by: [53]Mohammad S Anwar + __________________________________________________________________ + + You are given an array of integers. + + Write a script to create an array such that new[i] = old[old[i]] where + 0 <= i < new.length. + +Example 1 + +Input: @int = (0, 2, 1, 5, 3, 4) +Output: (0, 1, 2, 4, 5, 3) + +Example 2 + +Input: @int = (5, 0, 1, 2, 3, 4) +Output: (4, 5, 0, 1, 2, 3) + __________________________________________________________________ + + Last date to submit the solution 23:59 (UK Time) Sunday 29th October + 2023. + __________________________________________________________________ + +SO WHAT DO YOU THINK ? +""" +### solution by pokgopun@gmail.com + +def iSort(tup): + return tuple( + map( lambda x: tup[x], tup ) + ) + + +for inpt,otpt in { + (0, 2, 1, 5, 3, 4): (0, 1, 2, 4, 5, 3), + (5, 0, 1, 2, 3, 4): (4, 5, 0, 1, 2, 3), + }.items(): + print(iSort(inpt)==otpt) -- cgit From f617f78f71cbb1f79fd56aed8596e63ff25941b7 Mon Sep 17 00:00:00 2001 From: Michael Firkins Date: Mon, 23 Oct 2023 20:34:49 +1100 Subject: pwc240 solution in go --- challenge-240/pokgopun/go/ch-1.go | 64 +++++++++++++++++++++++++++++++++++++++ challenge-240/pokgopun/go/ch-2.go | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 challenge-240/pokgopun/go/ch-1.go create mode 100644 challenge-240/pokgopun/go/ch-2.go diff --git a/challenge-240/pokgopun/go/ch-1.go b/challenge-240/pokgopun/go/ch-1.go new file mode 100644 index 0000000000..d9b36532fb --- /dev/null +++ b/challenge-240/pokgopun/go/ch-1.go @@ -0,0 +1,64 @@ +//# https://theweeklychallenge.org/blog/perl-weekly-challenge-240/ +/*# + +Task 1: Acronym + +Submitted by: [52]Mohammad S Anwar + __________________________________________________________________ + + You are given two arrays of strings and a check string. + + Write a script to find out if the check string is the acronym of the + words in the given array. + +Example 1 + +Input: @str = ("Perl", "Python", "Pascal") + $chk = "ppp" +Output: true + +Example 2 + +Input: @str = ("Perl", "Raku") + $chk = "rp" +Output: false + +Example 3 + +Input: @str = ("Oracle", "Awk", "C") + $chk = "oac" +Output: true + +Task 2: Build Array +#*/ +//# solution by pokgopun@gmail.com + +package main + +import "fmt" + +func main() { + for _, data := range []struct { + strings []string + abbrv string + res bool + }{ + {[]string{"Perl", "Python", "Pascal"}, "ppp", true}, + {[]string{"Perl", "Raku"}, "rp", false}, + {[]string{"Oracle", "Awk", "C"}, "oac", true}, + } { + fmt.Println(isAbbrv(data.strings, data.abbrv) == data.res) + } +} + +func isAbbrv(s []string, a string) bool { + if len(s) != len(a) { + return false + } + for i, v := range s { + if (v[0]-a[i])%32 != 0 { + return false + } + } + return true +} diff --git a/challenge-240/pokgopun/go/ch-2.go b/challenge-240/pokgopun/go/ch-2.go new file mode 100644 index 0000000000..c04b18d2ad --- /dev/null +++ b/challenge-240/pokgopun/go/ch-2.go @@ -0,0 +1,57 @@ +//# https://theweeklychallenge.org/blog/perl-weekly-challenge-240/ +/*# + +Task 2: Build Array + +Submitted by: [53]Mohammad S Anwar + __________________________________________________________________ + + You are given an array of integers. + + Write a script to create an array such that new[i] = old[old[i]] where + 0 <= i < new.length. + +Example 1 + +Input: @int = (0, 2, 1, 5, 3, 4) +Output: (0, 1, 2, 4, 5, 3) + +Example 2 + +Input: @int = (5, 0, 1, 2, 3, 4) +Output: (4, 5, 0, 1, 2, 3) + __________________________________________________________________ + + Last date to submit the solution 23:59 (UK Time) Sunday 29th October + 2023. + __________________________________________________________________ + +SO WHAT DO YOU THINK ? +#*/ +//# solution by pokgopun@gmail.com + +package main + +import ( + "fmt" + "slices" +) + +func main() { + for _, data := range []struct { + input, output []int + }{ + {[]int{0, 2, 1, 5, 3, 4}, []int{0, 1, 2, 4, 5, 3}}, + {[]int{5, 0, 1, 2, 3, 4}, []int{4, 5, 0, 1, 2, 3}}, + } { + fmt.Println(slices.Equal(iSort(data.input), data.output)) + } +} + +func iSort(s []int) []int { + r := make([]int, len(s)) + for i, v := range s { + r[i] = s[v] + } + return r +} -- cgit From 3f147d6e611147048d3ebae3cc10deef176f5c67 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Mon, 23 Oct 2023 13:12:50 +0200 Subject: feat(challenge-240/lubos-kolouch/perl,python,raku/): Challenge 240 LK Perl Python Raku Blog --- challenge-240/lubos-kolouch/blog.txt | 1 + challenge-240/lubos-kolouch/perl/ch-1.pl | 17 +++++++++++++++++ challenge-240/lubos-kolouch/perl/ch-2.pl | 19 +++++++++++++++++++ challenge-240/lubos-kolouch/python/ch-1.py | 17 +++++++++++++++++ challenge-240/lubos-kolouch/python/ch-2.py | 16 ++++++++++++++++ challenge-240/lubos-kolouch/raku/ch-1.raku | 12 ++++++++++++ challenge-240/lubos-kolouch/raku/ch-2.raku | 14 ++++++++++++++ 7 files changed, 96 insertions(+) create mode 100644 challenge-240/lubos-kolouch/blog.txt create mode 100644 challenge-240/lubos-kolouch/perl/ch-1.pl create mode 100644 challenge-240/lubos-kolouch/perl/ch-2.pl create mode 100644 challenge-240/lubos-kolouch/python/ch-1.py create mode 100644 challenge-240/lubos-kolouch/python/ch-2.py create mode 100644 challenge-240/lubos-kolouch/raku/ch-1.raku create mode 100644 challenge-240/lubos-kolouch/raku/ch-2.raku diff --git a/challenge-240/lubos-kolouch/blog.txt b/challenge-240/lubos-kolouch/blog.txt new file mode 100644 index 0000000000..be65cccbf2 --- /dev/null +++ b/challenge-240/lubos-kolouch/blog.txt @@ -0,0 +1 @@ +https://egroup.kolouch.org/nextcloud/sites/lubos/2023-10-23_Weekly_challenge_240 diff --git a/challenge-240/lubos-kolouch/perl/ch-1.pl b/challenge-240/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..443f29943b --- /dev/null +++ b/challenge-240/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,17 @@ +use strict; +use warnings; +use Test::More; + +sub is_acronym { + my ($chk, @words) = @_; + + my $acronym = join '', map { lc(substr($_, 0, 1)) } @words; + + return $acronym eq lc($chk); +} + +is(is_acronym("ppp", "Perl", "Python", "Pascal"), 1, 'Test Case 1'); +is(is_acronym("rp", "Perl", "Raku"), '', 'Test Case 2'); +is(is_acronym("oac", "Oracle", "Awk", "C"), 1, 'Test Case 3'); + +done_testing(); diff --git a/challenge-240/lubos-kolouch/perl/ch-2.pl b/challenge-240/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..1d64fca101 --- /dev/null +++ b/challenge-240/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +use Test::More; + +sub create_new_array { + my @old = @_; + my @new; + + for my $i (0..$#old) { + push @new, $old[$old[$i]]; + } + + return @new; +} + +is_deeply([create_new_array(0, 2, 1, 5, 3, 4)], [0, 1, 2, 4, 5, 3], 'Test Case 1'); +is_deeply([create_new_array(5, 0, 1, 2, 3, 4)], [4, 5, 0, 1, 2, 3], 'Test Case 2'); + +done_testing(); diff --git a/challenge-240/lubos-kolouch/python/ch-1.py b/challenge-240/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..37163ce8f4 --- /dev/null +++ b/challenge-240/lubos-kolouch/python/ch-1.py @@ -0,0 +1,17 @@ +import unittest + + +def is_acronym(chk: str, words: list[str]) -> bool: + acronym = "".join(word[0].lower() for word in words) + return acronym == chk.lower() + + +class TestIsAcronym(unittest.TestCase): + def test_cases(self): + self.assertEqual(is_acronym("ppp", ["Perl", "Python", "Pascal"]), True) + self.assertEqual(is_acronym("rp", ["Perl", "Raku"]), False) + self.assertEqual(is_acronym("oac", ["Oracle", "Awk", "C"]), True) + + +if __name__ == "__main__": + unittest.main() diff --git a/challenge-240/lubos-kolouch/python/ch-2.py b/challenge-240/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..3c26236e2c --- /dev/null +++ b/challenge-240/lubos-kolouch/python/ch-2.py @@ -0,0 +1,16 @@ +import unittest +from typing import List + + +def create_new_array(old: list[int]) -> list[int]: + return [old[old[i]] for i in range(len(old))] + + +class TestCreateNewArray(unittest.TestCase): + def test_cases(self): + self.assertEqual(create_new_array([0, 2, 1, 5, 3, 4]), [0, 1, 2, 4, 5, 3]) + self.assertEqual(create_new_array([5, 0, 1, 2, 3, 4]), [4, 5, 0, 1, 2, 3]) + + +if __name__ == "__main__": + unittest.main() diff --git a/challenge-240/lubos-kolouch/raku/ch-1.raku b/challenge-240/lubos-kolouch/raku/ch-1.raku new file mode 100644 index 0000000000..6343481fa2 --- /dev/null +++ b/challenge-240/lubos-kolouch/raku/ch-1.raku @@ -0,0 +1,12 @@ +use Test; + +sub is-acronym(Str $chk, @words) returns Bool { + my $acronym = @words.map({ .substr(0, 1).lc }).join(''); + return $acronym eq $chk.lc; +} + +plan 3; + +ok is-acronym("ppp", ["Perl", "Python", "Pascal"]), 'Test Case 1'; +ok !is-acronym("rp", ["Perl", "Raku"]), 'Test Case 2'; +ok is-acronym("oac", ["Oracle", "Awk", "C"]), 'Test Case 3'; diff --git a/challenge-240/lubos-kolouch/raku/ch-2.raku b/challenge-240/lubos-kolouch/raku/ch-2.raku new file mode 100644 index 0000000000..9f511b750a --- /dev/null +++ b/challenge-240/lubos-kolouch/raku/ch-2.raku @@ -0,0 +1,14 @@ +use Test; + +sub create-new-array(@old) { + my @new; + for 0..^@old.elems -> $i { + @new.push(@old[@old[$i]]); + } + return @new; +} + +plan 2; + +is-deeply create-new-array([0, 2, 1, 5, 3, 4]), [0, 1, 2, 4, 5, 3], 'Test Case 1'; +is-deeply create-new-array([5, 0, 1, 2, 3, 4]), [4, 5, 0, 1, 2, 3], 'Test Case 2'; -- cgit From 3e8a148928bacb42c496880a9e5d05e53840ba02 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 23 Oct 2023 16:14:59 +0100 Subject: add solutions week 240 in python --- challenge-240/steven-wilson/python/ch-01.py | 24 ++++++++++++++++++++++++ challenge-240/steven-wilson/python/ch-02.py | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 challenge-240/steven-wilson/python/ch-01.py create mode 100644 challenge-240/steven-wilson/python/ch-02.py diff --git a/challenge-240/steven-wilson/python/ch-01.py b/challenge-240/steven-wilson/python/ch-01.py new file mode 100644 index 0000000000..ffddcff201 --- /dev/null +++ b/challenge-240/steven-wilson/python/ch-01.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + + +def acronym(check, words): + ''' + Is the check string an acronym of the words in the given array + >>> acronym("ppp", ("Perl", "Python", "Pascal")) + True + >>> acronym("rp", ("Perl", "Raku")) + False + >>> acronym("oac", ("Oracle", "Awk", "C")) + True + ''' + acronym = "".join([word[0].lower() for word in words]) + if acronym == check: + return True + else: + return False + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/challenge-240/steven-wilson/python/ch-02.py b/challenge-240/steven-wilson/python/ch-02.py new file mode 100644 index 0000000000..a54d18efee --- /dev/null +++ b/challenge-240/steven-wilson/python/ch-02.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + + +def build_array(elements): + ''' + create an array such that new[i] = old[old[i]] where 0 <= i < new.length + >>> build_array([0, 2, 1, 5, 3, 4]) + [0, 1, 2, 4, 5, 3] + >>> build_array([5, 0, 1, 2, 3, 4]) + [4, 5, 0, 1, 2, 3] + ''' + new = [] + for i, value in enumerate(elements): + new.append(elements[elements[i]]) + return new + + +if __name__ == "__main__": + import doctest + + doctest.testmod() -- cgit From 1eeedc22524f01cc4d0a554b47641ba80d929251 Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Mon, 23 Oct 2023 11:34:22 -0400 Subject: Week 240 --- challenge-240/zapwai/perl/ch-1.pl | 9 +++++++++ challenge-240/zapwai/perl/ch-2.pl | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100644 challenge-240/zapwai/perl/ch-1.pl create mode 100644 challenge-240/zapwai/perl/ch-2.pl diff --git a/challenge-240/zapwai/perl/ch-1.pl b/challenge-240/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..2fae11f77f --- /dev/null +++ b/challenge-240/zapwai/perl/ch-1.pl @@ -0,0 +1,9 @@ +use v5.30; +my @str = ("Perl", "Python", "Pascal"); +my ($acr, $chk) = ("", "ppp"); +foreach my $word (@str) { + my @t = split "", $word; + $acr .= shift @t; +} +say "Input: \@str = @str \n\t\$chk = $chk"; +say "Output: ", ($chk eq lc $acr) ? "True" : "False"; diff --git a/challenge-240/zapwai/perl/ch-2.pl b/challenge-240/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..062f59ef2b --- /dev/null +++ b/challenge-240/zapwai/perl/ch-2.pl @@ -0,0 +1,6 @@ +use v5.30; +my @int = (0, 2, 1, 5, 3, 4); +my @new; +$new[$_] = $int[$int[$_]] for (0 .. $#int); +say "Input: \@int = (" . join(", ", @int) . ")"; +say "Output:\@new = (" . join(", ", @new) . ")"; -- cgit From e24784a826187f877141dc4b986d815c7d9874a5 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 23 Oct 2023 22:22:18 +0200 Subject: Task 1 Raku done Another Task1 implementation Task 2 implementation Task 1 PL/Perl Task 2 PL/Perl done. Task 1 PL/PgSQL done Task 1 PL/PgSQL done Task 1 Python done Task 2 Python done --- challenge-240/luca-ferrari/blog-1.txt | 1 + challenge-240/luca-ferrari/blog-2.txt | 1 + challenge-240/luca-ferrari/blog-3.txt | 1 + challenge-240/luca-ferrari/blog-4.txt | 1 + challenge-240/luca-ferrari/blog-5.txt | 1 + challenge-240/luca-ferrari/blog-6.txt | 1 + challenge-240/luca-ferrari/blog-7.txt | 1 + challenge-240/luca-ferrari/blog-8.txt | 1 + challenge-240/luca-ferrari/postgresql/ch-1.plperl | 25 ++++++++++++++++ challenge-240/luca-ferrari/postgresql/ch-1.sql | 35 +++++++++++++++++++++++ challenge-240/luca-ferrari/postgresql/ch-2.plperl | 21 ++++++++++++++ challenge-240/luca-ferrari/postgresql/ch-2.sql | 29 +++++++++++++++++++ challenge-240/luca-ferrari/python/ch-1.py | 34 ++++++++++++++++++++++ challenge-240/luca-ferrari/python/ch-2.py | 25 ++++++++++++++++ challenge-240/luca-ferrari/raku/ch-1.p6 | 27 +++++++++++++++++ challenge-240/luca-ferrari/raku/ch-2.p6 | 14 +++++++++ 16 files changed, 218 insertions(+) create mode 100644 challenge-240/luca-ferrari/blog-1.txt create mode 100644 challenge-240/luca-ferrari/blog-2.txt create mode 100644 challenge-240/luca-ferrari/blog-3.txt create mode 100644 challenge-240/luca-ferrari/blog-4.txt create mode 100644 challenge-240/luca-ferrari/blog-5.txt create mode 100644 challenge-240/luca-ferrari/blog-6.txt create mode 100644 challenge-240/luca-ferrari/blog-7.txt create mode 100644 challenge-240/luca-ferrari/blog-8.txt create mode 100644 challenge-240/luca-ferrari/postgresql/ch-1.plperl create mode 100644 challenge-240/luca-ferrari/postgresql/ch-1.sql create mode 100644 challenge-240/luca-ferrari/postgresql/ch-2.plperl create mode 100644 challenge-240/luca-ferrari/postgresql/ch-2.sql create mode 100644 challenge-240/luca-ferrari/python/ch-1.py create mode 100644 challenge-240/luca-ferrari/python/ch-2.py create mode 100644 challenge-240/luca-ferrari/raku/ch-1.p6 create mode 100644 challenge-240/luca-ferrari/raku/ch-2.p6 diff --git a/challenge-240/luca-ferrari/blog-1.txt b/challenge-240/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..4269929cbc --- /dev/null +++ b/challenge-240/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task1 diff --git a/challenge-240/luca-ferrari/blog-2.txt b/challenge-240/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..6d4d871905 --- /dev/null +++ b/challenge-240/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task2 diff --git a/challenge-240/luca-ferrari/blog-3.txt b/challenge-240/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..0f0e65edac --- /dev/null +++ b/challenge-240/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task1plperl diff --git a/challenge-240/luca-ferrari/blog-4.txt b/challenge-240/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..aba90f9235 --- /dev/null +++ b/challenge-240/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task2plperl diff --git a/challenge-240/luca-ferrari/blog-5.txt b/challenge-240/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..2fa0731ce3 --- /dev/null +++ b/challenge-240/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task1plpgsql diff --git a/challenge-240/luca-ferrari/blog-6.txt b/challenge-240/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..8f92fbb884 --- /dev/null +++ b/challenge-240/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task2plpgsql diff --git a/challenge-240/luca-ferrari/blog-7.txt b/challenge-240/luca-ferrari/blog-7.txt new file mode 100644 index 0000000000..e897c21a36 --- /dev/null +++ b/challenge-240/luca-ferrari/blog-7.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task1python diff --git a/challenge-240/luca-ferrari/blog-8.txt b/challenge-240/luca-ferrari/blog-8.txt new file mode 100644 index 0000000000..0f73f70b90 --- /dev/null +++ b/challenge-240/luca-ferrari/blog-8.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/10/23/PerlWeeklyChallenge240.html#task2python diff --git a/challenge-240/luca-ferrari/postgresql/ch-1.plperl b/challenge-240/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..57ac9e5d31 --- /dev/null +++ b/challenge-240/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,25 @@ +-- +-- Perl Weekly Challenge 240 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc240; + +CREATE OR REPLACE FUNCTION +pwc240.task1_plperl( text, text[] ) +RETURNS boolean +AS $CODE$ + my ( $check, $strings ) = @_; + my @check_letters = map { $_ } split( //, $check ); + my @letters = map { ( split //, $_ )[ 0 ] } $strings->@*; + + return 0 if ( @check_letters != @letters ); + + for ( 0 .. @check_letters ) { + return 0 if ( CORE::fc( $check_letters[ $_ ] ) ne CORE::fc( $letters[ $_ ] ) ); + } + + return 1; +$CODE$ +LANGUAGE plperl; diff --git a/challenge-240/luca-ferrari/postgresql/ch-1.sql b/challenge-240/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..0626a4f257 --- /dev/null +++ b/challenge-240/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,35 @@ +-- +-- Perl Weekly Challenge 240 +-- Task 1 +-- +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc240; + +CREATE OR REPLACE FUNCTION +pwc240.task1_plpgsql( c text, s text[] ) +RETURNS boolean +AS $CODE$ +DECLARE + check_letters text[]; + current_index int; + current_letter text; +BEGIN + check_letters := regexp_split_to_array( c, '' ); + + IF array_length( check_letters, 1 ) <> array_length( s, 1 ) THEN + RETURN FALSE; + END IF; + + FOR current_index IN 1 .. array_length( check_letters, 1 ) LOOP + current_letter := ( regexp_split_to_array( s[ current_index ], '' ) )[ 1 ]; + IF lower( current_letter ) <> lower( check_letters[ current_index ] ) THEN + RETURN FALSE; + END IF; + END LOOP; + + RETURN TRUE; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-240/luca-ferrari/postgresql/ch-2.plperl b/challenge-240/luca-ferrari/postgresql/ch-2.plperl new file mode 100644 index 0000000000..61bc0e99a9 --- /dev/null +++ b/challenge-240/luca-ferrari/postgresql/ch-2.plperl @@ -0,0 +1,21 @@ +-- +-- Perl Weekly Challenge 240 +-- Task 2 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc240; + +CREATE OR REPLACE FUNCTION +pwc240.task2_plperl( int[] ) +RETURNS SETOF int +AS $CODE$ + my ( $numbers ) = @_; + + for ( 0 .. $numbers->@* ) { + return_next( $numbers->[ $numbers->[ $_ ] ] ); + } + + return undef; +$CODE$ +LANGUAGE plperl; diff --git a/challenge-240/luca-ferrari/postgresql/ch-2.sql b/challenge-240/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..d17a71c816 --- /dev/null +++ b/challenge-240/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,29 @@ +-- +-- Perl Weekly Challenge 240 +-- Task 2 +-- +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc240; + +CREATE OR REPLACE FUNCTION +pwc240.task2_plpgsql( n int[] ) +RETURNS SETOF INT +AS $CODE$ +DECLARE + current_index int; + position int; +BEGIN + FOR current_index IN 1 .. array_length( n, 1 ) LOOP + position := n[ current_index ]; + IF position = 0 THEN + position := 1; + END IF; + RETURN NEXT n[ position ]; + END LOOP; + + RETURN; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-240/luca-ferrari/python/ch-1.py b/challenge-240/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..8dbb559f5f --- /dev/null +++ b/challenge-240/luca-ferrari/python/ch-1.py @@ -0,0 +1,34 @@ +#!python + +# +# Perl Weekly Challenge 240 +# Task 1 +# +# See +# + +import sys + +# task implementation +def main( argv ): + letters = list( map( lambda x: x[ 0 ].casefold(), argv[1:] ) ) + check_chars = list( argv[ 0 ] ) + + if len( check_chars ) != len( letters ): + print( 'False' ) + return False + + for index in range( len( argv[ 0 ] ) ): + if argv[ 0 ][ index ].casefold() != letters[ index ]: + print( 'False' ) + return False + + print( 'True' ) + return True + + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + diff --git a/challenge-240/luca-ferrari/python/ch-2.py b/challenge-240/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..c72aab54ec --- /dev/null +++ b/challenge-240/luca-ferrari/python/ch-2.py @@ -0,0 +1,25 @@ +#!python + +# +# Perl Weekly Challenge 240 +# Task 2 +# +# See +# + +import sys + +# task implementation +def main( argv ): + new_array = [] + for index in range( len( argv ) ): + new_array.insert( index, argv[ int( argv[ index ] ) ] ) + + print( ','.join( new_array ) ) + + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + diff --git a/challenge-240/luca-ferrari/raku/ch-1.p6 b/challenge-240/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..9b47851f0a --- /dev/null +++ b/challenge-240/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,27 @@ +#!raku + +# +# Perl Weekly Challenge 240 +# Task 1 +# +# See +# + +sub MAIN( $check-string, *@strings ) { + # the check string must contain the same + # exact number of chars of the number of strings + 'False'.say and exit if ( $check-string.comb.elems != @strings.elems ); + + # # check all the letters + # my @letters = $check-string.comb; + # for 0 ..^ @strings.elems { + # 'False'.say and exit if ( @letters[ $_ ].fc ne ( @strings[ $_ ].comb )[ 0 ].fc ); + # } + + + my @check-letters = $check-string.comb.map( *.fc ); + my @letters = @strings.map( ( *.comb )[ 0 ].fc ); + 'True'.say and exit if ( @letters ~~ @check-letters ); + + 'False'.say; +} diff --git a/challenge-240/luca-ferrari/raku/ch-2.p6 b/challenge-240/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..8f7508123d --- /dev/null +++ b/challenge-240/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,14 @@ +#!raku + +# +# Perl Weekly Challenge 240 +# Task 2 +# +# See +# +# Write a script to create an array such that new[i] = old[old[i]] where 0 <= i < new.length. +sub MAIN( *@numbers where { @numbers.grep( * ~~ Int ).elems == @numbers.elems } ) { + my @new; + @new[ $_ ] = @numbers[ @numbers[ $_ ] ] for 0 ..^ @numbers.elems; + @new.join( ', ' ).say; +} -- cgit From 94e2cf1f9c5dd483dce42373a407e2f49f792fd2 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 23 Oct 2023 10:27:28 -0600 Subject: Solve PWC240 --- challenge-240/wlmb/blog.txt | 1 + challenge-240/wlmb/perl/ch-1.pl | 12 ++++++++++++ challenge-240/wlmb/perl/ch-2.pl | 13 +++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 challenge-240/wlmb/blog.txt create mode 100755 challenge-240/wlmb/perl/ch-1.pl create mode 100755 challenge-240/wlmb/perl/ch-2.pl diff --git a/challenge-240/wlmb/blog.txt b/challenge-240/wlmb/blog.txt new file mode 100644 index 0000000000..88dc3f83c5 --- /dev/null +++ b/challenge-240/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2023/10/23/PWC240/ diff --git a/challenge-240/wlmb/perl/ch-1.pl b/challenge-240/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..db3ea1b6a2 --- /dev/null +++ b/challenge-240/wlmb/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +# Perl weekly challenge 240 +# Task 1: Acronym +# +# See https://wlmb.github.io/2023/10/23/PWC240/#task-1-acronym +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 A W1 [W2...] + to test if A is an acronym of the words W1, W2... + FIN +my $acronym=shift; +say "$acronym <= @ARGV: ", lc $acronym eq (lc join "", map {substr $_, 0,1} @ARGV)?"True":"False" diff --git a/challenge-240/wlmb/perl/ch-2.pl b/challenge-240/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..e49a17262f --- /dev/null +++ b/challenge-240/wlmb/perl/ch-2.pl @@ -0,0 +1,13 @@ +#!/usr/bin/env perl +# Perl weekly challenge 240 +# Task 2: Build Array +# +# See https://wlmb.github.io/2023/10/23/PWC240/#task-2-build-array +use v5.36; +use List::Util qw(min max); +die <<~"FIN" unless @ARGV; + Usage: $0 N0 [N1...] + to iterate indexing the array N0, N1... + FIN +die "Elements should be >=0 and < #of elements" unless 0<=min @ARGV && max @ARGV<@ARGV; +say "@ARGV -> @ARGV[@ARGV]"; -- cgit From bc7ba222cd6a91bf181bc8c571ffa873f79a34af Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Mon, 23 Oct 2023 12:44:04 -0400 Subject: DAJ 240 --- challenge-240/dave-jacoby/perl/ch-1.pl | 28 ++++++++++++++++++++++++++ challenge-240/dave-jacoby/perl/ch-2.pl | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 challenge-240/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-240/dave-jacoby/perl/ch-2.pl diff --git a/challenge-240/dave-jacoby/perl/ch-1.pl b/challenge-240/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..a983dd259a --- /dev/null +++ b/challenge-240/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +my @examples = ( + + { str => [ "Perl", "Python", "Pascal" ], chk => "ppp", }, + { str => [ "Perl", "Raku" ], chk => "rp", }, + { str => [ "Oracle", "Awk", "C" ], chk => "oac", }, +); + +for my $e (@examples) { + my $output = acronym($e); + my $str = join ', ', map { qq{"$_"} } $e->{str}->@*; + my $chk = $e->{chk}; + say <<~"END"; + Input: \@str = ($str) + \$chk = "$chk" + Output: $output + END +} + +sub acronym ($input) { + my $work = lc join '', map { substr $_, 0, 1 } $input->{str}->@*; + return $work eq $input->{chk} ? 'true' : 'false' ; +} diff --git a/challenge-240/dave-jacoby/perl/ch-2.pl b/challenge-240/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..5a31994e2b --- /dev/null +++ b/challenge-240/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,36 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +use Algorithm::Permute; + +my @examples = ( + + [ 0, 2, 1, 5, 3, 4 ], + [ 5, 0, 1, 2, 3, 4 ], +); +for my $e (@examples) { + my @output = build_array( $e->@* ); + my @input = $e->@*; + my $output = join ', ', @output; + my $input = join ', ', @input; + say <<~"END"; + Input: \@int = ($input) + Output: ($output) + END +} + +sub build_array (@int) { + my $len = -1 + scalar @int; + my @copy = @int; + my $p = Algorithm::Permute->new( \@copy ); +OUTER: while ( my @res = $p->next ) { + for my $i ( 0 .. $len ) { + next OUTER unless $res[$i] == $int[ $int[$i] ]; + } + return @res; + } + return (); +} -- cgit From ade424306f2fa756c28685a54ee32ae013719fa1 Mon Sep 17 00:00:00 2001 From: Humberto Massa Date: Mon, 23 Oct 2023 15:14:39 -0300 Subject: one-liners for challenge 228 --- challenge-228/massa/raku/ch-1.raku | 68 ++++++++++++++++++++++++++++++++++++ challenge-228/massa/raku/ch-2.raku | 71 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 challenge-228/massa/raku/ch-1.raku create mode 100644 challenge-228/massa/raku/ch-2.raku diff --git a/challenge-228/massa/raku/ch-1.raku b/challenge-228/massa/raku/ch-1.raku new file mode 100644 index 0000000000..c105d1e19c --- /dev/null +++ b/challenge-228/massa/raku/ch-1.raku @@ -0,0 +1,68 @@ +#! /usr/bin/env raku + +# Perl Weekly Challenge +# © 2023 Shimon Bollinger. All rights reserved. +# Last modified: Mon 15 May 2023 09:17:32 PM EDT +# Version 0.0.1 + +=begin pod +=TITLE +=head2 Task 1: Unique Sum + +=SUBTITLE +=head2 Submitted by massa + +=CHALLENGE +=head2 + +You are given an array of integers. + +Write a script to find out the sum of unique elements in the given array. + +=head3 Example 1: + + Input: @int = (2, 1, 3, 2) + Output: 4 + + In the given array we have 2 unique elements (1, 3). + +=head3 Example 2: + + Input: @int = (1, 1, 1, 1) + Output: 0 + + In the given array no unique element found. + +=head3 Example 3: + + Input: @int = (2, 1, 3, 4) + Output: 10 + + In the given array every element is unique. + +=SOLUTION + +=end pod + +# always use the latest version of Raku +use v6.*; + +sub unique-sum(Positional $_) { + .Bag.grep(*.value ≤ 1)».key.sum +} + +multi MAIN (Bool :$test!) { + use Test; + + my @tests = [ + %{ input => (2, 1, 3, 2), output => 4 }, + %{ input => (1, 1, 1, 1), output => 0 }, + %{ input => (2, 1, 3, 4), output => 10 }, + ]; + + for @tests { + unique-sum( . ).&is-deeply: ., .; + } # end of for @tests +} # end of multi MAIN (Bool :$test!) + + diff --git a/challenge-228/massa/raku/ch-2.raku b/challenge-228/massa/raku/ch-2.raku new file mode 100644 index 0000000000..a23be64440 --- /dev/null +++ b/challenge-228/massa/raku/ch-2.raku @@ -0,0 +1,71 @@ +#! /usr/bin/env raku + +# Perl Weekly Challenge +# © 2023 Shimon Bollinger. All rights reserved. +# Last modified: Mon 15 May 2023 09:17:32 PM EDT +# Version 0.0.1 + +=begin pod +=TITLE +=head2 Task 2: Empty Array + +=SUBTITLE +=head2 Submitted by massa + +=CHALLENGE +=head2 + +You are given an array of integers in which all elements are unique. + +Write a script to perform the following operations until the array is empty and +return the total count of operations. + + If the first element is the smallest then remove it otherwise move it to + the end. + +=head3 Example 1: + + Input: @int = (3, 4, 2) + Ouput: 5 + + Operation 1: move 3 to the end: (4, 2, 3) + Operation 2: move 4 to the end: (2, 3, 4) + Operation 3: remove element 2: (3, 4) + Operation 4: remove element 3: (4) + Operation 5: remove element 4: () + +=head3 Example 2: + + Input: @int = (1, 2, 3) + Ouput: 3 + + Operation 1: remove element 1: (2, 3) + Operation 2: remove element 2: (3) + Operation 3: remove element 3: () + +=SOLUTION + +=end pod + +# always use the latest version of Raku +use v6.*; + +sub empty-array(@_) { + + (@_, -> @ [$head, *@tail] { $head ≤ @tail.all ?? @tail !! [|@tail, $head] } ... * ≤ 1) +} + +multi MAIN (Bool :$test!) { + use Test; + + my @tests = [ + %{ input => (3, 4, 2), output => 5 }, + %{ input => (1, 2, 3), output => 3 }, + ]; + + for @tests { + empty-array( . ).&is-deeply: ., .; + + } # end of for @tests +} # end of multi MAIN (:$test!) + + -- cgit From 11d3736ea230f3db841584aa1a55988d851bb61e Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 23 Oct 2023 19:31:53 +0100 Subject: - Added solutions by Robert DiCicco. - Added solutions by Ulrich Rieke. - Added solutions by Eric Cheung. - Added solutions by Mark Anderson. - Added solutions by Niels van Dijke. - Added solutions by Peter Meszaros. - Added solutions by PokGoPun. - Added solutions by E. Choroba. - Added solutions by Lubos Kolouch. - Added solutions by Steven Wilson. - Added solutions by David Ferrone. - Added solutions by W. Luis Mochan. - Added solutions by Dave Jacoby. - Added solutions by Humberto Massa. --- challenge-240/eric-cheung/python/ch-1.py | 16 + challenge-240/eric-cheung/python/ch-2.py | 7 + challenge-240/perlboy1967/perl/ch-1.pl | 34 + challenge-240/perlboy1967/perl/ch-2.pl | 33 + challenge-240/perlboy1967/perl/ch1.pl | 34 - challenge-240/perlboy1967/perl/ch2.pl | 33 - challenge-240/robert-dicicco/julia/ch-1.jl | 53 + challenge-240/robert-dicicco/perl/ch-1.pl | 53 + challenge-240/robert-dicicco/powershell/ch-1.psl | 54 + challenge-240/robert-dicicco/python/ch-1.py | 45 + challenge-240/robert-dicicco/raku/ch-1.raku | 51 + challenge-240/robert-dicicco/ruby/ch-1.rb | 51 + challenge-240/steven-wilson/python/ch-01.py | 24 - challenge-240/steven-wilson/python/ch-02.py | 21 - challenge-240/steven-wilson/python/ch-1.py | 24 + challenge-240/steven-wilson/python/ch-2.py | 21 + challenge-240/ulrich-rieke/cpp/ch-1.cpp | 37 + challenge-240/ulrich-rieke/cpp/ch-2.cpp | 37 + challenge-240/ulrich-rieke/haskell/ch-1.hs | 15 + challenge-240/ulrich-rieke/haskell/ch-2.hs | 15 + challenge-240/ulrich-rieke/perl/ch-1.pl | 23 + challenge-240/ulrich-rieke/perl/ch-2.pl | 17 + challenge-240/ulrich-rieke/raku/ch-1.raku | 12 + challenge-240/ulrich-rieke/raku/ch-2.raku | 12 + challenge-240/ulrich-rieke/rust/ch-1.rs | 25 + challenge-240/ulrich-rieke/rust/ch-2.rs | 18 + stats/pwc-challenge-228.json | 287 +- stats/pwc-challenge-239.json | 760 ++++++ stats/pwc-current.json | 676 +---- stats/pwc-language-breakdown-summary.json | 72 +- stats/pwc-language-breakdown.json | 3165 +++++++++++----------- stats/pwc-leaders.json | 438 +-- stats/pwc-summary-1-30.json | 42 +- stats/pwc-summary-121-150.json | 24 +- stats/pwc-summary-151-180.json | 132 +- stats/pwc-summary-181-210.json | 108 +- stats/pwc-summary-211-240.json | 50 +- stats/pwc-summary-241-270.json | 108 +- stats/pwc-summary-271-300.json | 108 +- stats/pwc-summary-31-60.json | 36 +- stats/pwc-summary-61-90.json | 52 +- stats/pwc-summary-91-120.json | 124 +- stats/pwc-summary.json | 1866 ++++++------- 43 files changed, 4807 insertions(+), 4006 deletions(-) create mode 100755 challenge-240/eric-cheung/python/ch-1.py create mode 100755 challenge-240/eric-cheung/python/ch-2.py create mode 100755 challenge-240/perlboy1967/perl/ch-1.pl create mode 100755 challenge-240/perlboy1967/perl/ch-2.pl delete mode 100755 challenge-240/perlboy1967/perl/ch1.pl delete mode 100755 challenge-240/perlboy1967/perl/ch2.pl create mode 100644 challenge-240/robert-dicicco/julia/ch-1.jl create mode 100644 challenge-240/robert-dicicco/perl/ch-1.pl create mode 100644 challenge-240/robert-dicicco/powershell/ch-1.psl create mode 100644 challenge-240/robert-dicicco/python/ch-1.py create mode 100644 challenge-240/robert-dicicco/raku/ch-1.raku create mode 100644 challenge-240/robert-dicicco/ruby/ch-1.rb delete mode 100644 challenge-240/steven-wilson/python/ch-01.py delete mode 100644 challenge-240/steven-wilson/python/ch-02.py create mode 100644 challenge-240/steven-wilson/python/ch-1.py create mode 100644 challenge-240/steven-wilson/python/ch-2.py create mode 100755 challenge-240/ulrich-rieke/cpp/ch-1.cpp create mode 100755 challenge-240/ulrich-rieke/cpp/ch-2.cpp create mode 100755 challenge-240/ulrich-rieke/haskell/ch-1.hs create mode 100755 challenge-240/ulrich-rieke/haskell/ch-2.hs create mode 100755 challenge-240/ulrich-rieke/perl/ch-1.pl create mode 100755 challenge-240/ulrich-rieke/perl/ch-2.pl create mode 100755 challenge-240/ulrich-rieke/raku/ch-1.raku create mode 100755 challenge-240/ulrich-rieke/raku/ch-2.raku create mode 100755 challenge-240/ulrich-rieke/rust/ch-1.rs create mode 100755 challenge-240/ulrich-rieke/rust/ch-2.rs create mode 100644 stats/pwc-challenge-239.json diff --git a/challenge-240/eric-cheung/python/ch-1.py b/challenge-240/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..0cc518455d --- /dev/null +++ b/challenge-240/eric-cheung/python/ch-1.py @@ -0,0 +1,16 @@ + +## Example 1 +## arrStrInput = ["Perl", "Python", "Pascal"] +## strCheck = "ppp" + + +## Example 2 +## arrStrInput = ["Perl", "Raku"] +## strCheck = "rp" + + +## Example 3 +arrStrInput = ["Oracle", "Awk", "C"] +strCheck = "oac" + +print ("".join([strLoop[0].lower() for strLoop in arrStrInput]) == strCheck) diff --git a/challenge-240/eric-cheung/python/ch-2.py b/challenge-240/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..409146c3f4 --- /dev/null +++ b/challenge-240/eric-cheung/python/ch-2.py @@ -0,0 +1,7 @@ + +## arrInput = [0, 2, 1, 5, 3, 4] ## Example 1 +arrInput = [5, 0, 1, 2, 3, 4] ## Example 2 + +arrOutput = [arrInput[arrInput[nIndx]] for nIndx in range(len(arrInput))] + +print (arrOutput) diff --git a/challenge-240/perlboy1967/perl/ch-1.pl b/challenge-240/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..6110e5f796 --- /dev/null +++ b/challenge-240/perlboy1967/perl/ch-1.pl @@ -0,0 +1,34 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 240 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-240 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Acronym +Submitted by: Mohammad S Anwar + +You are given two arrays of strings and a check string. + +Write a script to find out if the check string is the acronym of the words +in the given array. + +=cut + +use v5.32; +use common::sense; +use feature 'signatures'; + +use Test2::V0; + +sub acronym ($string,@words) { + lc($string) eq join('',map {lc substr($_,0,1)} @words) ? 1 : 0; +} + +is(acronym('ppp','Perl','Python','Pascal'),1); +is(acronym('rp','Perl','Raku'),0); +is(acronym('oac','Oracle','Awk','C'),1); + +done_testing; diff --git a/challenge-240/perlboy1967/perl/ch-2.pl b/challenge-240/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..89727b06df --- /dev/null +++ b/challenge-240/perlboy1967/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 240 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-240 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Build Array +Submitted by: Mohammad S Anwar + +You are given an array of integers. + +Write a script to create an array such that +new[i] = old[old[i]] where 0 <= i < new.length. + +=cut + +use v5.32; +use common::sense; +use feature 'signatures'; + +use Test2::V0; + +sub buildArray (@int) { + [map { $int[$int[$_]] } (0 .. scalar(@int) - 1)]; +} + +is(buildArray(0,2,1,5,3,4),[0,1,2,4,5,3]); +is(buildArray(5,0,1,2,3,4),[4,5,0,1,2,3]); + +done_testing; diff --git a/challenge-240/perlboy1967/perl/ch1.pl b/challenge-240/perlboy1967/perl/ch1.pl deleted file mode 100755 index 6110e5f796..0000000000 --- a/challenge-240/perlboy1967/perl/ch1.pl +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/perl - -=pod - -The Weekly Challenge - 240 -- https://theweeklychallenge.org/blog/perl-weekly-challenge-240 - -Author: Niels 'PerlBoy' van Dijke - -Task 1: Acronym -Submitted by: Mohammad S Anwar - -You are given two arrays of strings and a check string. - -Write a script to find out if the check string is the acronym of the words -in the given array. - -=cut - -use v5.32; -use common::sense; -use feature 'signatures'; - -use Test2::V0; - -sub acronym ($string,@words) { - lc($string) eq join('',map {lc substr($_,0,1)} @words) ? 1 : 0; -} - -is(acronym('ppp','Perl','Python','Pascal'),1); -is(acronym('rp','Perl','Raku'),0); -is(acronym('oac','Oracle','Awk','C'),1); - -done_testing; diff --git a/challenge-240/perlboy1967/perl/ch2.pl b/challenge-240/perlboy1967/perl/ch2.pl deleted file mode 100755 index 89727b06df..0000000000 --- a/challenge-240/perlboy1967/perl/ch2.pl +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/perl - -=pod - -The Weekly Challenge - 240 -- https://theweeklychallenge.org/blog/perl-weekly-challenge-240 - -Author: Niels 'PerlBoy' van Dijke - -Task 2: Build Array -Submitted by: Mohammad S Anwar - -You are given an array of integers. - -Write a script to create an array such that -new[i] = old[old[i]] where 0 <= i < new.length. - -=cut - -use v5.32; -use common::sense; -use feature 'signatures'; - -use Test2::V0; - -sub buildArray (@int) { - [map { $int[$int[$_]] } (0 .. scalar(@int) - 1)]; -} - -is(buildArray(0,2,1,5,3,4),[0,1,2,4,5,3]); -is(buildArray(5,0,1,2,3,4),[4,5,0,1,2,3]); - -done_testing; diff --git a/challenge-240/robert-dicicco/julia/ch-1.jl b/challenge-240/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..dd6395a738 --- /dev/null +++ b/challenge-240/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,53 @@ +#!/usr/bin/env julia +#= +------------------------------------ +AUTHOR: Robert DiCicco +DATE : 2023-10-21 +Challenge 240 Task 01 Acronym ( Julia ) +------------------------------------ +=# + +using Printf + +mystr = [["Perl", "Python", "Pascal"],["Perl", "Raku"],["Oracle", "Awk", "C"]] +mychk = ["ppp","rp","oac"] + +cnt = 1 + +function GetFirstLetters(wds) + acronym = "" + for w in wds + acronym = string(acronym, lowercase(w[1,1])) + end + return acronym +end + +for str in mystr + global cnt + @printf("Input: @str = %s\n",str) + @printf("check = %s\n", mychk[cnt]) + retval == mychk[cnt] ? println("Output: true\n\n") : println("Output: false\n\n") + cnt += 1 +end + +#= +------------------------------------ +SAMPLE OUTPUT + +ruby .\Acronym.rb + +Input: @str = ["Perl", "Python", "Pascal"] +check = ppp +Output: true + +Input: @str = ["Perl", "Raku"] +check = rp +Output: false + +Input: @str = ["Oracle", "Awk", "C"] +check = oac +Output: true +------------------------------------ +=# + + diff --git a/challenge-240/robert-dicicco/perl/ch-1.pl b/challenge-240/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..eb14123032 --- /dev/null +++ b/challenge-240/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +=begin +------------------------------------ +AUTHOR: Robert DiCicco +DATE : 2023-10-21 +Challenge 240 Task 01 Acronym ( Perl ) +------------------------------------ +=cut + +use v5.38; + +my @mystr = (["Perl", "Python", "Pascal"],["Perl", "Raku"],["Oracle", "Awk", "C"]); +my @mychk = ("ppp","rp","oac"); +my $cnt = 0; + +sub GetFirstLetters($wds) { + my $acronym = ""; + for my $w (@$wds) { + $acronym .= lc(substr($w,0,1)); + } + return $acronym; + +} + +for my $str (@mystr){ + say "Input: \@str = [@$str]"; + say "\$chk = \"$mychk[$cnt]\""; + my $retval = GetFirstLetters($str); + $retval eq $mychk[$cnt] ? say "Output: true\n" : say "Output: false\n"; + $cnt++; +} + +=begin +------------------------------------ +SAMPLE OUTPUT + +perl .\Acronym.pl + +Input: @str = [Perl Python Pascal] +$chk = "ppp" +Output: true + +Input: @str = [Perl Raku] +$chk = "rp" +Output: false + +Input: @str = [Oracle Awk C] +$chk = "oac" +Output: true +------------------------------------ +=cut + + diff --git a/challenge-240/robert-dicicco/powershell/ch-1.psl b/challenge-240/robert-dicicco/powershell/ch-1.psl new file mode 100644 index 0000000000..593a5f00ed --- /dev/null +++ b/challenge-240/robert-dicicco/powershell/ch-1.psl @@ -0,0 +1,54 @@ +#!/usr/bin/env powershell +<# +------------------------------------ +AUTHOR: Robert DiCicco +DATE : 2023-10-21 +Challenge 240 Task 01 Acronym ( Powershell ) +------------------------------------ + #> +$mystr = @(("Perl", "Python", "Pascal"),("Perl", "Raku"),("Oracle", "Awk", "C")) +$mychk = @(("ppp","rp","oac")) +$cnt = 0 + +function GetFirstLetters($wds) { + $acronym = "" + foreach ($w in $wds) { + $w = $w.ToLower() + $acronym += $w[0] + } + return $acronym +} + +foreach ($str in $mystr) { + write-host "Input: @str = [$str]" + write-host "check = ["$mychk[$cnt]"]" + $retval = GetFirstLetters($mystr[$cnt]) + if ( $retval -eq $mychk[$cnt]) { + write-host "Output: true`n" + } else { + write-host "Output: false`n" + } + $cnt += 1 +} + +<# +------------------------------------ +SAMPLE OUTPUT + +.\Acronym.ps1 + +Input: @str = [Perl Python Pascal] +check = [ ppp ] +Output: true + +Input: @str = [Perl Raku] +check = [ rp ] +Output: false + +Input: @str = [Oracle Awk C] +check = [ oac ] +Output: true +------------------------------------ + #> + + diff --git a/challenge-240/robert-dicicco/python/ch-1.py b/challenge-240/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..295308ee1e --- /dev/null +++ b/challenge-240/robert-dicicco/python/ch-1.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# ------------------------------------ +# AUTHOR: Robert DiCicco +# DATE : 2023-10-21 +# Challenge 240 Task 01 Acronym ( Python ) +# ------------------------------------ + +mystr = [["Perl", "Python", "Pascal"],["Perl", "Raku"],["Oracle", "Awk", "C"]] +mychk = ["ppp","rp","oac"] + +cnt = 0 + +def GetFirstLetters(wds): + acronym = "" + for w in wds: + acronym += w[0].lower() + return acronym + +for str in mystr: + print(f"Input: @str = {str}") + print(f"check = \"{mychk[cnt]}\"") + retval = GetFirstLetters(str) + if retval == mychk[cnt] : + print("Output: true\n") + else : + print("Output: false\n") + cnt += 1 + +# ------------------------------------ +# SAMPLE OUTPUT + +# python .\Acronym.py + +# Input: @str = ['Perl', 'Python', 'Pascal'] +# check = "ppp" +# Output: true + +# Input: @str = ['Perl', 'Raku'] +# check = "rp" +# Output: false + +# Input: @str = ['Oracle', 'Awk', 'C'] +# check = "oac" +# Output: true +# ------------------------------------ diff --git a/challenge-240/robert-dicicco/raku/ch-1.raku b/challenge-240/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..756d324c98 --- /dev/null +++ b/challenge-240/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,51 @@ +#!/usr/bin/env raku +=begin comment +------------------------------------ +AUTHOR: Robert DiCicco +DATE : 2023-10-21 +Challenge 240 Task 01 Acronym ( Raku ) +------------------------------------ +=end comment +use v6; + +my @mystr = (["Perl", "Python", "Pascal"],["Perl", "Raku"],["Oracle", "Awk", "C"]); +my @mychk = ("ppp","rp","oac"); +my $cnt = 0; + +sub GetFirstLetters(@wds) { + my $acronym = ""; + for @wds -> $w { + $acronym ~= lc(substr($w,0,1)); + } + return $acronym; +} + +for (@mystr) -> @str { + say "Input: \@str = ",@str; + say "\$chk = \"@mychk[$cnt]\""; + my $retval = GetFirstLetters(@str); + $retval eq @mychk[$cnt] ?? say "Output: true\n" !! say "Output: false\n"; + $cnt++; +} + +=begin comment +------------------------------------ +SAMPLE OUTPUT + +raku .\Acronym.rk + +Input: @str = [Perl Python Pascal] +$chk = "ppp" +Output: true + +Input: @str = [Perl Raku] +$chk = "rp" +Output: false + +Input: @str = [Oracle Awk C] +$chk = "oac" +Output: true +------------------------------------ +=end comment + + diff --git a/challenge-240/robert-dicicco/ruby/ch-1.rb b/challenge-240/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..0b84a9c850 --- /dev/null +++ b/challenge-240/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby +=begin +------------------------------------ +AUTHOR: Robert DiCicco +DATE : 2023-10-21 +Challenge 240 Task 01 Acronym ( Ruby ) +------------------------------------ +=end + +mystr = [["Perl", "Python", "Pascal"],["Perl", "Raku"],["Oracle", "Awk", "C"]] +mychk = ["ppp","rp","oac"] +cnt = 0; + +def GetFirstLetters(wds) + acronym = "" + wds.each do |w| + acronym.concat(w[0,1]) + end + return acronym.downcase +end + +mystr.each do |str| + puts("Input: @str = #{str}") + puts("check = #{mychk[cnt]}") + retval = GetFirstLetters(str) + retval == mychk[cnt] ? puts("Output: true\n\n") : puts("Output: false\n\n") + cnt += 1 +end + +=begin +------------------------------------ +SAMPLE OUTPUT + +ruby .\Acronym.rb + +Input: @str = ["Perl", "Python", "Pascal"] +check = ppp +Output: true + +Input: @str = ["Perl", "Raku"] +check = rp +Output: false + +Input: @str = ["Oracle", "Awk", "C"] +check = oac +Output: true +------------------------------------ +=end + + + diff --git a/challenge-240/steven-wilson/python/ch-01.py b/challenge-240/steven-wilson/python/ch-01.py deleted file mode 100644 index ffddcff201..0000000000 --- a/challenge-240/steven-wilson/python/ch-01.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 - - -def acronym(check, words): - ''' - Is the check string an acronym of the words in the given array - >>> acronym("ppp", ("Perl", "Python", "Pascal")) - True - >>> acronym("rp", ("Perl", "Raku")) - False - >>> acronym("oac", ("Oracle", "Awk", "C")) - True - ''' - acronym = "".join([word[0].lower() for word in words]) - if acronym == check: - return True - else: - return False - - -if __name__ == "__main__": - import doctest - - doctest.testmod() diff --git a/challenge-240/steven-wilson/python/ch-02.py b/challenge-240/steven-wilson/python/ch-02.py deleted file mode 100644 index a54d18efee..0000000000 --- a/challenge-240/steven-wilson/python/ch-02.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 - - -def build_array(elements): - ''' - create an array such that new[i] = old[old[i]] where 0 <= i < new.length - >>> build_array([0, 2, 1, 5, 3, 4]) - [0, 1, 2, 4, 5, 3] - >>> build_array([5, 0, 1, 2, 3, 4]) - [4, 5, 0, 1, 2, 3] - ''' - new = [] - for i, value in enumerate(elements): - new.append(elements[elements[i]]) - return new - - -if __name__ == "__main__": - import doctest - - doctest.testmod() diff --git a/challenge-240/steven-wilson/python/ch-1.py b/challenge-240/steven-wilson/python/ch-1.py new file mode 100644 index 0000000000..ffddcff201 --- /dev/null +++ b/challenge-240/steven-wilson/python/ch-1.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + + +def acronym(check, words): + ''' + Is the check string an acronym of the words in the given array + >>> acronym("ppp", ("Perl", "Python", "Pascal")) + True + >>> acronym("rp", ("Perl", "Raku")) + False + >>> acronym("oac", ("Oracle", "Awk", "C")) + True + ''' + acronym = "".join([word[0].lower() for word in words]) + if acronym == check: + return True + else: + return False + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/challenge-240/steven-wilson/python/ch-2.py b/challenge-240/steven-wilson/python/ch-2.py new file mode 100644 index 0000000000..a54d18efee --- /dev/null +++ b/challenge-240/steven-wilson/python/ch-2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + + +def build_array(elements): + ''' + create an array such that new[i] = old[old[i]] where 0 <= i < new.length + >>> build_array([0, 2, 1, 5, 3, 4]) + [0, 1, 2, 4, 5, 3] + >>> build_array([5, 0, 1, 2, 3, 4]) + [4, 5, 0, 1, 2, 3] + ''' + new = [] + for i, value in enumerate(elements): + new.append(elements[elements[i]]) + return new + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/challenge-240/ulrich-rieke/cpp/ch-1.cpp b/challenge-240/ulrich-rieke/cpp/ch-1.cpp new file mode 10