diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-14 20:46:12 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-14 20:46:12 +0000 |
| commit | c0a77fed469750f4d61fc8217dba94dea7f608e2 (patch) | |
| tree | fc6b34a249023115b7998ab1a084656867a4faa4 /challenge-191 | |
| parent | 5ff6e3dd8272452defdb5cba3f4ae90866cee0c9 (diff) | |
| download | perlweeklychallenge-club-c0a77fed469750f4d61fc8217dba94dea7f608e2.tar.gz perlweeklychallenge-club-c0a77fed469750f4d61fc8217dba94dea7f608e2.tar.bz2 perlweeklychallenge-club-c0a77fed469750f4d61fc8217dba94dea7f608e2.zip | |
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-191')
| -rw-r--r-- | challenge-191/robert-dicicco/julia/ch-1.jl | 93 | ||||
| -rw-r--r-- | challenge-191/robert-dicicco/perl/ch-1.pl | 95 | ||||
| -rw-r--r-- | challenge-191/robert-dicicco/raku/ch-1.raku | 87 | ||||
| -rw-r--r-- | challenge-191/robert-dicicco/ruby/ch-1.rb | 91 | ||||
| -rw-r--r-- | challenge-191/robert-dicicco/tcl/ch-1.tcl | 97 |
5 files changed, 463 insertions, 0 deletions
diff --git a/challenge-191/robert-dicicco/julia/ch-1.jl b/challenge-191/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..816f27ba38 --- /dev/null +++ b/challenge-191/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,93 @@ +#!/usr/bin/env julia + +#= + +UTHOR: Robert DiCicco + +DATE: 2022-11-14 + +Challenge 191 Twice Largest ( Julia ) + + + +You are given list of integers, @list. + +Write a script to find out whether the largest item in the + +list is at least twice as large as each of the other items. + +=# + +using Printf + + + +arr = [[1,2,3,4],[1,2,0,5],[2,6,3,1],[4,5,2,3]] + + + +for lst in arr + + @printf("Input: @list = %s\n",lst); + + result = "good" + + max = maximum(lst) + + sort!(lst) + + x = 1 + + while (x < length(lst)) + + if ( (2 * (lst[x]) > max)) + + println("Output: -1\n") + + result = "bad" + + break + + end + + x += 1 + + end + + if (cmp(result,"good") == 0) + + println("Output: 1\n") + + end + +end + + + +#= + +SAMPLE OUTPUT + +Input: @list = [1, 2, 3, 4] + +Output: -1 + + + +Input: @list = [1, 2, 0, 5] + +Output: 1 + + + +Input: @list = [2, 6, 3, 1] + +Output: 1 + + + +Input: @list = [4, 5, 2, 3] + +Output: -1 + +=# diff --git a/challenge-191/robert-dicicco/perl/ch-1.pl b/challenge-191/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..2d17a4a15f --- /dev/null +++ b/challenge-191/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,95 @@ +#!/usr/bin/env perl + +=begin pod + +AUTHOR: Robert DiCicco + +DATE: 2022-11-14 + +Challenge 191 Twice Largest ( Perl ) + + + +You are given list of integers, @list. + +Write a script to find out whether the largest item in the + +list is at least twice as large as each of the other items. + +=cut + +use strict; + +use warnings; + +use feature qw/say/; + +use List::Util qw( max ); + + + +my @arr = ([1,2,3,4],[1,2,0,5],[2,6,3,1],[4,5,2,3]); + + + +for my $lst (@arr) { + + my $result = "good"; + + print("Input: \@list = \(@$lst\)\n"); + + my $max = max(@$lst); + + my @sorted = sort @$lst; + + my $x = 0; + + while($x < scalar(@$lst)-1) { + + if ( (2 * ($sorted[$x]) > $max)) { + + say "Output: -1\n"; + + $result = "bad"; + + last; + + } + + $x++; + + } + + if ($result eq "good") { say "Output: 1\n"} + + } + + + +=begin pod + +SAMPLE OUTPUT + +Input: @list = (1 2 3 4) + +Output: -1 + + + +Input: @list = (1 2 0 5) + +Output: 1 + + + +Input: @list = (2 6 3 1) + +Output: 1 + + + +Input: @list = (4 5 2 3) + +Output: -1 + +=cut diff --git a/challenge-191/robert-dicicco/raku/ch-1.raku b/challenge-191/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..7933d1d3f6 --- /dev/null +++ b/challenge-191/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,87 @@ +use v6; + +=begin comment + +AUTHOR: Robert DiCicco + +DATE: 2022-11-14 + +Challenge 191 Twice Largest ( Raku ) + + + +You are given list of integers, @list. + +Write a script to find out whether the largest item in the + +list is at least twice as large as each of the other items. + +=end comment + + + +my @arr = ([1,2,3,4],[1,2,0,5],[2,6,3,1],[4,5,2,3]); + + + +for (@arr) -> @lst { + + my $result = "good"; + + print("Input: @list = (" ~ @lst ~ ")\n"); + + my $max = @lst.max; + + my @sorted = @lst.sort; + + my $x = 0; + + while ($x < @lst.elems - 1) { + + if ( (2 * (@sorted[$x]) > $max)) { + + say "Output: -1\n"; + + $result = "bad"; + + last; + + } + + $x++; + + } + + if ($result eq "good") { say "Output: 1\n"} + +} + + + +=begin comment + +SAMPLE OUTPUT + +Input: @list = (1 2 3 4) + +Output: -1 + + + +Input: @list = (1 2 0 5) + +Output: 1 + + + +Input: @list = (2 6 3 1) + +Output: 1 + + + +Input: @list = (4 5 2 3) + +Output: -1 + +=end comment diff --git a/challenge-191/robert-dicicco/ruby/ch-1.rb b/challenge-191/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..606784214b --- /dev/null +++ b/challenge-191/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,91 @@ +#!/usr/bin/env ruby + +=begin + +AUTHOR: Robert DiCicco + +DATE: 2022-11-14 + +Challenge 191 Twice Largest ( Ruby ) + + + +You are given list of integers, @list. + +Write a script to find out whether the largest item in the + +list is at least twice as large as each of the other items. + +=end + + + +arr = [[1,2,3,4],[1,2,0,5],[2,6,3,1],[4,5,2,3]] + + + +arr.each do |lst| + + result = "good" + + print("Input: @list = #{lst}\n"); + + max = lst.max() + + lst = lst.sort! + + x = 0 + + while (x < lst.length()-1) + + if ( (2 * (lst[x]) > max)) + + puts "Output: -1\n\n" + + result = "bad" + + break + + end + + x += 1 + + end + + if (result.eql? "good") + + puts "Output: 1\n\n" + + end + +end + + + +=begin + +SAMPLE OUTPUT + +Input: @list = [1, 2, 3, 4] + +Output: -1 + + + +Input: @list = [1, 2, 0, 5] + +Output: 1 + + + +Input: @list = [2, 6, 3, 1] + +Output: 1 + + + +Input: @list = [4, 5, 2, 3] + +Output: -1 + +=end diff --git a/challenge-191/robert-dicicco/tcl/ch-1.tcl b/challenge-191/robert-dicicco/tcl/ch-1.tcl new file mode 100644 index 0000000000..ae38c0003d --- /dev/null +++ b/challenge-191/robert-dicicco/tcl/ch-1.tcl @@ -0,0 +1,97 @@ +#!/usr/bin/env tclsh + + + +set comment { + + AUTHOR: Robert DiCicco + + DATE: 2022-11-14 + + Challenge 191 Twice Largest ( Tcl ) + + + + You are given list of integers, @list. + + Write a script to find out whether the largest item in the + + list is at least twice as large as each of the other items. + +} + + + +set arr {{1 2 3 4} {1 2 0 5} {2 6 3 1} {4 5 2 3}} + + + +foreach lst $arr { + + puts "Input: @list = \($lst\)" + + set max [tcl::mathfunc::max {*}$lst] + + set result "good" + + set lst [lsort $lst] + + set x 0 + + set len [llength $lst] + + while { $x < $len - 1} { + + set dubl [expr { 2 * [lindex $lst $x]}] + + if {$dubl > $max} { + + puts "Output: -1\n" + + set result "bad" + + break + + } + + incr x + + } + + if {$result eq "good"} { puts "Output: 1\n" } + +} + + + +set comment { + + + +SAMPLE OUTPUT + +Input: @list = (1 2 3 4) + +Output: -1 + + + +Input: @list = (1 2 0 5) + +Output: 1 + + + +Input: @list = (2 6 3 1) + +Output: 1 + + + +Input: @list = (4 5 2 3) + +Output: -1 + + + +} |
