diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2023-05-10 17:09:33 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2023-05-10 17:09:33 +0100 |
| commit | bb52405967e3387c63e9fffd0a2bd82678882f40 (patch) | |
| tree | 88eba058d26136d2a86dcc77982f42cdc245bdf6 /challenge-216/robert-dicicco | |
| parent | 2e943784a5c321b375ba33ab415a70dcf030b61c (diff) | |
| parent | 722527ed475e56e5717e60f8d3b52d9bbcef492c (diff) | |
| download | perlweeklychallenge-club-bb52405967e3387c63e9fffd0a2bd82678882f40.tar.gz perlweeklychallenge-club-bb52405967e3387c63e9fffd0a2bd82678882f40.tar.bz2 perlweeklychallenge-club-bb52405967e3387c63e9fffd0a2bd82678882f40.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-216/robert-dicicco')
| -rw-r--r-- | challenge-216/robert-dicicco/julia/ch-1.jl | 61 | ||||
| -rw-r--r-- | challenge-216/robert-dicicco/perl/ch-1.pl | 61 | ||||
| -rw-r--r-- | challenge-216/robert-dicicco/python/ch-1.py | 48 | ||||
| -rw-r--r-- | challenge-216/robert-dicicco/raku/ch-1.raku | 58 | ||||
| -rw-r--r-- | challenge-216/robert-dicicco/ruby/ch-1.rb | 60 |
5 files changed, 288 insertions, 0 deletions
diff --git a/challenge-216/robert-dicicco/julia/ch-1.jl b/challenge-216/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..477f717ce3 --- /dev/null +++ b/challenge-216/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,61 @@ +#!/usr/bin/env julia +#= +-------------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-08 +Challenge 216 Registration Number ( Julia ) +-------------------------------------------- +=# +using Printf + +words = [["abc", "abcd", "bcd", "AB1 2CD"], ["job", "james", "bjorg", "007 JB"], ["crack", "road", "rac", "C7 RA2"]] + +flag = 0 +out = [] + +function CheckWords(wd, rg) + arr = split(rg,"") + flag = 0 + for lett in arr + if ! occursin(lett, wd) + flag = 1 + end + end + if flag == 0 + push!(out, wd) + end +end + +for wds in words + global out + len = length(wds) + + reg = wds[end] + @printf("Input: @words = %s, \$reg = %s\n", wds[begin:end-1],reg) + r = r"0|1|2|3|4|5|6|7|8|9| " + reg = lowercase(replace(reg,r => "" )) + x = 1 + while x < len + CheckWords(wds[x], reg) + x += 1 + end + println("Output: ["*join(out,",")*"]\n") + out = [] +end + +#= +-------------------------------------------- +SAMPLE OUTPUT +julia .\Registration.jl +Input: @words = ["abc", "abcd", "bcd"], $reg = AB1 2CD +Output: [abcd] + +Input: @words = ["job", "james", "bjorg"], $reg = 007 JB +Output: [job,bjorg] + +Input: @words = ["crack", "road", "rac"], $reg = C7 RA2 +Output: [crack,rac] +-------------------------------------------- +=# + + diff --git a/challenge-216/robert-dicicco/perl/ch-1.pl b/challenge-216/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..4450672b23 --- /dev/null +++ b/challenge-216/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,61 @@ +#!/usr/bin/env perl +=begin comment +-------------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-08 +Challenge 216 Registration Number ( Perl ) +-------------------------------------------- +=cut +use strict; +use warnings; +use feature 'say'; + +my @words = (['abc', 'abcd', 'bcd', 'AB1 2CD'], ['job', 'james', 'bjorg', '007 JB'], ['crack', 'road', 'rac', 'C7 RA2']); + +my @out = (); + +sub CheckWords { + my $wd = shift; # word to be checked + my $rg = shift; # registration + my @arr = split("",$rg); # split the registration into chars + my $flag = 0; # the match flag, set to 1 if reg char is not in word + foreach my $let (@arr) { + if ($wd !~ /$let/) { + $flag = 1; # set flag to 1 if no match + } + } + push(@out, $wd) if ($flag == 0); # save word if all match +} + +for (@words) { + my @wds = @{$_}; # get list of words + my $len = scalar @wds; # and its length + print("Input: @wds[0..($len-2)], "); + my $reg = $wds[$len - 1]; # registration is last entry in words + print(" \$reg = $reg\n"); + $reg =~ tr/A-Z/a-z/; # convert all to lower case + $reg =~ tr/0-9 //d; # remove spaces and numbers + for (my $x = 0; $x < $len - 1;$x++) { + CheckWords($wds[$x],$reg); + } + print("Output: @out\n\n"); + @out = (); + } + +=begin comment + -------------------------------------------- + SAMPLE OUTPUT +perl .\Registration.pl +Input: abc abcd bcd, $reg = AB1 2CD +Output: abcd + +Input: job james bjorg, $reg = 007 JB +Output: job bjorg + +Input: crack road rac, $reg = C7 RA2 +Output: crack rac +-------------------------------------------- +=cut + + + diff --git a/challenge-216/robert-dicicco/python/ch-1.py b/challenge-216/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..1e3344bd90 --- /dev/null +++ b/challenge-216/robert-dicicco/python/ch-1.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# ------------------------------------------ +# AUTHOR: Robert DiCicco +# DATE : 2023-05-09 +# Challenge 216 Registration Number ( Python ) +# ------------------------------------------ + +words = [["abc", "abcd", "bcd", "AB1 2CD"], ["job", "james", "bjorg", "007 JB"], ["crack", "road", "rac", "C7 RA2"]] +out = [] + +def CheckWords(wd, rg): + flag = 0 + arr = [x for x in rg] + for lett in arr: + if wd.count(lett) == 0: + flag = 1 + if flag == 0: + out.append(wd) + +for wds in words: + wds_only = wds[0:-1] + reg = wds[-1] + print("Input: ",wds_only,", $reg = ", reg) + reg = reg.translate({ord(i): None for i in '1234567890 '}).lower() + x = 0 + cnt = len(wds) - 1 + while x < cnt: + CheckWords(wds[x],reg) + x += 1 + print("Output: ",out,"\n") + out = [] + +# ------------------------------------------ +# SAMPLE OUTPUT +# python .\Registration.py +# Input: ['abc', 'abcd', 'bcd'] , $reg = AB1 2CD +# Output: ['abcd'] + +# Input: ['job', 'james', 'bjorg'] , $reg = 007 JB +# Output: ['job', 'bjorg'] + +# Input: ['crack', 'road', 'rac'] , $reg = C7 RA2 +# Output: ['crack', 'rac'] +# ------------------------------------------ + + + + diff --git a/challenge-216/robert-dicicco/raku/ch-1.raku b/challenge-216/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..3be62a7fea --- /dev/null +++ b/challenge-216/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,58 @@ +#!/usr/bin/env raku +=begin comment +-------------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-08 +Challenge 216 Registration Number ( Raku ) +-------------------------------------------- +=end comment + +use v6; + +my @words = ('abc', 'abcd', 'bcd', 'AB1 2CD'), ('job', 'james', 'bjorg', '007 JB'), ('crack', 'road', 'rac', 'C7 RA2'); +my @out = (); + +sub CheckWords($wd, $rg) { + my @arr = $rg.comb; + my $flag = 0; + for (@arr) -> $let { + if ($wd !~~ /$let/) { + $flag = 1; # set flag to 1 if no match + } + } + @out.push($wd) if $flag == 0; +} + + +for (@words) -> @wds { + my $reg = @wds.[*-1]; + my $cnt = @wds.elems - 2; + my @wds_only = @wds[0..$cnt]; + print "Input: [",@wds_only,"] \$reg = ",$reg,"\n"; + $reg ~~ tr/A..Z/a..z/; + $reg ~~ s:g/\d|\s//; # remove spaces and numbers + my $x = 0; + while $x <= $cnt { + CheckWords(@wds[$x], $reg); + $x += 1; + } + print("Output: ",@out,"\n\n"); + @out = (); +} + +=begin comment +-------------------------------------------- +SAMPLE OUTPUT +raku .\Registration.rk +Input: [abc abcd bcd] $reg = AB1 2CD +Output: abcd + +Input: [job james bjorg] $reg = 007 JB +Output: job bjorg + +Input: [crack road rac] $reg = C7 RA2 +Output: crack rac +-------------------------------------------- +=end comment + + diff --git a/challenge-216/robert-dicicco/ruby/ch-1.rb b/challenge-216/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..fe5cb76e9d --- /dev/null +++ b/challenge-216/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,60 @@ +#!/usr/bin/env ruby +=begin +-------------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-05-08 +Challenge 216 Registration Number ( Ruby ) +-------------------------------------------- +=end + +@words = [['abc', 'abcd', 'bcd', 'AB1 2CD'], ['job', 'james', 'bjorg', '007 JB'], ['crack', 'road', 'rac', 'C7 RA2']] + +$out = [] +def CheckWords(wd, rg) + arr = rg.split(//) + flag = 0 + arr.each do |lett| + if ! wd.include? lett + flag = 1; # set flag to 1 if no match + end + end + if flag == 0 + $out.push(wd) + end +end + +@words.each do |wds| + $out = [] + len = wds.length() + wds_only = wds.slice(0,len-1) + reg = wds.slice(-1,1) + reg = reg.to_s + reg.delete! '[]"0123456789 ' + reg = reg.to_s.tr('A-Z', 'a-z') + puts("Input: @words = #{wds_only} $reg = #{reg}") + x = 0 + cnt = len - 2 + while x <= cnt + CheckWords(wds_only[x], reg) + x += 1 + end + puts("Output: #{$out}") + puts('') +end + +=begin +-------------------------------------------- +SAMPLE OUTPUT +ruby .\Registration.rb +Input: @words = ["abc", "abcd", "bcd"] $reg = abcd +Output: ["abcd"] + +Input: @words = ["job", "james", "bjorg"] $reg = jb +Output: ["job", "bjorg"] + +Input: @words = ["crack", "road", "rac"] $reg = cra +Output: ["crack", "rac"] +-------------------------------------------- +=end + + |
