aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-15 22:25:18 +0100
committerGitHub <noreply@github.com>2024-09-15 22:25:18 +0100
commitbdc7f807d308edec64b5277c6518fa24184fe1b0 (patch)
tree2e8678016be42b4bbe662e7401662916c87a6073
parent747b06081f2f62296d2659ba754a67fd47eb177d (diff)
parent1f1c8e0a7954e5dd61dd9f12712e5213d9cfb582 (diff)
downloadperlweeklychallenge-club-bdc7f807d308edec64b5277c6518fa24184fe1b0.tar.gz
perlweeklychallenge-club-bdc7f807d308edec64b5277c6518fa24184fe1b0.tar.bz2
perlweeklychallenge-club-bdc7f807d308edec64b5277c6518fa24184fe1b0.zip
Merge pull request #10840 from JTimothyKing/challenge-286
Solutions to challenge 286 by Tim King
-rw-r--r--challenge-286/jtimothyking/blog.txt1
-rw-r--r--challenge-286/jtimothyking/csharp/ch-1.cs27
-rw-r--r--challenge-286/jtimothyking/csharp/ch-2.cs22
-rw-r--r--challenge-286/jtimothyking/perl/ch-1.pl21
-rw-r--r--challenge-286/jtimothyking/perl/ch-2.pl21
5 files changed, 92 insertions, 0 deletions
diff --git a/challenge-286/jtimothyking/blog.txt b/challenge-286/jtimothyking/blog.txt
new file mode 100644
index 0000000000..98b1d6756b
--- /dev/null
+++ b/challenge-286/jtimothyking/blog.txt
@@ -0,0 +1 @@
+https://github.com/JTimothyKing/PWC/blob/main/challenge-286/blog.md
diff --git a/challenge-286/jtimothyking/csharp/ch-1.cs b/challenge-286/jtimothyking/csharp/ch-1.cs
new file mode 100644
index 0000000000..0e3537bfb3
--- /dev/null
+++ b/challenge-286/jtimothyking/csharp/ch-1.cs
@@ -0,0 +1,27 @@
+namespace ch_1;
+
+public static class Ch1
+{
+ public static void Main(string[] args)
+ {
+ const string quineString = """
+ namespace ch_1;
+
+ public static class Ch1
+ {{
+ public static void Main(string[] args)
+ {{
+ const string quineString = {0}{0}{0} {1} {0}{0}{0};
+ var words = string.Format(quineString, (char)34, quineString)
+ .Trim().Split([' ', '\n', '\r', '\t'], StringSplitOptions.RemoveEmptyEntries);
+ var randomWord = words[Random.Shared.Next(words.Length)];
+ Console.WriteLine(randomWord);
+ }}
+ }}
+ """;
+ var words = string.Format(quineString, (char)34, quineString)
+ .Trim().Split([' ', '\n', '\r', '\t'], StringSplitOptions.RemoveEmptyEntries);
+ var randomWord = words[Random.Shared.Next(words.Length)];
+ Console.WriteLine(randomWord);
+ }
+} \ No newline at end of file
diff --git a/challenge-286/jtimothyking/csharp/ch-2.cs b/challenge-286/jtimothyking/csharp/ch-2.cs
new file mode 100644
index 0000000000..3c074ac7ec
--- /dev/null
+++ b/challenge-286/jtimothyking/csharp/ch-2.cs
@@ -0,0 +1,22 @@
+namespace ch_2;
+
+public static class Ch2
+{
+ public static void Main(string[] args)
+ {
+ var ints = args.Select(int.Parse).ToList();
+ if (ints.Count < 1) return;
+ while (ints.Count > 1) ints = ints.MinMax().ToList();
+ Console.WriteLine(ints[0]);
+ }
+
+ private static IEnumerable<int> MinMax(this IEnumerable<int> ints)
+ {
+ var doMin = true;
+ foreach (var pair in ints.Chunk(2))
+ {
+ yield return doMin ? pair.Min() : pair.Max();
+ doMin = !doMin;
+ }
+ }
+} \ No newline at end of file
diff --git a/challenge-286/jtimothyking/perl/ch-1.pl b/challenge-286/jtimothyking/perl/ch-1.pl
new file mode 100644
index 0000000000..2c6fbc99dd
--- /dev/null
+++ b/challenge-286/jtimothyking/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use v5.38;
+use warnings;
+
+my $quine_string = q(
+ #!/usr/bin/perl
+ use v5.38;
+ use warnings;
+
+ $quine_string = q( %s );
+ my @words = split ' ', sprintf $quine_string, $quine_string;
+ my $random_word = $words[rand @words];
+ print "$random_word\n";
+
+ __END__
+);
+my @words = split ' ', sprintf $quine_string, $quine_string;
+my $random_word = $words[rand @words];
+print "$random_word\n";
+
+__END__
diff --git a/challenge-286/jtimothyking/perl/ch-2.pl b/challenge-286/jtimothyking/perl/ch-2.pl
new file mode 100644
index 0000000000..22fd34dcd6
--- /dev/null
+++ b/challenge-286/jtimothyking/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use v5.38;
+use warnings;
+
+use List::Util qw(min max pairs);
+
+{
+ my @ints = @ARGV;
+ exit unless @ints;
+ @ints = min_max(@ints) while (@ints > 1);
+ say $ints[0];
+}
+
+sub min_max {
+ my $idx_op = 0;
+ my @ints = @_;
+ push @ints, $ints[-1] if @ints & 0x1; # Repeat last item if odd number.
+ return map { [ \&min, \&max ]->[($idx_op++) & 0x1]->(@$_) } pairs @ints;
+}
+
+__END__