aboutsummaryrefslogtreecommitdiff
path: root/challenge-228
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-08-01 19:05:05 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-08-01 19:05:05 +0100
commit107a44513e966e7cd37501766c573e3c97688680 (patch)
tree51f3a78e2d86e5fdd6faef12f454f7f54436123d /challenge-228
parent6919309e7a165c572c3cef20c8d0bd7ed9e79f57 (diff)
downloadperlweeklychallenge-club-107a44513e966e7cd37501766c573e3c97688680.tar.gz
perlweeklychallenge-club-107a44513e966e7cd37501766c573e3c97688680.tar.bz2
perlweeklychallenge-club-107a44513e966e7cd37501766c573e3c97688680.zip
- Added solutions by Mariano Spadaccini.
- Added solutions by Andreas Voegele. - Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-228')
-rw-r--r--challenge-228/robert-dicicco/julia/ch-2.jl56
-rw-r--r--challenge-228/robert-dicicco/perl/ch-2.pl54
-rw-r--r--challenge-228/robert-dicicco/python/ch-2.py44
-rw-r--r--challenge-228/robert-dicicco/raku/ch-2.raku52
-rw-r--r--challenge-228/robert-dicicco/ruby/ch-2.rb50
5 files changed, 256 insertions, 0 deletions
diff --git a/challenge-228/robert-dicicco/julia/ch-2.jl b/challenge-228/robert-dicicco/julia/ch-2.jl
new file mode 100644
index 0000000000..1539892622
--- /dev/null
+++ b/challenge-228/robert-dicicco/julia/ch-2.jl
@@ -0,0 +1,56 @@
+#!/usr/bin/env julia
+#=
+---------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-08-01
+Challenge 228 Task 2 Empty Array ( Julia )
+---------------------------------------
+=#
+
+using Printf
+
+myints = [[3, 4, 2],[1,2,3]]
+
+for i in myints
+ @printf("Input: @int = %s\n",i)
+ cnt = 0
+ while length(i) > 0
+ min = minimum(i)
+ #@printf("min = %d\n",min)
+ #@printf("before %s\n",i)
+ if (i[1] == min)
+ popfirst!(i)
+ else
+ push!(i,i[1])
+ popfirst!(i)
+ end
+ #@printf("after %s\n",i)
+ length(i) > 0 ? @printf("%s\n",i) : @printf("%s\n","()")
+ cnt += 1
+ end
+ @printf("Output: %d\n\n",cnt)
+end
+
+#=
+---------------------------------------
+SAMPLE OUTPUT
+julia .\EmptyArray.jl
+
+Input: @int = [3, 4, 2]
+[4, 2, 3]
+[2, 3, 4]
+[3, 4]
+[4]
+()
+Output: 5
+
+Input: @int = [1, 2, 3]
+[2, 3]
+[3]
+()
+Output: 3
+---------------------------------------
+=#
+
+
+
diff --git a/challenge-228/robert-dicicco/perl/ch-2.pl b/challenge-228/robert-dicicco/perl/ch-2.pl
new file mode 100644
index 0000000000..b948b27b5b
--- /dev/null
+++ b/challenge-228/robert-dicicco/perl/ch-2.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/env perl
+=begin comment
+---------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-08-01
+Challenge 228 Task 2 Empty Array ( Perl )
+---------------------------------------
+=cut
+use v5.38;
+use List::Util qw/min/;
+
+my @myints = ([3, 4, 2],[1,2,3]);
+
+for my $i (@myints) {
+ say "Input: \@int = (@$i)";
+ my $cnt = 0;
+ while(scalar @$i) {
+ my $min = min(@$i);
+ if ($i->[0] == $min) {
+ shift(@$i);
+ } else {
+ push(@$i,$i->[0]);
+ shift(@$i);
+ }
+ scalar @$i > 0 ? say "(@$i)" : say "()";
+ $cnt++;
+ }
+ say "Output: $cnt\n";
+}
+
+=begin comment
+---------------------------------------
+SAMPLE OUTPUT
+perl .\EmptyArray.pl
+
+Input: @int = (3 4 2)
+(4 2 3)
+(2 3 4)
+(3 4)
+(4)
+()
+Output: 5
+
+Input: @int = (1 2 3)
+(2 3)
+(3)
+()
+Output: 3
+---------------------------------------
+=cut
+
+
+
+
diff --git a/challenge-228/robert-dicicco/python/ch-2.py b/challenge-228/robert-dicicco/python/ch-2.py
new file mode 100644
index 0000000000..a45a57a3b3
--- /dev/null
+++ b/challenge-228/robert-dicicco/python/ch-2.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# ---------------------------------------
+# AUTHOR: Robert DiCicco
+# DATE : 2023-08-01
+# Challenge 228 Task 2 Empty Array ( Python )
+# ---------------------------------------
+
+myints = [[3, 4, 2],[1,2,3]]
+
+for i in myints:
+ print(f"Input: @int = {i}")
+ cnt = 0
+ while len(i) > 0:
+ mn = min(i)
+ if (i[0] == mn):
+ i.pop(0)
+ else:
+ i.append(i[0])
+ i.pop(0)
+ print(i) if len(i) > 0 else print("()")
+ cnt += 1
+ print(f"Output: {cnt}\n")
+
+# ---------------------------------------
+# SAMPLE OUTPUT
+# python .\EmptyArray.py
+# #
+# Input: @int = [3, 4, 2]
+# [4, 2, 3]
+# [2, 3, 4]
+# [3, 4]
+# [4]
+# ()
+# Output: 5
+# #
+# Input: @int = [1, 2, 3]
+# [2, 3]
+# [3]
+# ()
+# Output: 3
+# ---------------------------------------
+
+
+
diff --git a/challenge-228/robert-dicicco/raku/ch-2.raku b/challenge-228/robert-dicicco/raku/ch-2.raku
new file mode 100644
index 0000000000..f4951f1d86
--- /dev/null
+++ b/challenge-228/robert-dicicco/raku/ch-2.raku
@@ -0,0 +1,52 @@
+#!/usr/bin/env raku
+=begin comment
+---------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-08-01
+Challenge 228 Task 2 Empty Array ( Raku )
+---------------------------------------
+=end comment
+use v6;
+
+my @myints = ([3, 4, 2],[1,2,3]);
+
+for (@myints) -> @i {
+ say "Input: \@int = ",@i;
+ my $cnt = 0;
+ while @i.elems {
+ my $min = @i.min;
+ if (@i[0] == $min) {
+ @i.shift;
+ } else {
+ @i.push: @i[0];
+ @i.shift;
+ }
+ @i.elems > 0 ?? say @i !! say "()";
+ $cnt++;
+ }
+ say "Output: $cnt\n";
+}
+
+=begin comment
+---------------------------------------
+SAMPLE OUTPUT
+raku .\EmptyArray.rk
+
+Input: @int = [3 4 2]
+[4 2 3]
+[2 3 4]
+[3 4]
+[4]
+()
+Output: 5
+
+Input: @int = [1 2 3]
+[2 3]
+[3]
+()
+Output: 3
+---------------------------------------
+=end comment
+
+
+
diff --git a/challenge-228/robert-dicicco/ruby/ch-2.rb b/challenge-228/robert-dicicco/ruby/ch-2.rb
new file mode 100644
index 0000000000..3c801fc147
--- /dev/null
+++ b/challenge-228/robert-dicicco/ruby/ch-2.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+=begin
+---------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-08-01
+Challenge 228 Task 2 Empty Array ( Raku )
+---------------------------------------
+=end
+
+myints = [[3, 4, 2],[1,2,3]]
+
+myints.each do |i|
+ puts("Input: @int = #{i}")
+ cnt = 0
+ while i.length() > 0
+ min = i.min()
+ if (i[0] == min)
+ i.shift()
+ else
+ i.push(i[0])
+ i.shift()
+ end
+ i.length() > 0 ? puts("#{i}") : puts("()")
+ cnt += 1
+ end
+ puts("Output: #{cnt}\n\n")
+end
+
+=begin
+---------------------------------------
+SAMPLE OUTPUT
+ruby .\EmptyArray.rb
+
+Input: @int = [3, 4, 2]
+[4, 2, 3]
+[2, 3, 4]
+[3, 4]
+[4]
+()
+Output: 5
+
+Input: @int = [1, 2, 3]
+[2, 3]
+[3]
+()
+Output: 3
+---------------------------------------
+=end
+
+