aboutsummaryrefslogtreecommitdiff
path: root/challenge-215
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-02 17:08:02 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-02 17:08:02 +0100
commitfc8013d400fee6ab06de6dc4da285d877b3eb555 (patch)
treeb396e4a4c039a88053b43b9994b7b0b6f5ad746b /challenge-215
parent30c20702df85ea5c5c9470634fedbeb954360884 (diff)
downloadperlweeklychallenge-club-fc8013d400fee6ab06de6dc4da285d877b3eb555.tar.gz
perlweeklychallenge-club-fc8013d400fee6ab06de6dc4da285d877b3eb555.tar.bz2
perlweeklychallenge-club-fc8013d400fee6ab06de6dc4da285d877b3eb555.zip
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-215')
-rwxr-xr-xchallenge-215/eric-cheung/python/ch-1.py16
-rwxr-xr-xchallenge-215/eric-cheung/python/ch-2.py26
-rw-r--r--challenge-215/robert-dicicco/julia/ch-1.jl40
-rw-r--r--challenge-215/robert-dicicco/perl/ch-1.pl41
-rw-r--r--challenge-215/robert-dicicco/python/ch-1.py34
-rw-r--r--challenge-215/robert-dicicco/raku/ch-1.raku38
-rw-r--r--challenge-215/robert-dicicco/ruby/ch-1.rb40
-rw-r--r--challenge-215/ziameraj16/java/OddOneOut.java24
8 files changed, 259 insertions, 0 deletions
diff --git a/challenge-215/eric-cheung/python/ch-1.py b/challenge-215/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..1398ab8a04
--- /dev/null
+++ b/challenge-215/eric-cheung/python/ch-1.py
@@ -0,0 +1,16 @@
+
+## arrWordInput = ['abc', 'xyz', 'tsu'] ## Example 1
+## arrWordInput = ['rat', 'cab', 'dad'] ## Example 2
+arrWordInput = ['x', 'y', 'z'] ## Example 3
+
+arrRemovedWord = []
+
+for strWordLoop in arrWordInput:
+
+ strSortWordLoop = ''.join(sorted(strWordLoop))
+ if strWordLoop == strSortWordLoop:
+ continue
+
+ arrRemovedWord.append(strWordLoop)
+
+print (len(arrRemovedWord))
diff --git a/challenge-215/eric-cheung/python/ch-2.py b/challenge-215/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..8c366a73f6
--- /dev/null
+++ b/challenge-215/eric-cheung/python/ch-2.py
@@ -0,0 +1,26 @@
+
+## Example 1
+## arrNum = [1, 0, 0, 0, 1]
+## nCount = 1
+
+## Example 2
+## arrNum = [1, 0, 0, 0, 1]
+## nCount = 2
+
+## Example 3
+arrNum = [1, 0, 0, 0, 0, 0, 0, 0, 1]
+nCount = 3
+
+for nIndxLoop in range(1, len(arrNum) - 1):
+
+ if nCount == 0:
+ break
+
+ if arrNum[nIndxLoop - 1] == 0 and arrNum[nIndxLoop] == 0 and arrNum[nIndxLoop + 1] == 0:
+ arrNum[nIndxLoop] = 1
+ nCount = nCount - 1
+
+if nCount == 0:
+ print (1)
+else:
+ print (0)
diff --git a/challenge-215/robert-dicicco/julia/ch-1.jl b/challenge-215/robert-dicicco/julia/ch-1.jl
new file mode 100644
index 0000000000..74c9ca9849
--- /dev/null
+++ b/challenge-215/robert-dicicco/julia/ch-1.jl
@@ -0,0 +1,40 @@
+#!/usr/bin/env julia
+#=
+----------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-01
+Challenge 215 Odd One Out ( Julia )
+----------------------------------------
+=#
+using Printf
+
+words = [["abc","xyz","tsu"],["rat", "cab", "dad"],["x", "y", "z"]]
+
+for wds in words
+ cnt = 0
+ @printf("Input: @words = %s\n",wds)
+ for w in wds
+ str1_arr = join(sort(collect(w)))
+ if (cmp(w,str1_arr) != 0)
+ cnt += 1
+ end
+ end
+ @printf("Output: %d\n\n", cnt)
+end
+
+#=
+----------------------------------------
+SAMPLE OUTPUT
+julia .\OddOneOut.jl
+Input: @words = ["abc", "xyz", "tsu"]
+Output: 1
+
+Input: @words = ["rat", "cab", "dad"]
+Output: 3
+
+Input: @words = ["x", "y", "z"]
+Output: 0
+----------------------------------------
+=#
+
+
diff --git a/challenge-215/robert-dicicco/perl/ch-1.pl b/challenge-215/robert-dicicco/perl/ch-1.pl
new file mode 100644
index 0000000000..5e2b7f6ea8
--- /dev/null
+++ b/challenge-215/robert-dicicco/perl/ch-1.pl
@@ -0,0 +1,41 @@
+#!/usr/bin/enc perl
+=begin pod
+----------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-01
+Challenge 215 Odd One Out ( Perl )
+----------------------------------------
+=cut
+use strict;
+use warnings;
+use feature 'say';
+
+my @words = (["abc", "xyz", "tsu"],["rat", "cab", "dad"],["x", "y", "z"]);
+
+for my $wds (@words) {
+ my $cnt = 0;
+ say "Input: \@words = (@$wds)";
+ for my $w (@$wds) {
+ my $w_sorted = join("",sort(split(//,$w)));
+ $cnt++ if ($w ne $w_sorted);
+ }
+ say "Output: $cnt\n";
+}
+
+=begin pod
+----------------------------------------
+SAMPLE OUTPUT
+perl .\OddOneOut.pl
+Input: @words = (abc xyz tsu)
+Output: 1
+
+Input: @words = (rat cab dad)
+Output: 3
+
+Input: @words = (x y z)
+Output: 0
+----------------------------------------
+=cut
+
+
+
diff --git a/challenge-215/robert-dicicco/python/ch-1.py b/challenge-215/robert-dicicco/python/ch-1.py
new file mode 100644
index 0000000000..158c58097c
--- /dev/null
+++ b/challenge-215/robert-dicicco/python/ch-1.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+'''
+----------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-01
+Challenge 215 Odd One Out ( Python )
+----------------------------------------
+'''
+
+words = [["abc","xyz","tsu"],["rat", "cab", "dad"],["x", "y", "z"]]
+
+for wds in words:
+ cnt = 0
+ print("Input: @words = ",wds)
+ for w in wds:
+ w_sorted = ''.join(sorted(w, key=str.lower))
+ if w != w_sorted:
+ cnt += 1
+ print("Output: ",cnt,"\n")
+
+'''
+ ----------------------------------------
+SAMPLE OUTPUT
+python .\OddOneOut.py
+Input: @words = ['abc', 'xyz', 'tsu']
+Output: 1
+Input: @words = ['rat', 'cab', 'dad']
+Output: 3
+Input: @words = ['x', 'y', 'z']
+Output: 0
+ ----------------------------------------
+'''
+
+
diff --git a/challenge-215/robert-dicicco/raku/ch-1.raku b/challenge-215/robert-dicicco/raku/ch-1.raku
new file mode 100644
index 0000000000..c14bf8604c
--- /dev/null
+++ b/challenge-215/robert-dicicco/raku/ch-1.raku
@@ -0,0 +1,38 @@
+#!/usr/bin/env raku
+#`{
+----------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-01
+Challenge 215 Odd One Out ( Raku )
+----------------------------------------
+}
+my @words = ('abc', 'xyz', 'tsu'),('rat', 'cab', 'dad'),('x', 'y', 'z');
+
+for (@words) -> @wds {
+ my $cnt = 0;
+ say "Input: \@words = ", @wds;
+ for (@wds) -> $w {
+ if $w ne $w.comb.sort.join {
+ $cnt++;
+ }
+ }
+ say "Output: ", $cnt;
+ say " ";
+}
+
+#`{
+----------------------------------------
+SAMPLE OUTPUT
+raku .\OddOneOut.rk
+Input: @words = (abc xyz tsu)
+Output: 1
+
+Input: @words = (rat cab dad)
+Output: 3
+
+Input: @words = (x y z)
+Output: 0
+}
+
+
+
diff --git a/challenge-215/robert-dicicco/ruby/ch-1.rb b/challenge-215/robert-dicicco/ruby/ch-1.rb
new file mode 100644
index 0000000000..acf5ca9845
--- /dev/null
+++ b/challenge-215/robert-dicicco/ruby/ch-1.rb
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+=begin
+----------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-05-01
+Challenge 215 Odd One Out ( Ruby )
+----------------------------------------
+=end
+
+words = [["abc","xyz","tsu"],["rat", "cab", "dad"],["x", "y", "z"]]
+
+words.each do |wds|
+ cnt = 0
+ puts("Input: @words = #{wds}")
+ wds.each do |w|
+ srt = w.chars.sort.join
+ if w != srt
+ cnt += 1
+ end
+ end
+ puts("Output: #{cnt}")
+ puts
+end
+
+=begin
+----------------------------------------
+SAMPLE OUTPUT
+ruby .\OddOneOut.rb
+Input: @words = ["abc", "xyz", "tsu"]
+Output: 1
+
+Input: @words = ["rat", "cab", "dad"]
+Output: 3
+
+Input: @words = ["x", "y", "z"]
+Output: 0
+----------------------------------------
+=end
+
+
diff --git a/challenge-215/ziameraj16/java/OddOneOut.java b/challenge-215/ziameraj16/java/OddOneOut.java
new file mode 100644
index 0000000000..bbd53574b7
--- /dev/null
+++ b/challenge-215/ziameraj16/java/OddOneOut.java
@@ -0,0 +1,24 @@
+import java.util.*;
+
+public class OddOneOut {
+
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ List<String> values = Arrays.stream(scanner.nextLine().split(",")).toList();
+ int count = 0;
+ List<String> newList = new ArrayList<>(values.size());
+ for (String str : values) {
+ String temp = new String(str);
+ final char[] chars = str.toCharArray();
+ Arrays.sort(chars);
+ if (!temp.equals(new String(chars))) {
+ count++;
+ } else {
+ newList.add(str);
+ }
+ }
+ System.out.println(count);
+ System.out.println(newList);
+ }
+}
+