aboutsummaryrefslogtreecommitdiff
path: root/challenge-193
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-193')
-rw-r--r--challenge-193/robert-dicicco/python/ch-2.py85
-rw-r--r--challenge-193/robert-dicicco/raku/ch-2.raku103
-rw-r--r--challenge-193/robert-dicicco/ruby/ch-2.rb95
3 files changed, 283 insertions, 0 deletions
diff --git a/challenge-193/robert-dicicco/python/ch-2.py b/challenge-193/robert-dicicco/python/ch-2.py
new file mode 100644
index 0000000000..d0ce4b5e98
--- /dev/null
+++ b/challenge-193/robert-dicicco/python/ch-2.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+# AUTHOR: Robert DiCicco
+
+# DATE: 2022-11-30
+
+# Challenge 193 Odd String ( Python )
+
+
+# You are given a list of strings of same length, @s.
+
+
+# Write a script to find the odd string in the given list. Use positional value of alphabet starting with 0, i.e. a = 0, b = 1, ... z = 25.
+
+
+# Find the difference array for each string as shown in the example. Then pick the odd one out.
+
+# ------------------------------------------------------------
+
+# SAMPLE OUTPUT
+
+# python .\OddString.py
+
+# Input: @s = ['adc', 'wzy', 'abc']
+
+# Output: abc
+
+
+# Input: @s = ['aaa', 'bob', 'ccc', 'ddd']
+
+# Output: bob
+
+
+ss = [["adc", "wzy", "abc"],["aaa", "bob", "ccc", "ddd"]]
+
+mylist = []
+
+
+def StringValue(s) :
+
+ global mylist
+
+ v1 = ord(s[1]) - ord(s[0])
+
+ v2 = ord(s[2]) - ord(s[1])
+
+ saved = f"{v1},{v2}"
+
+ mylist.append(saved)
+
+
+def main() :
+
+ for i in ss :
+
+ print(f"Input: @s = {i}")
+
+ global mylist
+
+ for x in range(len(i)) :
+
+ StringValue(i[x])
+
+ for x in range(len(i)) :
+
+ cnt = mylist.count(mylist[x])
+
+ if cnt == 1 :
+
+ print(f"Output: {i[x]}\n")
+
+ mylist = []
+
+
+
+if __name__ == '__main__':
+
+ main()
diff --git a/challenge-193/robert-dicicco/raku/ch-2.raku b/challenge-193/robert-dicicco/raku/ch-2.raku
new file mode 100644
index 0000000000..1df02ab0e7
--- /dev/null
+++ b/challenge-193/robert-dicicco/raku/ch-2.raku
@@ -0,0 +1,103 @@
+#!/usr/bin/env raku
+
+=begin comment
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-11-30
+
+Challenge 193 Odd String ( Raku )
+
+
+You are given a list of strings of same length, @s.
+
+
+Write a script to find the odd string in the given list. Use positional value of alphabet starting with 0, i.e. a = 0, b = 1, ... z = 25.
+
+
+Find the difference array for each string as shown in the example. Then pick the odd one out.
+
+------------------------------------------------------------
+
+SAMPLE OUTPUT
+
+
+raku .\OddString.rk
+
+Input: @n = [adc wzy abc]
+
+Output: abc
+
+
+Input: @n = [aaa bob ccc ddd]
+
+Output: bob
+
+
+=end comment
+
+
+use v6;
+
+
+my @ss = [["adc", "wzy", "abc"],["aaa", "bob", "ccc", "ddd"]];
+
+my @out = [];
+
+
+sub StringValue($mystr) {
+
+ my $val1 = substr($mystr,1,1);
+
+ my $val0 = substr($mystr,0,1);
+
+ my $val2 = substr($mystr,2,1);
+
+ my $x = ord($val1) - ord($val0);
+
+ my $y = ord($val2) - ord($val1);
+
+ push(@out, "$x:$y");
+
+}
+
+
+sub MAIN() {
+
+ for @ss -> @n {
+
+ put "Input: @n = \[" ~ @n ~ "]";
+
+ for 0..(@n.elems - 1) -> $x {
+
+ StringValue(@n[$x]);
+
+ }
+
+ for 0..(@n.elems - 1) -> $x {
+
+ my $cnt = @out.grep(@out[$x]).elems;
+
+ if $cnt == 1 {
+
+ print("Output: @n[$x]\n\n");
+
+ }
+
+ }
+
+ @out = [];
+
+ }
+
+}
diff --git a/challenge-193/robert-dicicco/ruby/ch-2.rb b/challenge-193/robert-dicicco/ruby/ch-2.rb
new file mode 100644
index 0000000000..90bdb90f28
--- /dev/null
+++ b/challenge-193/robert-dicicco/ruby/ch-2.rb
@@ -0,0 +1,95 @@
+#!/usr/bin/env ruby
+
+=begin
+
+AUTHOR: Robert DiCicco
+
+DATE: 2022-11-30
+
+Challenge 193 Odd String ( Ruby )
+
+
+You are given a list of strings of same length, @s.
+
+
+Write a script to find the odd string in the given list. Use positional value of alphabet starting with 0, i.e. a = 0, b = 1, ... z = 25.
+
+
+Find the difference array for each string as shown in the example. Then pick the odd one out.
+
+------------------------------------------------------------
+
+SAMPLE OUTPUT
+
+ruby .\OddString.rb
+
+Input: ["adc", "wzy", "abc"]
+
+Output: abc
+
+
+Input: ["aaa", "bob", "ccc", "ddd"]
+
+Output: bob
+
+=end
+
+
+ss = [["adc", "wzy", "abc"],["aaa", "bob", "ccc", "ddd"]]
+
+
+$myout = []
+
+
+def StringValue(s)
+
+ v1 = s[1].ord - s[0].ord
+
+ v2 = s[2].ord - s[1].ord
+
+ saved = "#{v1},#{v2}"
+
+ $myout.push(saved)
+
+end
+
+
+ss.each do |i|
+
+ ln = i.length() # i = ssubarray length
+
+ puts("Input: #{i}")
+
+ (0..ln-1).each do |x|
+
+ StringValue(i[x]) # record value for each string
+
+ end
+
+ (0..i.length-1).each do |alen|
+
+ c = $myout.count($myout[alen])
+
+ if c == 1
+
+ puts("Output: #{i[alen]}")
+
+ break
+
+ end
+
+ end
+
+ puts(" ")
+
+ $myout = []
+
+end