From f5bc523cc5811d19eace035887c107108c894c2d Mon Sep 17 00:00:00 2001 From: "Jaldhar H. Vyas" Date: Thu, 4 Jan 2024 15:08:54 -0500 Subject: Challenge 248 by Jaldhar H. Vyas. --- challenge-248/jaldhar-h-vyas/blog.txt | 1 + challenge-248/jaldhar-h-vyas/perl/ch-1.pl | 23 +++++++++++++++++++++++ challenge-248/jaldhar-h-vyas/perl/ch-2.pl | 20 ++++++++++++++++++++ challenge-248/jaldhar-h-vyas/raku/ch-1.raku | 13 +++++++++++++ challenge-248/jaldhar-h-vyas/raku/ch-2.raku | 21 +++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 challenge-248/jaldhar-h-vyas/blog.txt create mode 100755 challenge-248/jaldhar-h-vyas/perl/ch-1.pl create mode 100755 challenge-248/jaldhar-h-vyas/perl/ch-2.pl create mode 100755 challenge-248/jaldhar-h-vyas/raku/ch-1.raku create mode 100755 challenge-248/jaldhar-h-vyas/raku/ch-2.raku diff --git a/challenge-248/jaldhar-h-vyas/blog.txt b/challenge-248/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..74b9281e31 --- /dev/null +++ b/challenge-248/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2024/01/perl_weekly_challenge_week_248.html diff --git a/challenge-248/jaldhar-h-vyas/perl/ch-1.pl b/challenge-248/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..592d96cfca --- /dev/null +++ b/challenge-248/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub min { + my @arr = @_; + my $lowest = 'inf'; + for my $i (@arr) { + if ($i < $lowest) { + $lowest = $i; + } + } + + return $lowest; +} + +my ($letter, $str) = @ARGV; + +my @chars = split //, $str; +my @j = grep { $chars[$_] eq $letter } keys @chars; +say q{(}, + (join q{,}, map { my $i = $_; min(map { abs($i - $_) } @j); } keys @chars), + q{)}; diff --git a/challenge-248/jaldhar-h-vyas/perl/ch-2.pl b/challenge-248/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..65ef6b3fc7 --- /dev/null +++ b/challenge-248/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +my @a = map { [ map { 0 + $_} split /\s+/ ] } @ARGV; +my @b; + +for my $row (0 .. scalar @a - 2) { + my @c; + for my $col (0 .. scalar @{$a[$row]} - 2) { + my $sum = $a[$row][$col] + $a[$row][$col + 1] + + $a[$row + 1][$col] + $a[$row + 1][$col + 1]; + push @c, $sum; + } + push @b,\@c; +} + +say "[\n", + (join ",\n", (map { join q{}, (q{ [ }, (join(q{, }, @{$_})), " ]") } @b)), + "\n]\n"; diff --git a/challenge-248/jaldhar-h-vyas/raku/ch-1.raku b/challenge-248/jaldhar-h-vyas/raku/ch-1.raku new file mode 100755 index 0000000000..4f5ae7f5f3 --- /dev/null +++ b/challenge-248/jaldhar-h-vyas/raku/ch-1.raku @@ -0,0 +1,13 @@ +#!/usr/bin/raku + +sub MAIN( + $letter, + $str +) { + my @chars = $str.comb; + my @j = @chars.keys.grep({ @chars[$_] eq $letter }); + say q{(}, + @chars.keys.map({ my $i = $_; @j.map({ abs($i - $_) }).min; }) + .join(q{,}), + q{)}; +} \ No newline at end of file diff --git a/challenge-248/jaldhar-h-vyas/raku/ch-2.raku b/challenge-248/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..cd9a5dc66f --- /dev/null +++ b/challenge-248/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,21 @@ +#!/usr/bin/raku + +sub MAIN( + *@args +) { + my @a = @args.map({ [ $_.words.map({ .Int }) ] }); + my @b; + + for 0 .. @a.elems - 2 -> $row { + my @c; + for 0 .. @a[$row].elems - 2 -> $col { + @c.push( [+] (@a[$row;$col], @a[$row;$col + 1], + @a[$row + 1; $col], @a[$row + 1; $col + 1]) ); + } + @b.push(@c); + } + + say "[\n", + @b.map({ (q{ [ }, @$_.join(q{, }), " ]").join }).join(",\n"), + "\n]\n"; +} \ No newline at end of file -- cgit From 7611c9ff2548d917e5093505ef514b351ec82b64 Mon Sep 17 00:00:00 2001 From: "Jaldhar H. Vyas" Date: Fri, 5 Jan 2024 17:32:06 -0500 Subject: Challenge 249 by Jaldhar H. Vyas. --- challenge-249/jaldhar-h-vyas/blog.txt | 1 + challenge-249/jaldhar-h-vyas/perl/ch-1.pl | 24 ++++++++++++++++++++++++ challenge-249/jaldhar-h-vyas/perl/ch-2.pl | 21 +++++++++++++++++++++ challenge-249/jaldhar-h-vyas/raku/ch-1.raku | 16 ++++++++++++++++ challenge-249/jaldhar-h-vyas/raku/ch-2.raku | 21 +++++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 challenge-249/jaldhar-h-vyas/blog.txt create mode 100755 challenge-249/jaldhar-h-vyas/perl/ch-1.pl create mode 100755 challenge-249/jaldhar-h-vyas/perl/ch-2.pl create mode 100755 challenge-249/jaldhar-h-vyas/raku/ch-1.raku create mode 100755 challenge-249/jaldhar-h-vyas/raku/ch-2.raku diff --git a/challenge-249/jaldhar-h-vyas/blog.txt b/challenge-249/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..76808547d1 --- /dev/null +++ b/challenge-249/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2024/01/perl_weekly_challenge_week_249.html diff --git a/challenge-249/jaldhar-h-vyas/perl/ch-1.pl b/challenge-249/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..045cacbe10 --- /dev/null +++ b/challenge-249/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +my @ints = @ARGV; + +my %elements; +for my $int (@ints) { + $elements{$int}++; +} + +my @output; +for my $k (keys %elements) { + if (scalar $elements{$k} % 2 == 1) { + say '()'; + exit; + } + + for (0 .. $elements{$k} / 2 - 1) { + push @output, [ $k, $k ]; + } +} + +say join q{, }, map { q{(} . (join q{, }, @{$_} ) . q{)} } @output; diff --git a/challenge-249/jaldhar-h-vyas/perl/ch-2.pl b/challenge-249/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..843e839e0d --- /dev/null +++ b/challenge-249/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +my $str = shift; + +my @chars = split //, $str; +my @numbers = 0 .. length $str; +my @s; + +for my $c (@chars) { + if ($c eq 'D') { + push @s, pop @numbers; + } + if ($c eq 'I') { + push @s, shift @numbers; + } +} +push @s, shift @numbers; + +say q{(}, (join q{, }, @s), q{)}; diff --git a/challenge-249/jaldhar-h-vyas/raku/ch-1.raku b/challenge-249/jaldhar-h-vyas/raku/ch-1.raku new file mode 100755 index 0000000000..00c7074a99 --- /dev/null +++ b/challenge-249/jaldhar-h-vyas/raku/ch-1.raku @@ -0,0 +1,16 @@ +#!/usr/bin/raku + +sub MAIN( + *@ints +) { + @ints.classify({ $_ }, :into(my %elements;) ); + if all %elements.values.map({ @$_.elems % 2 == 0 }) { + %elements.values + .map({| @$_.batch(2) }) + .map({ q{(} ~ @$_.join(q{, }) ~ q{)} }) + .join(q{, }) + .say; + } else { + say '()'; + } +} diff --git a/challenge-249/jaldhar-h-vyas/raku/ch-2.raku b/challenge-249/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..dad4f8fcaf --- /dev/null +++ b/challenge-249/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,21 @@ +#!/usr/bin/raku + +sub MAIN( + Str $str +) { + my @chars = $str.comb; + my @numbers = 0 .. $str.chars; + my @s; + + for @chars -> $c { + if $c eq 'D' { + @s.push(@numbers.pop); + } + if $c eq 'I' { + @s.push(@numbers.shift); + } + } + @s.push(@numbers.shift); + + say q{(}, @s.join(q{, }), q{)}; +} -- cgit From 959647373fe8b2e4626d37ea01ef68e470c8e9f9 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 29 Jan 2024 09:46:22 +0100 Subject: Add solutions to 254: Three Power & Reverse Vowels by E. Choroba --- challenge-254/e-choroba/perl/ch-1.pl | 20 ++++++++++++++++++++ challenge-254/e-choroba/perl/ch-2.pl | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 challenge-254/e-choroba/perl/ch-1.pl create mode 100755 challenge-254/e-choroba/perl/ch-2.pl diff --git a/challenge-254/e-choroba/perl/ch-1.pl b/challenge-254/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..0920ddf653 --- /dev/null +++ b/challenge-254/e-choroba/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub three_power($n) { + for (1, 2) { + return if $n % 3; + $n /= 3; + } + return 1 +} + +use Test::More tests => 3 + 2; + +ok three_power(27), 'Example 1'; +ok three_power(0), 'Example 2'; +ok ! three_power(6), 'Example 3'; +ok three_power(18446703239944862784), 'Large true'; +ok ! three_power(18446744073709551615), 'Large false'; diff --git a/challenge-254/e-choroba/perl/ch-2.pl b/challenge-254/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..11c56a1804 --- /dev/null +++ b/challenge-254/e-choroba/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub reverse_vowels($s) { + my @vowels = $s =~ /[aeiou]/gi; + $s =~ s{([aeiou])}{ + my $v = pop @vowels; + $1 ge 'a' ? lc $v : uc $v + }ige; + return $s +} + +use Test::More tests => 4; + +is reverse_vowels('Raku'), 'Ruka', 'Example 1'; +is reverse_vowels('Perl'), 'Perl', 'Example 2'; +is reverse_vowels('Julia'), 'Jaliu', 'Example 3'; +is reverse_vowels('Uiua'), 'Auiu', 'Example 4'; -- cgit From 57558851871adbaf762e1ef132f0d27e220e5a57 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 29 Jan 2024 10:04:57 +0000 Subject: w254 - Task 1 & 2 --- challenge-254/perlboy1967/perl/ch1.pl | 36 +++++++++++++++++++++++++++++++++++ challenge-254/perlboy1967/perl/ch2.pl | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 challenge-254/perlboy1967/perl/ch1.pl create mode 100755 challenge-254/perlboy1967/perl/ch2.pl diff --git a/challenge-254/perlboy1967/perl/ch1.pl b/challenge-254/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..68c055158f --- /dev/null +++ b/challenge-254/perlboy1967/perl/ch1.pl @@ -0,0 +1,36 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 254 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-254 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Three Power +Submitted by: Mohammad S Anwar + +You are given a positive integer, $n. + +Write a script to return true if the given integer is a power of three otherwise return false. + +=cut + +use v5.32; +use feature qw(signatures); +use common::sense; + +use Test2::V0; + +sub isPowerN ($n,$base) { + return 1 if $n == 0; + my $r = $n ** (1/$base); + $r =~ m#^\d+$# ? 1 : 0; +} + + +is(isPowerN($_,3),1,"isPowerN($_,3) == 1") for (0,1,8,27,64); +is(isPowerN($_,3),0,"isPowerN($_,3) == 0") for (2,7,9,26,28,63,65); +is(isPowerN($_,5),1,"isPowerN($_,5) == 1") for (1,32,243); + +done_testing; diff --git a/challenge-254/perlboy1967/perl/ch2.pl b/challenge-254/perlboy1967/perl/ch2.pl new file mode 100755 index 0000000000..b0e4391327 --- /dev/null +++ b/challenge-254/perlboy1967/perl/ch2.pl @@ -0,0 +1,36 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 254 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-254 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Reverse Vowels +Submitted by: Mohammad S Anwar + +You are given a string, $s. + +Write a script to reverse all the vowels (a, e, i, o, u) in the given string. + +=cut + +use v5.32; +use feature qw(signatures); +use common::sense; + +use Test2::V0; + +sub reverseVowels ($str) { + my @v = reverse $str =~ m/(?i)[aeiou]/g; + ucfirst lc $str =~ s/(?i)[aeiou]/shift @v/egr; +} + + +is(reverseVowels('Raku'),'Ruka'); +is(reverseVowels('Perl'),'Perl'); +is(reverseVowels('Julia'),'Jaliu'); +is(reverseVowels('Uiua'),'Auiu'); + +done_testing; -- cgit From 7c3628d24263d828b990af5eeac286e3ab7819af Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 29 Jan 2024 09:55:32 +0100 Subject: PWC 254 Task 1 Raku done Task 2 Raku done Task 1 PL/Perl done Task 2 PL/Perl done Task 1 PL/PgSQL done Task 2 PL/PgSQL done Task 1 Python done Task 2 Python done Task 1 PL/Java done Task2 PL/java done --- challenge-252/luca-ferrari/java/ch-1.java | 15 ++++ challenge-252/luca-ferrari/postgresql/java/pom.xml | 84 ++++++++++++++++++++++ .../java/src/main/java/PWC252/Task1.java | 11 +++ challenge-253/luca-ferrari/pljava/ch-1.java | 40 +++++++++++ challenge-253/luca-ferrari/pljava/ch-2.java | 28 ++++++++ challenge-254/luca-ferrari/blog-1.txt | 1 + challenge-254/luca-ferrari/blog-10.txt | 1 + challenge-254/luca-ferrari/blog-2.txt | 1 + challenge-254/luca-ferrari/blog-3.txt | 1 + challenge-254/luca-ferrari/blog-4.txt | 1 + challenge-254/luca-ferrari/blog-5.txt | 1 + challenge-254/luca-ferrari/blog-6.txt | 1 + challenge-254/luca-ferrari/blog-7.txt | 1 + challenge-254/luca-ferrari/blog-8.txt | 1 + challenge-254/luca-ferrari/blog-9.txt | 1 + challenge-254/luca-ferrari/pljava/pom.xml | 6 +- .../luca-ferrari/pljava/src/main/java/Task1.java | 50 +++++++++++++ .../luca-ferrari/pljava/src/main/java/Task2.java | 69 ++++++++++++++++++ challenge-254/luca-ferrari/plperl/ch-1.plperl | 23 ++++++ challenge-254/luca-ferrari/plperl/ch-2.plperl | 27 +++++++ challenge-254/luca-ferrari/plpgsql/ch-1.sql | 24 +++++++ challenge-254/luca-ferrari/plpgsql/ch-2.sql | 50 +++++++++++++ challenge-254/luca-ferrari/python/ch-1.python | 26 +++++++ challenge-254/luca-ferrari/python/ch-2.python | 29 ++++++++ challenge-254/luca-ferrari/raku/ch-1.raku | 17 +++++ challenge-254/luca-ferrari/raku/ch-2.raku | 21 ++++++ 26 files changed, 527 insertions(+), 3 deletions(-) create mode 100644 challenge-252/luca-ferrari/java/ch-1.java create mode 100644 challenge-252/luca-ferrari/postgresql/java/pom.xml create mode 100644 challenge-252/luca-ferrari/postgresql/java/src/main/java/PWC252/Task1.java create mode 100644 challenge-253/luca-ferrari/pljava/ch-1.java create mode 100644 challenge-253/luca-ferrari/pljava/ch-2.java create mode 100644 challenge-254/luca-ferrari/blog-1.txt create mode 100644 challenge-254/luca-ferrari/blog-10.txt create mode 100644 challenge-254/luca-ferrari/blog-2.txt create mode 100644 challenge-254/luca-ferrari/blog-3.txt create mode 100644 challenge-254/luca-ferrari/blog-4.txt create mode 100644 challenge-254/luca-ferrari/blog-5.txt create mode 100644 challenge-254/luca-ferrari/blog-6.txt create mode 100644 challenge-254/luca-ferrari/blog-7.txt create mode 100644 challenge-254/luca-ferrari/blog-8.txt create mode 100644 challenge-254/luca-ferrari/blog-9.txt create mode 100644 challenge-254/luca-ferrari/pljava/src/main/java/Task1.java create mode 100644 challenge-254/luca-ferrari/pljava/src/main/java/Task2.java create mode 100644 challenge-254/luca-ferrari/plperl/ch-1.plperl create mode 100644 challenge-254/luca-ferrari/plperl/ch-2.plperl create mode 100644 challenge-254/luca-ferrari/plpgsql/ch-1.sql create mode 100644 challenge-254/luca-ferrari/plpgsql/ch-2.sql create mode 100644 challenge-254/luca-ferrari/python/ch-1.python create mode 100644 challenge-254/luca-ferrari/python/ch-2.python create mode 100644 challenge-254/luca-ferrari/raku/ch-1.raku create mode 100644 challenge-254/luca-ferrari/raku/ch-2.raku diff --git a/challenge-252/luca-ferrari/java/ch-1.java b/challenge-252/luca-ferrari/java/ch-1.java new file mode 100644 index 0000000000..18ba5f7aa1 --- /dev/null +++ b/challenge-252/luca-ferrari/java/ch-1.java @@ -0,0 +1,15 @@ +package PWC252; + +public class ch_1 { + public static void main( String argv[] ) { + int sum = 0; + for ( int i = 0; i < argv.length; i++ ) { + if ( agrv.length % i != 0 ) + continue; + + sum += Integer.parseInt( argv[ i ] ) ^ 2; + } + + System.out.println( sum ); + } +} diff --git a/challenge-252/luca-ferrari/postgresql/java/pom.xml b/challenge-252/luca-ferrari/postgresql/java/pom.xml new file mode 100644 index 0000000000..8975c014a2 --- /dev/null +++ b/challenge-252/luca-ferrari/postgresql/java/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + + + + pwc + pwc252 + 0.0.1-SNAPSHOT + + + + Perl Weekly Challenge 252 + Implementation of the tasks in PL/Java + + + + + US-ASCII + + + + + + + org.postgresql + pljava-api + 1.6.6 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 9 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + + + + + true + + + + + + + pljava.ddr + + + true + + + + + + + + + + diff --git a/challenge-252/luca-ferrari/postgresql/java/src/main/java/PWC252/Task1.java b/challenge-252/luca-ferrari/postgresql/java/src/main/java/PWC252/Task1.java new file mode 100644 index 0000000000..4714df0ad5 --- /dev/null +++ b/challenge-252/luca-ferrari/postgresql/java/src/main/java/PWC252/Task1.java @@ -0,0 +1,11 @@ +package PWC252; + +import org.postgresql.pljava.annotation.Function; + +public class Task1 { + + @Function + public static final int task1( int[] nums ) { + return 0; + } +} diff --git a/challenge-253/luca-ferrari/pljava/ch-1.java b/challenge-253/luca-ferrari/pljava/ch-1.java new file mode 100644 index 0000000000..51a2428a5b --- /dev/null +++ b/challenge-253/luca-ferrari/pljava/ch-1.java @@ -0,0 +1,40 @@ +//package PWC253; + +/** + * PL/Java implementation for PWC 253 + * Task 1 + * See + * + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC253.1.jar', 'PWC253', true ); + select sqlj.set_classpath( 'public', 'PWC253' ); + + select task$tn_pljava(); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; + +public class Task1 { + + @Function( onNullInput = RETURNS_NULL, effects = IMMUTABLE ) + public static final String[] task1_pljava( String separator, String[] words ) { + List result = new LinkedList(); + + for ( String w : words ) { + if ( ! w.contains( separator ) ) + result.add( w ); + else + result.addAll( w.split( separator ) ); + } + + return result; + + } +} diff --git a/challenge-253/luca-ferrari/pljava/ch-2.java b/challenge-253/luca-ferrari/pljava/ch-2.java new file mode 100644 index 0000000000..4a664fb345 --- /dev/null +++ b/challenge-253/luca-ferrari/pljava/ch-2.java @@ -0,0 +1,28 @@ +package PWC253; + +/** + * PL/Java implementation for PWC 253 + * Task 2 + * See + * + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC253.1.jar', 'PWC253', true ); + select sqlj.set_classpath( 'public', 'PWC253' ); + + select task$tn_pljava(); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +public class Task2 { + + @Function( onNullInput = RETURNS_NULL, effects = IMMUTABLE ) + public static final void task2_pljava() throws Exception { + throws Exception( "Not Implemented" ); + } +} diff --git a/challenge-254/luca-ferrari/blog-1.txt b/challenge-254/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..3014ec9e95 --- /dev/null +++ b/challenge-254/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task1 diff --git a/challenge-254/luca-ferrari/blog-10.txt b/challenge-254/luca-ferrari/blog-10.txt new file mode 100644 index 0000000000..7fcf1cea31 --- /dev/null +++ b/challenge-254/luca-ferrari/blog-10.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/[= date -%]/PerlWeeklyChallenge254.html#task2pljava diff --git a/challenge-254/luca-ferrari/blog-2.txt b/challenge-254/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..b678fbc47d --- /dev/null +++ b/challenge-254/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task2 diff --git a/challenge-254/luca-ferrari/blog-3.txt b/challenge-254/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..e21ffb6783 --- /dev/null +++ b/challenge-254/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task1plperl diff --git a/challenge-254/luca-ferrari/blog-4.txt b/challenge-254/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..423c6c15a3 --- /dev/null +++ b/challenge-254/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task2plperl diff --git a/challenge-254/luca-ferrari/blog-5.txt b/challenge-254/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..d16e156f35 --- /dev/null +++ b/challenge-254/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task1plpgsql diff --git a/challenge-254/luca-ferrari/blog-6.txt b/challenge-254/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..83e86f8b34 --- /dev/null +++ b/challenge-254/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task2plpgsql diff --git a/challenge-254/luca-ferrari/blog-7.txt b/challenge-254/luca-ferrari/blog-7.txt new file mode 100644 index 0000000000..84b7463fba --- /dev/null +++ b/challenge-254/luca-ferrari/blog-7.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task1python diff --git a/challenge-254/luca-ferrari/blog-8.txt b/challenge-254/luca-ferrari/blog-8.txt new file mode 100644 index 0000000000..f7d14503d6 --- /dev/null +++ b/challenge-254/luca-ferrari/blog-8.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task2python diff --git a/challenge-254/luca-ferrari/blog-9.txt b/challenge-254/luca-ferrari/blog-9.txt new file mode 100644 index 0000000000..aa57bfbb2b --- /dev/null +++ b/challenge-254/luca-ferrari/blog-9.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/29/PerlWeeklyChallenge254.html#task1pljava diff --git a/challenge-254/luca-ferrari/pljava/pom.xml b/challenge-254/luca-ferrari/pljava/pom.xml index d9047c527c..8777b204e3 100644 --- a/challenge-254/luca-ferrari/pljava/pom.xml +++ b/challenge-254/luca-ferrari/pljava/pom.xml @@ -5,11 +5,11 @@ 4.0.0 PWC - PWC253 + PWC254 1 - Perl Weekly Challenge 253 - Implementation of the tasks in PL/Java for PWC 253 + Perl Weekly Challenge 254 + Implementation of the tasks in PL/Java for PWC 254 US-ASCII diff --git a/challenge-254/luca-ferrari/pljava/src/main/java/Task1.java b/challenge-254/luca-ferrari/pljava/src/main/java/Task1.java new file mode 100644 index 0000000000..643a13cbab --- /dev/null +++ b/challenge-254/luca-ferrari/pljava/src/main/java/Task1.java @@ -0,0 +1,50 @@ +package PWC254; + +/** + * PL/Java implementation for PWC 254 + * Task 1 + * See + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ $ scp target/PWC253-1.jar luca@venkman:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC254-1.jar', 'PWC254', true ); + select sqlj.set_classpath( 'public', 'PWC254' ); + + select task1_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC254-1.jar', 'PWC254', true ); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; +import java.sql.SQLException; +import java.util.logging.*; + +public class Task1 { + + private final static Logger logger = Logger.getAnonymousLogger(); + + @Function( onNullInput = RETURNS_NULL, effects = IMMUTABLE ) + public static final boolean task1_pljava( int num ) throws SQLException { + for ( int i = 2; i < Math.sqrt( num ); i++ ) + if ( Math.pow( i, 3 ) == num ) + return true; + + return false; + } +} diff --git a/challenge-254/luca-ferrari/pljava/src/main/java/Task2.java b/challenge-254/luca-ferrari/pljava/src/main/java/Task2.java new file mode 100644 index 0000000000..034943bebc --- /dev/null +++ b/challenge-254/luca-ferrari/pljava/src/main/java/Task2.java @@ -0,0 +1,69 @@ +package PWC254; + +/** + * PL/Java implementation for PWC 254 + * Task 1 + * See + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ $ scp target/PWC253-1.jar luca@venkman:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC254-1.jar', 'PWC254', true ); + select sqlj.set_classpath( 'public', 'PWC254' ); + + select task1_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC254-1.jar', 'PWC254', true ); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; +import java.sql.SQLException; +import java.util.logging.*; + +public class Task2 { + private final static Logger logger = Logger.getAnonymousLogger(); + + @Function( onNullInput = RETURNS_NULL, effects = IMMUTABLE ) + public static final String task2_pljava( String word ) throws SQLException { + String result = ""; + Stack vowels = new Stack(); + + for ( String letter : word.split( "" ) ) { + if ( isVowel( letter ) ) + vowels.push( letter ); + } + + for ( String letter : word.split( "" ) ) { + if ( ! isVowel( letter ) || vowels.empty() ) + result += letter; + else + result += vowels.pop(); + } + + return result; + } + + + public static final boolean isVowel( String letter ) { + return letter.toLowerCase().equals( "a" ) + || letter.toLowerCase().equals( "e" ) + || letter.toLowerCase().equals( "i" ) + || letter.toLowerCase().equals( "o" ) + || letter.toLowerCase().equals( "u" ); + } +} diff --git a/challenge-254/luca-ferrari/plperl/ch-1.plperl b/challenge-254/luca-ferrari/plperl/ch-1.plperl new file mode 100644 index 0000000000..6b1db77580 --- /dev/null +++ b/challenge-254/luca-ferrari/plperl/ch-1.plperl @@ -0,0 +1,23 @@ +-- +-- Perl Weekly Challenge 254 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc254; + +CREATE OR REPLACE FUNCTION +pwc254.task1_plperl( int ) +RETURNS bool +AS $CODE$ + + my ( $num ) = @_; + + for ( 2 .. ( $num / 2 ) ) { + return 1 if ( $_ ** 3 == $num ); + } + + return 0; + +$CODE$ +LANGUAGE plperl; diff --git a/challenge-254/luca-ferrari/plperl/ch-2.plperl b/challenge-254/luca-ferrari/plperl/ch-2.plperl new file mode 100644 index 0000000000..9deb0bdab1 --- /dev/null +++ b/challenge-254/luca-ferrari/plperl/ch-2.plperl @@ -0,0 +1,27 @@ +-- +-- Perl Weekly Challenge 254 +-- Task 2 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc254; + +CREATE OR REPLACE FUNCTION +pwc254.task2_plperl( text ) +RETURNS text +AS $CODE$ + + my ( $word ) = @_; + + my @vowels = reverse grep { $_ =~ / [aeiou] /ix } split( //, $word ); + my $output = ''; + + for ( split //, $word ) { + $output .= $_ and next if ( $_ !~ / [aeiou] /ix || ! @vowels ); + $output .= shift( @vowels ) and next; + } + + return $output; + +$CODE$ +LANGUAGE plperl; diff --git a/challenge-254/luca-ferrari/plpgsql/ch-1.sql b/challenge-254/luca-ferrari/plpgsql/ch-1.sql new file mode 100644 index 0000000000..e52a58df16 --- /dev/null +++ b/challenge-254/luca-ferrari/plpgsql/ch-1.sql @@ -0,0 +1,24 @@ +-- +-- Perl Weekly Challenge 254 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc254; + +CREATE OR REPLACE FUNCTION +pwc254.task1_plpgsql( n int ) +RETURNS bool +AS $CODE$ +BEGIN + FOR i IN 2 .. sqrt( n )::int LOOP + IF pow( i, 3 ) = n THEN + RETURN TRUE; + END IF; + END LOOP; + + RETURN FALSE; + +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-254/luca-ferrari/plpgsql/ch-2.sql b/challenge-254/luca-ferrari/plpgsql/ch-2.sql new file mode 100644 index 0000000000..78cb4eb8eb --- /dev/null +++ b/challenge-254/luca-ferrari/plpgsql/ch-2.sql @@ -0,0 +1,50 @@ +-- +-- Perl Weekly Challenge 254 +-- Task 2 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc254; + +CREATE OR REPLACE FUNCTION +pwc254.task2_plpgsql( word text ) +RETURNS text +AS $CODE$ +DECLARE + output_string text := ''; + current_vowel char; + current_index int; + remaining_vowels int; + letter char; +BEGIN + CREATE TEMPORARY TABLE IF NOT EXISTS vowels( v char, i serial ); + TRUNCATE vowels; + + INSERT INTO vowels( v ) + SELECT v + FROM regexp_split_to_table( lower( word ), '' ) v + WHERE v IN ( 'a', 'e', 'i', 'o', 'u' ); + + FOR letter IN SELECT v FROM regexp_split_to_table( lower( word ), '' ) v LOOP + + SELECT count( * ) + FROM vowels + INTO remaining_vowels; + + IF letter NOT IN ('a', 'e', 'i', 'o', 'u' ) OR remaining_vowels = 0 THEN + output_string := output_string || letter; + ELSE + SELECT v, i + INTO current_vowel, current_index + FROM vowels + ORDER BY i DESC; + + output_string := output_string || current_vowel; + DELETE FROM vowels WHERE i = current_index; + END IF; + END LOOP; + + RETURN output_string; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-254/luca-ferrari/python/ch-1.python b/challenge-254/luca-ferrari/python/ch-1.python new file mode 100644 index 0000000000..a0533551d8 --- /dev/null +++ b/challenge-254/luca-ferrari/python/ch-1.python @@ -0,0 +1,26 @@ +#!python + +# +# Perl Weekly Challenge 254 +# Task 1 +# +# See +# + +import sys +import math + +# task implementation +# the return value will be printed +def task_1( args ): + num = int( args[ 0 ] ) + for i in range( 2, int( math.sqrt( num ) ) ): + if ( i ** 3 ) == num: + return True + + return False + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) diff --git a/challenge-254/luca-ferrari/python/ch-2.python b/challenge-254/luca-ferrari/python/ch-2.python new file mode 100644 index 0000000000..dc37e2ad93 --- /dev/null +++ b/challenge-254/luca-ferrari/python/ch-2.python @@ -0,0 +1,29 @@ +#!python + +# +# Perl Weekly Challenge 254 +# Task 2 +# +# See +# + +import sys + +# task implementation +# the return value will be printed +def task_2( args ): + word = args[ 0 ].lower() + vowels = list( reversed( list( filter( lambda x: x in ('a','e','i','o','u'), word ) ) ) ) + output = '' + for letter in word: + if letter not in ( 'a', 'e', 'i', 'o', 'u' ) or len( vowels ) == 0 + output += letter + else: + output += vowels.pop( 0 ) + + return output + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_2( sys.argv[ 1: ] ) ) diff --git a/challenge-254/luca-ferrari/raku/ch-1.raku b/challenge-254/luca-ferrari/raku/ch-1.raku new file mode 100644 index 0000000000..48656b5e81 --- /dev/null +++ b/challenge-254/luca-ferrari/raku/ch-1.raku @@ -0,0 +1,17 @@ +#!raku + +# +# Perl Weekly Challenge 254 +# Task 1 +# +# See +# + +sub MAIN( Int $n ) { + # say ( $n ** ( 1 / 3 ) ).Int == ( $n ** ( 1 / 3 ) ); + for ( 2 ..^ $n.sqrt.Int ) { + 'true'.say and exit if ( $_ ** 3 == $n ); + } + + 'false'.say; +} diff --git a/challenge-254/luca-ferrari/raku/ch-2.raku b/challenge-254/luca-ferrari/raku/ch-2.raku new file mode 100644 index 0000000000..c72766df6f --- /dev/null +++ b/challenge-254/luca-ferrari/raku/ch-2.raku @@ -0,0 +1,21 @@ +#!raku + +# +# Perl Weekly Challenge 254 +# Task 2 +# +# See +# + +sub MAIN( Str $word ) { + my @reversed; + my @vowels.push: |$word.lc.comb.grep( * ~~ / <[aeiou]> / ).reverse; + + for $word.comb { + + @reversed.push( $_ ) and next if ( $_.lc !~~ / <[aeiou]> / || @vowels.elems == 0 ); + @reversed.push: @vowels.shift if ( @vowels.elems > 0 ); + } + + @reversed.join.say; +} -- cgit From 9f5a6b4518271be9a6eafc81ea341add51686490 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Mon, 29 Jan 2024 10:15:33 +0000 Subject: Task 2 - Don't need reverse(), just pop() --- challenge-254/perlboy1967/perl/ch2.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-254/perlboy1967/perl/ch2.pl b/challenge-254/perlboy1967/perl/ch2.pl index b0e4391327..2af8efbfb6 100755 --- a/challenge-254/perlboy1967/perl/ch2.pl +++ b/challenge-254/perlboy1967/perl/ch2.pl @@ -23,8 +23,8 @@ use common::sense; use Test2::V0; sub reverseVowels ($str) { - my @v = reverse $str =~ m/(?i)[aeiou]/g; - ucfirst lc $str =~ s/(?i)[aeiou]/shift @v/egr; + my @v = $str =~ m/(?i)[aeiou]/g; + ucfirst lc $str =~ s/(?i)[aeiou]/pop @v/egr; } -- cgit From 9d084b8b424f33a6fcc4d6fc56958a35f510c159 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:22:37 +0000 Subject: Challenge 254 Solutions (Raku) --- challenge-254/mark-anderson/raku/ch-1.raku | 26 ++++++++++++++++++++++++++ challenge-254/mark-anderson/raku/ch-2.raku | 16 ++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 challenge-254/mark-anderson/raku/ch-1.raku create mode 100644 challenge-254/mark-anderson/raku/ch-2.raku diff --git a/challenge-254/mark-anderson/raku/ch-1.raku b/challenge-254/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..95125ba617 --- /dev/null +++ b/challenge-254/mark-anderson/raku/ch-1.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku +use Test; + +# https://oeis.org/A000578/b000578.txt + +ok three-power(27); +ok three-power(0); +nok three-power(6); +nok three-power(999400119991); +ok three-power(999400119992); +nok three-power(999400119993); +is-deeply (^Inf).hyper(batch => 4096).grep(&three-power).skip(100).head(10), (1000000, + 1030301, + 1061208, + 1092727, + 1124864, + 1157625, + 1191016, + 1225043, + 1259712, + 1295029); + +sub three-power($n) +{ + $n == exp(3, exp(1/3, $n).ceiling) +} diff --git a/challenge-254/mark-anderson/raku/ch-2.raku b/challenge-254/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..2180e0ebf9 --- /dev/null +++ b/challenge-254/mark-anderson/raku/ch-2.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku +use Test; + +is reverse-vowels("Raku"), "Ruka"; +is reverse-vowels("Perl"), "Perl"; +is reverse-vowels("Julia"), "Jaliu"; +is reverse-vowels("Uiua"), "Auiu"; +is reverse-vowels("Supercalifragilisticexpialidocious"), "Suporcilofrigalistecixpiiladicaeus"; + +sub reverse-vowels($w) +{ + my @a = $w.comb; + my @i = @a.grep(/:i<[aeiou]>/, :k); + @a[@i] .= reverse; + tclc [~] @a +} -- cgit From 343367e8c6cfee34c9653bae91434dc234ee6785 Mon Sep 17 00:00:00 2001 From: Stephen Lynn Date: Mon, 29 Jan 2024 21:38:54 +0800 Subject: pwc 254 --- challenge-254/steve-g-lynn/blog.txt | 1 + challenge-254/steve-g-lynn/perl/ch-1.pl | 10 ++++++++++ challenge-254/steve-g-lynn/perl/ch-2.pl | 26 ++++++++++++++++++++++++++ challenge-254/steve-g-lynn/python/ch-1.py | 11 +++++++++++ challenge-254/steve-g-lynn/python/ch-2.py | 25 +++++++++++++++++++++++++ 5 files changed, 73 insertions(+) create mode 100644 challenge-254/steve-g-lynn/blog.txt create mode 100644 challenge-254/steve-g-lynn/perl/ch-1.pl create mode 100644 challenge-254/steve-g-lynn/perl/ch-2.pl create mode 100644 challenge-254/steve-g-lynn/python/ch-1.py create mode 100644 challenge-254/steve-g-lynn/python/ch-2.py diff --git a/challenge-254/steve-g-lynn/blog.txt b/challenge-254/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..c8fec55ec1 --- /dev/null +++ b/challenge-254/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2024/01/pwc-254.html diff --git a/challenge-254/steve-g-lynn/perl/ch-1.pl b/challenge-254/steve-g-lynn/perl/ch-1.pl new file mode 100644 index 0000000000..4c0ef9fbcf --- /dev/null +++ b/challenge-254/steve-g-lynn/perl/ch-1.pl @@ -0,0 +1,10 @@ +# Perl 4.019 on DOSBOX + +sub three_power { + local( $n )=@_; + $n=($n**(1/3)); + $n==sprintf("%d",$n); +} +print &three_power(27),"\n"; #1 +print &three_power(0),"\n"; #1 +print &three_power(6),"\n"; #0 diff --git a/challenge-254/steve-g-lynn/perl/ch-2.pl b/challenge-254/steve-g-lynn/perl/ch-2.pl new file mode 100644 index 0000000000..3c0723375d --- /dev/null +++ b/challenge-254/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,26 @@ +#perl 4.019 on DOSBOX + +sub reverse_vowels { + local(@s)=split(//,$_[0]); + local(@reverse_vowels)=grep($s[$_] =~ /[aeiouAEIOU]/, 0..$#s); + @s[@reverse_vowels]=@s[reverse(@reverse_vowels)]; + &ucfirst(&lc(join('',@s))); +} + +sub lc { + local($lc)=$_[0]; + $lc =~ tr/A-Z/a-z/; + $lc; +} + +sub ucfirst { + local($ucfirst)=$_[0]; + substr($ucfirst,0,1) =~ tr/a-z/A-Z/; + $ucfirst; +} + + +print &reverse_vowels('Raku'),"\n"; #Ruka +print &reverse_vowels('Perl'),"\n"; #Perl +print &reverse_vowels('Julia'),"\n"; #Jaliu +print &reverse_vowels('Uiua'),"\n"; #Auiu diff --git a/challenge-254/steve-g-lynn/python/ch-1.py b/challenge-254/steve-g-lynn/python/ch-1.py new file mode 100644 index 0000000000..8a72a0be0f --- /dev/null +++ b/challenge-254/steve-g-lynn/python/ch-1.py @@ -0,0 +1,11 @@ + +# Python 1.4 beta on DOSBOX + +def three_power(n): + n=n**(1.0/3.0) + return (n==int(n)) + +print three_power(27) #1 +print three_power(0) #1 +print three_power(6) #0 + diff --git a/challenge-254/steve-g-lynn/python/ch-2.py b/challenge-254/steve-g-lynn/python/ch-2.py new file mode 100644 index 0000000000..6aabcf097a --- /dev/null +++ b/challenge-254/steve-g-lynn/python/ch-2.py @@ -0,0 +1,25 @@ +# python 1.4 beta on DOSBOX +# does not run in python 2.7.18 + +import regex,regsub,string +vowels=regex.compile("[aeiouAEIOU]") + +def reverse_vowels(mystr): + vind=[] #store indices of vowel elements of mystr + str2arr=[] #store elements of mystr + for i in range(len(mystr)): + str2arr.append(mystr[i]) + if ( vowels.match( mystr[i] ) > -1 ): + vind.append(i) + vindr=vind[:] + vindr.reverse() + + for i in range(len(vind)): + str2arr[vind[i]]=mystr[vindr[i]] + retval=regsub.gsub(" ","", string.join(str2arr)) + return string.capitalize(string.lower(retval)) + +print reverse_vowels("Raku") #Ruka +print reverse_vowels("Perl") #Perl +print reverse_vowels("Julia") #Jaliu +print reverse_vowels("Uiua") #Auiu -- cgit From 3d4e9f00856f735ad7d7710b01ce7329dabd4218 Mon Sep 17 00:00:00 2001 From: pme Date: Mon, 29 Jan 2024 15:22:01 +0100 Subject: challenge-254 --- challenge-254/peter-meszaros/perl/ch-1.pl | 60 +++++++++++++++++++++++++++++ challenge-254/peter-meszaros/perl/ch-2.pl | 63 +++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100755 challenge-254/peter-meszaros/perl/ch-1.pl create mode 100755 challenge-254/peter-meszaros/perl/ch-2.pl diff --git a/challenge-254/peter-meszaros/perl/ch-1.pl b/challenge-254/peter-meszaros/perl/ch-1.pl new file mode 100755 index 0000000000..8a1d8509b3 --- /dev/null +++ b/challenge-254/peter-meszaros/perl/ch-1.pl @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +# +# You are given a positive integer, $n. +# +# Write a script to return true if the given integer is a power of three +# otherwise return false. +# Example 1 +# +# Input: $n = 27 +# Output: true +# +# 27 = 3 ^ 3 +# +# Example 2 +# +# Input: $n = 0 +# Output: true +# +# 0 = 0 ^ 3 +# +# Example 3 +# +# Input: $n = 6 +# Output: false +# + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; + +my $cases = [ + [27], + [0], + [6], + [1], + [3], + [4] +]; + +sub three_power +{ + my $n = shift; + + while ($n) { + last if $n % 3; + $n /= 3; + } + return $n == 1 ? 1 : 0; +} + +is(three_power($cases->[0]->@*), 1, 'Example 1 ' . $cases->[0]->[0]); +is(three_power($cases->[1]->@*), 0, 'Example 2 ' . $cases->[1]->[0]); +is(three_power($cases->[2]->@*), 0, 'Example 3 ' . $cases->[2]->[0]); +is(three_power($cases->[3]->@*), 1, 'Example 4 ' . $cases->[3]->[0]); +is(three_power($cases->[4]->@*), 1, 'Example 5 ' . $cases->[4]->[0]); +is(three_power($cases->[5]->@*), 0, 'Example 6 ' . $cases->[5]->[0]); +done_testing(); + +exit 0; diff --git a/challenge-254/peter-meszaros/perl/ch-2.pl b/challenge-254/peter-meszaros/perl/ch-2.pl new file mode 100755 index 0000000000..96aff6bc0a --- /dev/null +++ b/challenge-254/peter-meszaros/perl/ch-2.pl @@ -0,0 +1,63 @@ +#!/usr/bin/env perl +# +# You are given a string, $s. +# +# Write a script to reverse all the vowels (a, e, i, o, u) in the given string. +# Example 1 +# +# Input: $s = "Raku" +# Output: "Ruka" +# +# Example 2 +# +# Input: $s = "Perl" +# Output: "Perl" +# +# Example 3 +# +# Input: $s = "Julia" +# Output: "Jaliu" +# +# Example 4 +# +# Input: $s = "Uiua" +# Output: "Auiu" + + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; +use List::Util qw/sum/; + +my $cases = [ + ['Raku'], + ['Perl'], + ['Julia'], + ['Uiua'], +]; + +sub reverse_wovels +{ + my $str = shift; + + my $qr = qr/[aeiou]/i; + my @str = split('', $str); + $str[0] = lc($str[0]); + my @w = reverse grep { lc(/$qr/) } @str; + for (@str) { + $_ = shift @w if /$qr/; + } + $str[0] = uc($str[0]); + return join('', @str); +} + +is(reverse_wovels($cases->[0]->@*), 'Ruka', 'Example 1'); +is(reverse_wovels($cases->[1]->@*), 'Perl', 'Example 2'); +is(reverse_wovels($cases->[2]->@*), 'Jaliu', 'Example 3'); +is(reverse_wovels($cases->[3]->@*), 'Auiu', 'Example 4'); +done_testing(); + +exit 0; + + -- cgit From 7f665027cfb52ecbab78999e054aa9cbb2214589 Mon Sep 17 00:00:00 2001 From: Thomas Köhler Date: Mon, 29 Jan 2024 15:50:43 +0100 Subject: Add solution 254 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Köhler --- challenge-254/jeanluc2020/blog-1.txt | 1 + challenge-254/jeanluc2020/blog-2.txt | 1 + challenge-254/jeanluc2020/perl/ch-1.pl | 59 +++++++++++++++++++++ challenge-254/jeanluc2020/perl/ch-2.pl | 88 ++++++++++++++++++++++++++++++++ challenge-254/jeanluc2020/python/ch-1.py | 55 ++++++++++++++++++++ challenge-254/jeanluc2020/python/ch-2.py | 84 ++++++++++++++++++++++++++++++ 6 files changed, 288 insertions(+) create mode 100644 challenge-254/jeanluc2020/blog-1.txt create mode 100644 challenge-254/jeanluc2020/blog-2.txt create mode 100755 challenge-254/jeanluc2020/perl/ch-1.pl create mode 100755 challenge-254/jeanluc2020/perl/ch-2.pl create mode 100755 challenge-254/jeanluc2020/python/ch-1.py create mode 100755 challenge-254/jeanluc2020/python/ch-2.py diff --git a/challenge-254/jeanluc2020/blog-1.txt b/challenge-254/jeanluc2020/blog-1.txt new file mode 100644 index 0000000000..62379a7741 --- /dev/null +++ b/challenge-254/jeanluc2020/blog-1.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-254-1.html diff --git a/challenge-254/jeanluc2020/blog-2.txt b/challenge-254/jeanluc2020/blog-2.txt new file mode 100644 index 0000000000..422b30e1fc --- /dev/null +++ b/challenge-254/jeanluc2020/blog-2.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-254-2.html diff --git a/challenge-254/jeanluc2020/perl/ch-1.pl b/challenge-254/jeanluc2020/perl/ch-1.pl new file mode 100755 index 0000000000..6076b8b237 --- /dev/null +++ b/challenge-254/jeanluc2020/perl/ch-1.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-254/#TASK1 +# +# Task 1: Three Power +# =================== +# +# You are given a positive integer, $n. +# +# Write a script to return true if the given integer is a power of three +# otherwise return false. +# +## Example 1 +## +## Input: $n = 27 +## Output: true +## +## 27 = 3 ^ 3 +# +## Example 2 +## +## Input: $n = 0 +## Output: true +## +## 0 = 0 ^ 3 +# +## Example 3 +## +## Input: $n = 6 +## Output: false +# +############################################################ +## +## discussion +## +############################################################ +# +# Starting with $i at 0, count up to $n. If $i**3 == $n we have +# a third power, so return true. If $i**3 > $n we don't have a +# third power, so return false. +# +use strict; +use warnings; + +three_power(27); +three_power(0); +three_power(6); + +sub three_power { + my $n = shift; + print "Input: $n\n"; + foreach my $i (0..$n) { + last if $i**3 > $n; + if($i**3 == $n) { + print "Output: true\n"; + return; + } + } + print "Output: false\n"; +} diff --git a/challenge-254/jeanluc2020/perl/ch-2.pl b/challenge-254/jeanluc2020/perl/ch-2.pl new file mode 100755 index 0000000000..2d78bff247 --- /dev/null +++ b/challenge-254/jeanluc2020/perl/ch-2.pl @@ -0,0 +1,88 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-254/#TASK2 +# +# Task 2: Reverse Vowels +# ====================== +# +# You are given a string, $s. +# +# Write a script to reverse all the vowels (a, e, i, o, u) in the given string. +# +## Example 1 +## +## Input: $s = "Raku" +## Output: "Ruka" +# +## Example 2 +## +## Input: $s = "Perl" +## Output: "Perl" +# +## Example 3 +## +## Input: $s = "Julia" +## Output: "Jaliu" +# +## Example 4 +## +## Input: $s = "Uiua" +## Output: "Auiu" +# +############################################################ +## +## discussion +## +############################################################ +# +# Let's first turn the string into an array of characters. Then +# let's collect the position of all vowels (and whether or not +# they were uppercase). Then we can walk through all vowels and +# write them to their new location in the correct (uppwer/lower) +# case. + +use strict; +use warnings; + +reverse_vowels("Raku"); +reverse_vowels("Perl"); +reverse_vowels("Julia"); +reverse_vowels("Uiua"); + +sub reverse_vowels { + my $s = shift; + print "Input: \"$s\"\n"; + my @chars = split //, $s; + my @vowels = (); + my @indices = (); + foreach my $i (0..$#chars) { + if(is_vowel($chars[$i])) { + push @vowels, [ $i, $chars[$i] ]; + unshift @indices, [ $i, is_upper($chars[$i]) ]; + } + } + foreach my $j (0..$#vowels) { + my ($old_index, $char, $is_upper) = @{ $vowels[$j] }; + my ($new_index, $is_upper) = @{ $indices[$j] }; + my $new_char = $char; + if($is_upper) { + $new_char = uc($new_char); + } else { + $new_char = lc($new_char); + } + $chars[$new_index] = $new_char; + } + $s = join("", @chars); + print "Output: \"$s\"\n"; + +} + +sub is_vowel { + my $char = shift; + my $vowels = { "a" => 1, "e" => 1, "i" => 1, "o" => 1, "u" => 1 }; + return $vowels->{lc($char)}; +} + +sub is_upper { + my $char = shift; + return $char eq uc($char); +} diff --git a/challenge-254/jeanluc2020/python/ch-1.py b/challenge-254/jeanluc2020/python/ch-1.py new file mode 100755 index 0000000000..cf41e8df6f --- /dev/null +++ b/challenge-254/jeanluc2020/python/ch-1.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-254/#TASK1 +# +# Task 1: Three Power +# =================== +# +# You are given a positive integer, $n. +# +# Write a script to return true if the given integer is a power of three +# otherwise return false. +# +## Example 1 +## +## Input: $n = 27 +## Output: true +## +## 27 = 3 ^ 3 +# +## Example 2 +## +## Input: $n = 0 +## Output: true +## +## 0 = 0 ^ 3 +# +## Example 3 +## +## Input: $n = 6 +## Output: false +# +############################################################ +## +## discussion +## +############################################################ +# +# Starting with $i at 0, count up to $n. If $i**3 == $n we have +# a third power, so return true. If $i**3 > $n we don't have a +# third power, so return false. +# + +def three_power(n: int) -> None: + print(f"Input: {n}") + for i in range(n+1): + if i**3 == n: + print("Output: true") + return + if i**3 > n: + print("Output: false") + return + +three_power(27); +three_power(0); +three_power(6); + diff --git a/challenge-254/jeanluc2020/python/ch-2.py b/challenge-254/jeanluc2020/python/ch-2.py new file mode 100755 index 0000000000..d87fb5f0f1 --- /dev/null +++ b/challenge-254/jeanluc2020/python/ch-2.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-254/#TASK2 +# +# Task 2: Reverse Vowels +# ====================== +# +# You are given a string, $s. +# +# Write a script to reverse all the vowels (a, e, i, o, u) in the given string. +# +## Example 1 +## +## Input: $s = "Raku" +## Output: "Ruka" +# +## Example 2 +## +## Input: $s = "Perl" +## Output: "Perl" +# +## Example 3 +## +## Input: $s = "Julia" +## Output: "Jaliu" +# +## Example 4 +## +## Input: $s = "Uiua" +## Output: "Auiu" +# +############################################################ +## +## discussion +## +############################################################ +# +# Let's first turn the string into an array of characters. Then +# let's collect the position of all vowels (and whether or not +# they were uppercase). Then we can walk through all vowels and +# write them to their new location in the correct (uppwer/lower) +# case. + +def is_upper(char: str) -> bool: + upper = char.upper() + if upper == char: + return True + return False + + +def is_vowel(char: str) -> bool: + vowels = { "a": True, "e": True, "i": True, "o": True, "u": True } + if char.lower() in vowels: + return True + return False + +def reverse_vowels(s: str) -> str: + print(f"Input: {s}") + chars = list(s) + vowels = [] + indices = [] + for i in range(len(chars)): + if is_vowel(chars[i]): + vowels.append( (i, chars[i] ) ) + indices.append( (i, is_upper(chars[i]) ) ) + indices.reverse() + for j in range(len(vowels)): + ( old_index, char ) = vowels[j] + ( new_index, is_up ) = indices[j] + new_char = char + if is_up: + new_char = char.upper() + else: + new_char = char.lower() + chars[new_index] = new_char + s = "".join(chars) + print(f"Output: {s}") + return s + + +reverse_vowels("Raku") +reverse_vowels("Perl") +reverse_vowels("Julia") +reverse_vowels("Uiua") + -- cgit From c4b685d93d17c1c40be4be12225d950788a5e5cd Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 29 Jan 2024 10:17:10 -0600 Subject: Solve PWC254 --- challenge-254/wlmb/blog.txt | 1 + challenge-254/wlmb/perl/ch-1.pl | 15 +++++++++++++++ challenge-254/wlmb/perl/ch-2.pl | 17 +++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 challenge-254/wlmb/blog.txt create mode 100755 challenge-254/wlmb/perl/ch-1.pl create mode 100755 challenge-254/wlmb/perl/ch-2.pl diff --git a/challenge-254/wlmb/blog.txt b/challenge-254/wlmb/blog.txt new file mode 100644 index 0000000000..a31d35a7ab --- /dev/null +++ b/challenge-254/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/01/29/PWC254/ diff --git a/challenge-254/wlmb/perl/ch-1.pl b/challenge-254/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..3cca2702aa --- /dev/null +++ b/challenge-254/wlmb/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# Perl weekly challenge 254 +# Task 1: Three Power +# +# See https://wlmb.github.io/2024/01/29/PWC254/#task-1-three-power +use v5.36; +use POSIX qw(lround); +die <<~"FIN" unless @ARGV; + Usage: $0 N1 [N2...] + to check if the integers N1 N2... are cubes + FIN +for(@ARGV){ + warn("$_ not integer"),next unless $_ == lround($_); + say "$_ -> ", abs($_)==lround(abs($_)**(1/3))**3?"True":"False"; +} diff --git a/challenge-254/wlmb/perl/ch-2.pl b/challenge-254/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..b2095c59e0 --- /dev/null +++ b/challenge-254/wlmb/perl/ch-2.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Perl weekly challenge 254 +# Task 2: Reverse Vowels +# +# See https://wlmb.github.io/2024/01/29/PWC254/#task-2-reverse-vowels +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 W1 [W2..] + to reverse the vowels in the words W1 W2... + FIN +for(@ARGV){ + my @all = split "", lc $_; + my @vowel_indices=grep {$all[$_]=~/[aeiou]/} 0..@all-1; + @all[@vowel_indices]=reverse @all[@vowel_indices]; + my $out=ucfirst join "", @all; + say "$_ -> $out"; +} -- cgit From e51d7db0618e4c435d7f3888dcc1c19cac6fbbb0 Mon Sep 17 00:00:00 2001 From: Zapwai Date: Mon, 29 Jan 2024 12:17:39 -0500 Subject: Week 254 --- challenge-254/zapwai/c/ch-1.c | 36 +++++++++++++++++++++ challenge-254/zapwai/c/ch-2.c | 66 +++++++++++++++++++++++++++++++++++++++ challenge-254/zapwai/perl/ch-1.pl | 37 ++++++++++++++++++++++ challenge-254/zapwai/perl/ch-2.pl | 31 ++++++++++++++++++ challenge-254/zapwai/rust/ch-1.rs | 19 +++++++++++ challenge-254/zapwai/rust/ch-2.rs | 39 +++++++++++++++++++++++ 6 files changed, 228 insertions(+) create mode 100644 challenge-254/zapwai/c/ch-1.c create mode 100644 challenge-254/zapwai/c/ch-2.c create mode 100644 challenge-254/zapwai/perl/ch-1.pl create mode 100644 challenge-254/zapwai/perl/ch-2.pl create mode 100644 challenge-254/zapwai/rust/ch-1.rs create mode 100644 challenge-254/zapwai/rust/ch-2.rs diff --git a/challenge-254/zapwai/c/ch-1.c b/challenge-254/zapwai/c/ch-1.c new file mode 100644 index 0000000000..a7044c40e7 --- /dev/null +++ b/challenge-254/zapwai/c/ch-1.c @@ -0,0 +1,36 @@ +#include + +void proc(int n) { + printf("Input: %d\n",n); + printf("Output: "); + int r = n % 3; + if (n == 1) { + printf("True\n"); + return; + } + else if (n < 3) { + printf("False\n"); + return; + } + else { + while (n > 1) { + r = n % 3; + n = n / 3; + } + if (r != 0) { + printf("False\n"); + return; + } + if ( (n == 1) && (r == 0) ) { + printf("True\n"); + return; + } + } +} + +int main() { + int l[] = {27, 0, 6}; + for (int i = 0; i < sizeof(l)/sizeof(int); i++) { + proc(l[i]); + } +} \ No newline at end of file diff --git a/challenge-254/zapwai/c/ch-2.c b/challenge-254/zapwai/c/ch-2.c new file mode 100644 index 0000000000..69e38352a5 --- /dev/null +++ b/challenge-254/zapwai/c/ch-2.c @@ -0,0 +1,66 @@ +#include +#include +bool is_vowel(char c) { + switch(c) { + case 'a' : + case 'e' : + case 'i' : + case 'o' : + case 'u' : + case 'A' : + case 'E' : + case 'I' : + case 'O' : + case 'U' : + return true; + default : + return false; + } +} + +void proc(char *word, int len) { + printf("Input: word = %s\n", word); + printf("Output: "); + char vows[20]; + int vlen = 0; + for (int i = 0; i < len; i++) { + if (is_vowel(word[i])) { + vows[vlen] = word[i]; + vlen++; + } + } + char rvows[20]; + for (int j = 0; j < vlen; j++) { + rvows[j] = vows[vlen - 1 - j]; + } + int j = 0; + for (int i = 0; i < len; i++) { + if (is_vowel(word[i])) { + printf("%c", rvows[j]); + j++; + } else { + printf("%c", word[i]); + } + } + printf("\n"); +} + +int main() { + char word1[] = "Raku"; + char word2[] = "Perl"; + char word3[] = "Julia"; + char word4[] = "Auiu"; + + int l1 = sizeof(word1) / sizeof(char); + proc(word1, l1); + + int l2 = sizeof(word2) / sizeof(char); + proc(word2, l2); + + int l3 = sizeof(word3) / sizeof(char); + proc(word3, l3); + + int l4 = sizeof(word4) / sizeof(char); + proc(word4, l4); + +} \ No newline at end of file diff --git a/challenge-254/zapwai/perl/ch-1.pl b/challenge-254/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..869edaa96b --- /dev/null +++ b/challenge-254/zapwai/perl/ch-1.pl @@ -0,0 +1,37 @@ +use v5.30; +my $n = 27; +#$n = 0; +#$n = 6; + + + say "Input: \$n = $n"; + my $output = div3($n); + if ($output >= 0) { + say "Output: True, $n = 3^", $output; + } else { + say "Output: False"; + } + +sub div3() { + my $n = shift; + my $powflag = 0; + my $endflag = 0; + my $cnt = 0; + do { + $n = $n / 3; + $cnt++; + if ($n == 1) { + $endflag = 1; + $powflag = 1; + } elsif ($n == 0) { + $endflag = 1; + } elsif (int $n != $n) { + $endflag = 1; + } + } until ($endflag); + if ($powflag) { + return $cnt; + } else { + return -1; + } +} \ No newline at end of file diff --git a/challenge-254/zapwai/perl/ch-2.pl b/challenge-254/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..4bf990c631 --- /dev/null +++ b/challenge-254/zapwai/perl/ch-2.pl @@ -0,0 +1,31 @@ +use v5.30; +my $s = "Raku"; +my $s2 = "Julia"; +my $s3 = "Perl"; +my $s4 = "Uiua"; +proc($s);proc($s2);proc($s3);proc($s4); + +sub proc() { + my $s = shift; + say "Input: \$s = $s"; + print "Output: "; + my (@vowels, @ind); + my @l = split "", $s; + foreach my $i (0 .. $#l) { + if ($l[$i] =~ /[aeiouAEIOU]/) { + push @vowels, $l[$i]; + push @ind, $i; + } + } + @vowels = reverse @vowels; + my $j = 0; + foreach my $i (0 .. $#l) { + if ($i ~~ @ind) { + print $vowels[$j]; + $j++; + } else { + print $l[$i]; + } + } + print "\n"; +} \ No newline at end of file diff --git a/challenge-254/zapwai/rust/ch-1.rs b/challenge-254/zapwai/rust/ch-1.rs new file mode 100644 index 0000000000..178d24ddbd --- /dev/null +++ b/challenge-254/zapwai/rust/ch-1.rs @@ -0,0 +1,19 @@ +fn main() { + for n in [27, 0, 6] { + println!("Input: {}\nOutput: {}", n, proc(n)); + } +} + +fn proc(n : i32) -> bool { + if n < 3 {return false;} + for i in 1 .. { + if n % i32::pow(3,i) != 0 { + if n / i32::pow(3,i-1) == 1 { + return true; + } else { + return false; + } + } + } + return true; +} \ No newline at end of file diff --git a/challenge-254/zapwai/rust/ch-2.rs b/challenge-254/zapwai/rust/ch-2.rs new file mode 100644 index 0000000000..a6b341a374 --- /dev/null +++ b/challenge-254/zapwai/rust/ch-2.rs @@ -0,0 +1,39 @@ +fn main() { + let words = ["Raku", "Perl", "Julia", "Uaia"]; + for w in words { + proc(w); + } +} + +fn proc(word : &str) { + let mut vows = Vec::new(); + let mut inds = Vec::new(); + let mut w = Vec::new(); + for c in word.chars() { + w.push(c); + } + for i in 0 .. word.len() { + let l = w[i]; + if l == 'a' || l == 'A' || + l == 'e' || l == 'E' || + l == 'i' || l == 'I' || + l == 'o' || l == 'O' || + l == 'u' || l == 'U' + { + vows.push(l); + inds.push(i); + } + } + inds.push(0); + let k = vows.len()-1; + let mut j = 0; + for i in 0 .. word.len() { + if i == inds[j] { + print!("{}", vows[k-j]); + j += 1; + } else { + print!("{}", w[i]); + } + } + println!(""); +} \ No newline at end of file -- cgit From d63377644b6fe7841a4e25eace5190494d2107cf Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 29 Jan 2024 21:47:46 +0000 Subject: add solutions week 254 in python --- challenge-254/steven-wilson/python/ch-01.py | 24 +++++++++++++++++ challenge-254/steven-wilson/python/ch-02.py | 40 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 challenge-254/steven-wilson/python/ch-01.py create mode 100644 challenge-254/steven-wilson/python/ch-02.py diff --git a/challenge-254/steven-wilson/python/ch-01.py b/challenge-254/steven-wilson/python/ch-01.py new file mode 100644 index 0000000000..6c51d189e2 --- /dev/null +++ b/challenge-254/steven-wilson/python/ch-01.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import math + + +def is_power_three(number): + ''' Given a positive integer. Returns true if the given integer is a power + of three otherwise returns false. + + >>> is_power_three(27) + True + >>> is_power_three(0) + True + >>> is_power_three(6) + False + ''' + cr = round(math.pow(number, 1/3), 6) + return ((cr - int(cr)) == 0) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/challenge-254/steven-wilson/python/ch-02.py b/challenge-254/steven-wilson/python/ch-02.py new file mode 100644 index 0000000000..3d2a7d6821 --- /dev/null +++ b/challenge-254/steven-wilson/python/ch-02.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + + +VOWELS = ['a', 'e', 'i', 'o', 'u'] + + +def reverse_vowels(string): + ''' Give