From dd7b7f3344a33d4c8f1b6947e58eeb2ba02f84f3 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 16 Jul 2024 11:53:17 +0100 Subject: - Added solutions by Eric Cheung. - Added solutions by Laurent Rosenfeld. - Added solutions by Mark Anderson. - Added solutions by Alexander Karelas. - Added solutions by Matthew Neleigh. - Added solutions by Feng Chang. - Added solutions by E. Choroba. - Added solutions by PokGoPun. - Added solutions by Steven Wilson. - Added solutions by Peter Meszaros. - Added solutions by Peter Campbell Smith. - Added solutions by David Ferrone. - Added solutions by Conor Hoekstra. - Added solutions by Thomas Kohler. - Added solutions by W. Luis Mochan. - Added solutions by Jaldhar H. Vyas. - Added solutions by Athanasius. - Added solutions by Robbie Hatley. - Added solutions by Luca Ferrari. --- challenge-278/eric-cheung/python/ch-1.py | 10 ++++++++++ challenge-278/eric-cheung/python/ch-2.py | 18 ++++++++++++++++++ challenge-278/laurent-rosenfeld/blog.txt | 1 + challenge-278/laurent-rosenfeld/perl/ch-1.pl | 22 ++++++++++++++++++++++ challenge-278/laurent-rosenfeld/raku/ch-1.raku | 17 +++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100755 challenge-278/eric-cheung/python/ch-1.py create mode 100755 challenge-278/eric-cheung/python/ch-2.py create mode 100644 challenge-278/laurent-rosenfeld/blog.txt create mode 100644 challenge-278/laurent-rosenfeld/perl/ch-1.pl create mode 100644 challenge-278/laurent-rosenfeld/raku/ch-1.raku (limited to 'challenge-278') diff --git a/challenge-278/eric-cheung/python/ch-1.py b/challenge-278/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..5fd86d7d26 --- /dev/null +++ b/challenge-278/eric-cheung/python/ch-1.py @@ -0,0 +1,10 @@ + +## strShuffle = "and2 Raku3 cousins5 Perl1 are4" ## Example 1 +## strShuffle = "guest6 Python1 most4 the3 popular5 is2 language7" ## Example 2 +strShuffle = "Challenge3 The1 Weekly2" ## Example 3 + +arrSplit = sorted([[int(strLoop[-1]), strLoop[:-1]] for strLoop in strShuffle.split()]) + +arrOrder = [strSortLoop for nSort, strSortLoop in arrSplit] + +print (" ".join(arrOrder)) diff --git a/challenge-278/eric-cheung/python/ch-2.py b/challenge-278/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..e173d974d8 --- /dev/null +++ b/challenge-278/eric-cheung/python/ch-2.py @@ -0,0 +1,18 @@ + +## Example 1 +## strInput = "challenge" +## charInput = "e" + +## Example 2 +## strInput = "programming" +## charInput = "a" + +## Example 3 +strInput = "champion" +charInput = "b" + +if charInput in strInput: + nPos = strInput.find(charInput) + print ("".join(sorted(strInput[:nPos + 1])) + strInput[nPos + 1:]) +else: + print (strInput) diff --git a/challenge-278/laurent-rosenfeld/blog.txt b/challenge-278/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..5a40c6ca06 --- /dev/null +++ b/challenge-278/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2024/07/perl-weekly-challenge-278-sort-string.html diff --git a/challenge-278/laurent-rosenfeld/perl/ch-1.pl b/challenge-278/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..6953ad0a53 --- /dev/null +++ b/challenge-278/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,22 @@ +use strict; +use warnings; +use feature 'say'; + +sub sort_string { + my @positions; + my @words = split /\s+/, shift; + for my $word (@words) { + my ($letters, $digits) = ($word =~ m/(\D+)(\d+)/); + $positions[$digits] = $letters; + + } + return "@positions[1..$#positions]"; +} +my @tests = ("and2 Raku3 cousins5 Perl1 are4", + "guest6 Python1 most4 the3 popular5 is2 language7", + "Challenge3 The1 Weekly2"); +for my $test (@tests) { + say $test; + say sort_string $test; + say ""; +} diff --git a/challenge-278/laurent-rosenfeld/raku/ch-1.raku b/challenge-278/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..b7bcaf9500 --- /dev/null +++ b/challenge-278/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,17 @@ +sub sort-string ($in) { + my @positions; + for $in.words -> $word { + $word ~~ m/(\D+)(\d+)/; + @positions[$/[1]] = ~$/[0]; + + } + return "@positions[1..@positions.end]"; +} +my @tests = "and2 Raku3 cousins5 Perl1 are4", + "guest6 Python1 most4 the3 popular5 is2 language7", + "Challenge3 The1 Weekly2"; +for @tests -> $test { + say $test; + say sort-string $test; + say ""; +} -- cgit