aboutsummaryrefslogtreecommitdiff
path: root/challenge-219
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-219')
-rwxr-xr-xchallenge-219/eric-cheung/python/ch-1.py7
-rwxr-xr-xchallenge-219/eric-cheung/python/ch-2.py60
-rw-r--r--challenge-219/jeanluc2020/blog.txt (renamed from challenge-219/jeanluc2020/blog-1.txt)0
-rw-r--r--challenge-219/jeanluc2020/blog1.txt (renamed from challenge-219/jeanluc2020/blog-2.txt)0
-rw-r--r--challenge-219/robert-dicicco/julia/ch-1.jl35
-rw-r--r--challenge-219/robert-dicicco/perl/ch-1.pl38
-rw-r--r--challenge-219/robert-dicicco/python/ch-1.py29
-rw-r--r--challenge-219/robert-dicicco/raku/ch-1.raku35
-rw-r--r--challenge-219/robert-dicicco/ruby/ch-1.rb34
9 files changed, 238 insertions, 0 deletions
diff --git a/challenge-219/eric-cheung/python/ch-1.py b/challenge-219/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..13c7e71089
--- /dev/null
+++ b/challenge-219/eric-cheung/python/ch-1.py
@@ -0,0 +1,7 @@
+
+## arrInputList = [-2, -1, 0, 3, 4] ## Example 1
+arrInputList = [5, -4, -1, 3, 6] ## Example 2
+
+arrOutputList = sorted([nElem * nElem for nElem in arrInputList])
+
+print (arrOutputList)
diff --git a/challenge-219/eric-cheung/python/ch-2.py b/challenge-219/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..e4c1d29724
--- /dev/null
+++ b/challenge-219/eric-cheung/python/ch-2.py
@@ -0,0 +1,60 @@
+
+## Example 1
+## arrCost = [2, 7, 25]
+## arrDays = [1, 5, 6, 7, 9, 15]
+
+## Example 2
+arrCost = [2, 7, 25]
+arrDays = [1, 2, 3, 5, 7, 10, 11, 12, 14, 20, 30, 31]
+
+## Trial 1
+nCost = arrCost[2]
+
+## Trial 2
+nCost = min(nCost, arrCost[0] * len(arrDays))
+
+## Trial 3
+nLoop = 0
+nWeekCount = 0
+while nLoop < len(arrDays):
+ nLoopDay = arrDays[nLoop] + 6
+
+ ## print ("nLoop: " + str(nLoop))
+ ## print ("nLoopDay: " + str(nLoopDay))
+
+ arrSubDay = [nIndx for nIndx, nElem in enumerate(arrDays) if nElem >= nLoopDay]
+
+ if arrSubDay == []:
+ nWeekCount = nWeekCount + 1
+ break
+
+ nFindIndx = min(arrSubDay)
+ nShiftIndx = (1 if arrDays[nFindIndx] == nLoopDay else 0)
+ nLoop = nShiftIndx + nFindIndx
+ nWeekCount = nWeekCount + 1
+
+ ## print ("nWeekCount: " + str(nWeekCount))
+ ## print ("")
+
+
+## print (nWeekCount)
+nCost = min(nCost, arrCost[1] * nWeekCount)
+
+## Trial 4
+nLoop = 1
+nIndx = 0
+while nLoop < nWeekCount:
+ nLoopDay = arrDays[nIndx] + 6
+ arrSubDay = [nIndx for nIndx, nElem in enumerate(arrDays) if nElem >= nLoopDay]
+
+ if arrSubDay == []:
+ break
+
+ nFindIndx = min(arrSubDay)
+ nShiftIndx = (1 if arrDays[nFindIndx] == nLoopDay else 0)
+ nIndx = nShiftIndx + nFindIndx
+ nRemain = len(arrSubDay) - nShiftIndx
+ nCost = min(nCost, arrCost[1] * nLoop + arrCost[0] * nRemain)
+ nLoop = nLoop + 1
+
+print (nCost)
diff --git a/challenge-219/jeanluc2020/blog-1.txt b/challenge-219/jeanluc2020/blog.txt
index 49272dae95..49272dae95 100644
--- a/challenge-219/jeanluc2020/blog-1.txt
+++ b/challenge-219/jeanluc2020/blog.txt
diff --git a/challenge-219/jeanluc2020/blog-2.txt b/challenge-219/jeanluc2020/blog1.txt
index c047a2bc98..c047a2bc98 100644
--- a/challenge-219/jeanluc2020/blog-2.txt
+++ b/challenge-219/jeanluc2020/blog1.txt
diff --git a/challenge-219/robert-dicicco/julia/ch-1.jl b/challenge-219/robert-dicicco/julia/ch-1.jl
new file mode 100644
index 0000000000..fb98a5a260
--- /dev/null
+++ b/challenge-219/robert-dicicco/julia/ch-1.jl
@@ -0,0 +1,35 @@
+#!/usr/bin/env julia
+using Printf
+#=
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-29
+Challenge 219 Sorted Squares Task 1 ( Julia )
+--------------------------------------
+=#
+
+list = [[-2, -1, 0, 3, 4],
+ [5, -4, -1, 3, 6]
+ ];
+
+for lst in list
+ @printf("Input: @list = %s\n",lst)
+ lst = map((x) -> x ^ 2, lst)
+ @printf("%s\n\n",sort(lst))
+end
+
+#=
+--------------------------------------
+SAMPLE OUTPUT
+julia .\SortedSquares.jl
+
+Input: @list = [-2, -1, 0, 3, 4]
+[0, 1, 4, 9, 16]
+
+Input: @list = [5, -4, -1, 3, 6]
+[1, 9, 16, 25, 36]
+
+--------------------------------------
+=#
+
+
diff --git a/challenge-219/robert-dicicco/perl/ch-1.pl b/challenge-219/robert-dicicco/perl/ch-1.pl
new file mode 100644
index 0000000000..0a0ef3c52a
--- /dev/null
+++ b/challenge-219/robert-dicicco/perl/ch-1.pl
@@ -0,0 +1,38 @@
+#!usr/bin/env perl
+use strict;
+use warnings;
+use feature 'say';
+=begin comment
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-29
+Challenge 219 Sorted Squares Task 1 ( Perl )
+--------------------------------------
+=cut
+
+my @list = ([-2, -1, 0, 3, 4],
+ [5, -4, -1, 3, 6]
+ );
+my $cnt = (scalar @list) ;
+
+while ($cnt--) {
+ say "Input: \@list = [@{$list[$cnt]}]";
+ my @squared_array = map { $_ ** 2 } @{$list[$cnt]};
+ my @sorted = sort { $a <=> $b } @squared_array;
+ print "Output: ",join(", ", @sorted), "\n\n";
+}
+
+=begin comment
+--------------------------------------
+SAMPLE OUTPUT
+
+perl .\SortedSquares.pl
+Input: @list = [5 -4 -1 3 6]
+Output: 1, 9, 16, 25, 36
+
+Input: @list = [-2 -1 0 3 4]
+Output: 0, 1, 4, 9, 16
+--------------------------------------
+=cut
+
+
diff --git a/challenge-219/robert-dicicco/python/ch-1.py b/challenge-219/robert-dicicco/python/ch-1.py
new file mode 100644
index 0000000000..8823416047
--- /dev/null
+++ b/challenge-219/robert-dicicco/python/ch-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+#--------------------------------------
+# AUTHOR: Robert DiCicco
+# DATE : 2023-05-29
+# Challenge 219 Sorted Squares Task 1 ( Python )
+#--------------------------------------
+
+mylist = [[-2, -1, 0, 3, 4],
+ [5, -4, -1, 3, 6]
+ ];
+
+for lst in mylist:
+ print("Input: @list = ",lst)
+ print(sorted(list(map(lambda x: x * x, lst))),"\n")
+
+#--------------------------------------
+# SORTED OUTPUT
+# python .\SortedSquares.py
+
+# Input: @list = [-2, -1, 0, 3, 4]
+# [0, 1, 4, 9, 16]
+
+# Input: @list = [5, -4, -1, 3, 6]
+# [1, 9, 16, 25, 36]
+
+#--------------------------------------
+
+
diff --git a/challenge-219/robert-dicicco/raku/ch-1.raku b/challenge-219/robert-dicicco/raku/ch-1.raku
new file mode 100644
index 0000000000..b844b85645
--- /dev/null
+++ b/challenge-219/robert-dicicco/raku/ch-1.raku
@@ -0,0 +1,35 @@
+#!/usr/bin/env raku
+=begin comment
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-29
+Challenge 219 Sorted Squares Task 1 ( Raku )
+--------------------------------------
+=end comment
+use v6;
+
+my @list = ([-2, -1, 0, 3, 4],
+ [5, -4, -1, 3, 6]
+ );
+my $cnt = @list.elems ;
+
+for (@list) -> @lst {
+ say "Input: \@list = ",@lst;
+ my @squared_array = map(-> $x {$x ** 2},@lst).sort.join(',');
+ say "Output: ",@squared_array,"\n";
+}
+
+=begin comment
+--------------------------------------
+SAMPLE OUTPUT
+raku .\SortedSquares.rk
+
+Input: @list = [-2 -1 0 3 4]
+Output: [0,1,4,9,16]
+
+Input: @list = [5 -4 -1 3 6]
+Output: [1,9,16,25,36]
+--------------------------------------
+=end comment
+
+
diff --git a/challenge-219/robert-dicicco/ruby/ch-1.rb b/challenge-219/robert-dicicco/ruby/ch-1.rb
new file mode 100644
index 0000000000..3c4fa8ceeb
--- /dev/null
+++ b/challenge-219/robert-dicicco/ruby/ch-1.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+=begin
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-29
+Challenge 219 Sorted Squares Task 1 ( Ruby )
+--------------------------------------
+=end
+
+list = [[-2, -1, 0, 3, 4],
+ [5, -4, -1, 3, 6]
+ ];
+
+list.each do |lst|
+ puts("Input: @list = #{lst}")
+ lst = lst.map { |val| val ** 2 }
+ puts("#{lst.sort}\n\n")
+end
+
+=begin
+--------------------------------------
+SAMPLE OUTPUT
+ruby .\SortedSquares.rb
+
+Input: @list = [-2, -1, 0, 3, 4]
+[0, 1, 4, 9, 16]
+
+Input: @list = [5, -4, -1, 3, 6]
+[1, 9, 16, 25, 36]
+
+--------------------------------------
+=end
+
+