diff options
Diffstat (limited to 'challenge-278')
| -rwxr-xr-x | challenge-278/eric-cheung/python/ch-1.py | 10 | ||||
| -rwxr-xr-x | challenge-278/eric-cheung/python/ch-2.py | 18 | ||||
| -rw-r--r-- | challenge-278/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-278/laurent-rosenfeld/perl/ch-1.pl | 22 | ||||
| -rw-r--r-- | challenge-278/laurent-rosenfeld/raku/ch-1.raku | 17 |
5 files changed, 68 insertions, 0 deletions
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 ""; +} |
