diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-03-08 23:32:11 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-03-08 23:32:11 +0000 |
| commit | a0ea2c78c8ac2bb33fb79ab151f86b3beb143647 (patch) | |
| tree | 41cbffecd69bd6774b09657b5702f620154cf9cb /challenge-207/robert-dicicco | |
| parent | bc577f09f07be6abd72291c3e9a6642e4336d9c9 (diff) | |
| download | perlweeklychallenge-club-a0ea2c78c8ac2bb33fb79ab151f86b3beb143647.tar.gz perlweeklychallenge-club-a0ea2c78c8ac2bb33fb79ab151f86b3beb143647.tar.bz2 perlweeklychallenge-club-a0ea2c78c8ac2bb33fb79ab151f86b3beb143647.zip | |
- Added solutions by Avery Adams.
- Added solutions by Jaldhar H. Vyas.
- Added solutions by Mark Anderson.
- Added solutions by Luca Ferrari.
- Added solutions by Peter Campbell Smith.
- Added solutions by W. Luis Mochan.
- Added solutions by Paulo Custodio.
- Added solutions by Cheok-Yin Fung.
- Added solutions by E. Choroba.
- Added solutions by Bob Lied.
- Added solutions by Robbie Hatley.
- Added solutions by Matthias Muth.
- Added solutions by Lubos Kolouch.
- Added solutions by Solathian.
- Added solutions by Duncan C. White.
- Added solutions by Kjetil Skotheim.
- Added solutions by Marton Polgar.
- Added solutions by David Ferrone.
- Added solutions by Mariano Spadaccini.
- Added solutions by Robert DiCicco.
- Added solutions by Ulrich Rieke.
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-207/robert-dicicco')
| -rw-r--r-- | challenge-207/robert-dicicco/julia/ch-1.jl | 55 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/julia/ch-2.jl | 44 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/perl/ch-1.pl | 66 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/perl/ch-2.pl | 47 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/python/ch-1.py | 47 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/python/ch-2.py | 37 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/raku/ch-1.raku | 58 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/raku/ch-2.raku | 47 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/ruby/ch-1.rb | 59 | ||||
| -rw-r--r-- | challenge-207/robert-dicicco/ruby/ch-2.rb | 43 |
10 files changed, 503 insertions, 0 deletions
diff --git a/challenge-207/robert-dicicco/julia/ch-1.jl b/challenge-207/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..d7f7f7071b --- /dev/null +++ b/challenge-207/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,55 @@ +#!/usr/bin/env julia +#= +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-06 +Challenge 207 Keyboard Word ( Julia ) +-------------------------------------- +=# +using Printf + +rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"] +words = ["Hello", "Alaska", "Dad", "Peace"], ["OMG", "Bye"] +flag = 0 + +function CheckLetters(w) + ln = length(w) + for j in 1:3 + flag = 0 + for x in 1:ln + if (occursin(w[x], rows[j])) + else + flag = 1 + end + end + if (flag == 0) + @printf("\t%s\n",w) + flag = 0 + end + end +end + +for wds in words + @printf("Input: @words = %s\n",wds) + println("Output:") + ln = length(wds) + for j in 1:ln + CheckLetters(lowercase(wds[j])) + end + println(" ") +end + +#= +-------------------------------------- +SAMPLE OUTPUT +julia .\KeyboardWord.jl +Input: @words = ["Hello", "Alaska", "Dad", "Peace"] +Output: + alaska + dad + +Input: @words = ["OMG", "Bye"] +Output: + +-------------------------------------- +=# diff --git a/challenge-207/robert-dicicco/julia/ch-2.jl b/challenge-207/robert-dicicco/julia/ch-2.jl new file mode 100644 index 0000000000..e5f96509b4 --- /dev/null +++ b/challenge-207/robert-dicicco/julia/ch-2.jl @@ -0,0 +1,44 @@ +#!/usr/bin/env julia +#= +---------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-07 +Challenge 207 H-Index ( Julia ) +---------------------------------- +=# +using Printf + +citations = [10,8,5,4,3],[25,8,5,3,3] + +function CalcIndex(c) + ln = length(c) + offset = ln + pos = ln + while offset >= 1 + if c[offset] >= pos + @printf("Output: %d\n", pos) + println(" ") + return + else + offset -= 1 + pos -= 1 + end + end +end + +for c in citations + @printf("Input: @citations = %s\n",c) + CalcIndex(c) +end + +#= +---------------------------------- +SAMPLE OUTPUT +julia .\HIndex.jl +Input: @citations = [10, 8, 5, 4, 3] +Output: 4 + +Input: @citations = [25, 8, 5, 3, 3] +Output: 3 +---------------------------------- +=# diff --git a/challenge-207/robert-dicicco/perl/ch-1.pl b/challenge-207/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..4f74af30e4 --- /dev/null +++ b/challenge-207/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +=begin comment +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-06 +Challenge 207 Keyboard Word ( Perl ) +-------------------------------------- +=cut +use strict; +use warnings; +use feature 'say'; + +my @rows = ("qwertyuiop", "asdfghjkl", "zxcvbnm"); +my @words = ("Hello Alaska Dad Peace", "OMG Bye"); + +sub do_nothing { + return; +} + +sub CheckLetters { + my $w = shift; + $w = lc($w); + my $flag = 0; + my $ln = length($w); + for my $ndx (0..2) { + for my $c (0..$ln-1) { + my $z = substr($w,$c,1); + if($rows[$ndx] =~ /$z/) { + do_nothing; + } else { + $flag = 1; + } + } + if ($flag == 0) { + say "\t$w"; + } + $flag = 0; + } +} + +for my $wds (@words) { + say "Input: \@array = [$wds]"; + say "Output: "; + my @split_words = split(" ",$wds); + foreach (@split_words) { + CheckLetters($_); + } + say " "; +} + +=begin comment +-------------------------------------- +SAMPLE OUTPUT +perl .\KeyboardWord.pl +Input: @array = [Hello Alaska Dad Peace] +Output: + alaska + dad + +Input: @array = [OMG Bye] +Output: + +-------------------------------------- +=cut + + diff --git a/challenge-207/robert-dicicco/perl/ch-2.pl b/challenge-207/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..5f4afcee9c --- /dev/null +++ b/challenge-207/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,47 @@ +#!/usr/bin/env perl +=begin comment +---------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-07 +Challenge 207 H-Index ( Perl ) +================================== +=cut +use strict; +use warnings; +use feature "say"; + +my @citations = ([10,8,5,4,3],[25,8,5,3,3]); + +sub CalcIndex { + my $arr = shift; + my $ln = scalar(@$arr); + my $offset = $ln; + $offset = $ln-1; + my $pos = $ln; + while($offset >= 0) { + if(@$arr[$offset] >= $pos){ + say "Output: $pos\n"; + return; + } else { + $offset--; + $pos--; + } + } +} + +for my $c (@citations) { + say "Input: \@citations = [@$c]"; + CalcIndex($c); +} + +=begin comment +================================== +SAMPLE OUTPUT +perl .\HIndex.pl +Input: @citations = [10 8 5 4 3] +Output: 4 + +Input: @citations = [25 8 5 3 3] +Output: 3 +================================== +=cut diff --git a/challenge-207/robert-dicicco/python/ch-1.py b/challenge-207/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..850c89b0ce --- /dev/null +++ b/challenge-207/robert-dicicco/python/ch-1.py @@ -0,0 +1,47 @@ +#/usr/bin/env python +''' +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-06 +Challenge 207 Keyboard Word ( Python ) +-------------------------------------- +''' + +rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"] +words = ["Hello", "Alaska", "Dad", "Peace"], ["OMG", "Bye"] +flag = 0 + +def CheckLetters(w): + ln = len(w) + for j in range(3): + flag = 0 + for x in range(ln): + if (w[x] in rows[j]): + pass + else: + flag = 1 + if flag == 0 : + print("\t",w) + flag = 0 + +for wds in words: + print("Input: @words = ",wds) + print("Output: ") + ln = len(wds) + for j in range(0,ln): + CheckLetters(wds[j].lower()) + print(" ") + +''' +-------------------------------------- +SAMPLE OUTPUT +python .\KeyboardWord.py +Input: @words = ['Hello', 'Alaska', 'Dad', 'Peace'] +Output: + alaska + dad + +Input: @words = ['OMG', 'Bye'] +Output: + +''' diff --git a/challenge-207/robert-dicicco/python/ch-2.py b/challenge-207/robert-dicicco/python/ch-2.py new file mode 100644 index 0000000000..4327ca5d04 --- /dev/null +++ b/challenge-207/robert-dicicco/python/ch-2.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +''' +---------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-07 +Challenge 207 H-Index ( Python ) +================================== +''' +citations = [10,8,5,4,3],[25,8,5,3,3] + +def CalcIndex(c): + ln = len(c) + offset = ln - 1 + pos = ln + while offset >= 0 : + if c[offset] >= pos : + print("Output: ",pos,"\n") + return + else : + offset -= 1 + pos -= 1 + +for c in citations: + print("Input: @citations =",c) + CalcIndex(c) + +''' +---------------------------------- +SAMPLE OUTPUT +python .\HIndex.py +Input: @citations = [10, 8, 5, 4, 3] +Output: 4 + +Input: @citations = [25, 8, 5, 3, 3] +Output: 3 +---------------------------------- +''' diff --git a/challenge-207/robert-dicicco/raku/ch-1.raku b/challenge-207/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..ee2093a26c --- /dev/null +++ b/challenge-207/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,58 @@ +#!/usr/bin/env raku +#`( +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-06 +Challenge 207 Keyboard Word ( Raku ) +-------------------------------------- +) + +use v6; + +my @rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]; +my @words = [["Hello Alaska Dad Peace"], ["OMG Bye"]]; + +sub CheckLetters($tw is copy) { + my $flag = 0; + $tw=$tw.lc; + for 0..2 -> $ndx { + for 0..$tw.chars-1 -> $c { + my $z = substr($tw,$c,1); + (@rows[$ndx].contains($z)) ?? (next) !! ($flag = 1); + } + if $flag == 0 { say "\t$tw" }; + $flag = 0; + } +} + +sub GetWords(@wds) { + my $ln = @wds.elems; + my @tw = @wds.split(' '); + for 0..$ln-1 -> $i { + my $test_word = @tw[$i]; + CheckLetters($test_word); + } + say " "; +} + +for (@words) -> @w { + say "Input: \@words = ",@w; + say "Output: "; + my @test_words = @w.split(' '); + GetWords(@test_words); +} + +#`( +-------------------------------------- +SAMPLE OUTPUT + raku .\KeyboardWord.rk +Input: @words = [Hello Alaska Dad Peace] +Output: + alaska + dad + +Input: @words = [OMG Bye] +Output: + +-------------------------------------- +) diff --git a/challenge-207/robert-dicicco/raku/ch-2.raku b/challenge-207/robert-dicicco/raku/ch-2.raku new file mode 100644 index 0000000000..754c3266d5 --- /dev/null +++ b/challenge-207/robert-dicicco/raku/ch-2.raku @@ -0,0 +1,47 @@ +#!/usr/bin/env raku +#`( +---------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-07 +Challenge 207 H-Index ( Raku) +================================== +) +use v6; + +my @citations = ([10,8,5,4,3],[25,8,5,3,3]); + +sub CalcIndex(@c) { + my $ln = @c.elems; + my $offset = $ln; + $offset = $ln-1; + my $pos = $ln; + while $offset >= 0 { + if @c[$offset] >= $pos { + say "Output: $pos\n"; + return; + } else { + $offset--; + $pos--; + } + } + +} + +for (@citations) -> @c { + say "Input: \@citations = ",@c; + CalcIndex(@c); +} + +#`( +---------------------------------- +SAMPLE OUTPUT + raku .\HIndex.rk +Input: @citations = [10 8 5 4 3] +Output: 4 + +Input: @citations = [25 8 5 3 3] +Output: 3 +---------------------------------- +) + + diff --git a/challenge-207/robert-dicicco/ruby/ch-1.rb b/challenge-207/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..c709241a3c --- /dev/null +++ b/challenge-207/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,59 @@ +#!/usr/bin/env ruby +=begin +-------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-06 +Challenge 207 Keyboard Word ( Ruby ) +-------------------------------------- +=end + +$rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"] +words = [["Hello Alaska Dad Peace"], ["OMG Bye"]] +$flag = 0 + +def CheckLetters(w) + w = w.downcase # convert to lc + ln = w.length + (0..2).each do |str| + $flag = 0 + (0..ln-1).each do |x| + unless $rows[str].include? w[x] + $flag += 1 + end + end + if ($flag == 0) + puts("\t#{w}") + end + end + end + +def GetWords(tws) + tws.each do |tw| + tw.delete! '[]\"' + #puts("#{tw}") + CheckLetters(tw) + end + puts(" ") +end + +words.each do |wds| + puts("Input: @words = #{wds}") + puts("Output: ") + test_words = wds.to_s.split + GetWords(test_words) +end +=begin +------------------------------------------ +SAMPLE OUTPUT +ruby .\KeyboardWord.rb +Input: @words = ["Hello Alaska Dad Peace"] +Output: + alaska + dad + +Input: @words = ["OMG Bye"] +Output: +------------------------------------------- +=end + + diff --git a/challenge-207/robert-dicicco/ruby/ch-2.rb b/challenge-207/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..5e14ff6860 --- /dev/null +++ b/challenge-207/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby +=begin +---------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-03-07 +Challenge 207 H-Index ( Ruby) +================================== +=end + +citations = [10,8,5,4,3],[25,8,5,3,3] + +def CalcIndex(c) + ln = c.length() + offset = ln - 1 + pos = ln + while offset >= 0 + if c[offset] >= pos + puts("Output: #{pos}") + puts + return + else + offset -= 1 + pos -= 1 + end + end +end + +citations.each do |c| + puts("Input: @citations = #{c}") + CalcIndex(c) +end + +=begin +================================== +SAMPLE OUTPUT +ruby .\HIndex.rb +Input: @citations = [10, 8, 5, 4, 3] +Output: 4 + +Input: @citations = [25, 8, 5, 3, 3] +Output: 3 +================================== +=end |
