diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-01-10 19:20:47 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-01-10 19:20:47 +0000 |
| commit | 13e4a2c007d7a0aac2bd1b8a48aa28003d772dc5 (patch) | |
| tree | 0870305b4bf1ed58b21f6910c71363f4b61a9b4d /challenge-199 | |
| parent | efa24791174b9cb35f0a5bf10881346ca447da47 (diff) | |
| download | perlweeklychallenge-club-13e4a2c007d7a0aac2bd1b8a48aa28003d772dc5.tar.gz perlweeklychallenge-club-13e4a2c007d7a0aac2bd1b8a48aa28003d772dc5.tar.bz2 perlweeklychallenge-club-13e4a2c007d7a0aac2bd1b8a48aa28003d772dc5.zip | |
- Added solutions by Mark Anderson.
- Added solutions by Luca Ferrari.
- Added solutions by Niels van Dijke.
- Added solutions by Mariano Spadaccini.
- Added solutions by Stephen G. Lynn.
- Added solutions by David Ferrone.
- Added solutions by Rawley Fowler.
- Added solutions by Dave Jacoby.
- Added solutions by Thomas Kohler.
- Added solutions by Roger Bell_West.
- Added solutions by E. Choroba.
- Added solutions by W. Luis Mochan.
- Added solutions by Ali Moradi.
- Added solutions by Peter Campbell Smith.
- Added solutions by Bob Lied.
- Added solutions by Robert Ransbottom.
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-199')
| -rw-r--r-- | challenge-199/robert-dicicco/julia/ch-1.jl | 109 | ||||
| -rw-r--r-- | challenge-199/robert-dicicco/perl/ch-1.pl | 113 | ||||
| -rw-r--r-- | challenge-199/robert-dicicco/python/ch-1.py | 95 | ||||
| -rw-r--r-- | challenge-199/robert-dicicco/raku/ch-1.raku | 103 | ||||
| -rw-r--r-- | challenge-199/robert-dicicco/ruby/ch-1.rb | 107 | ||||
| -rw-r--r-- | challenge-199/ziameraj16/java/GoodPairs.java | 20 |
6 files changed, 547 insertions, 0 deletions
diff --git a/challenge-199/robert-dicicco/julia/ch-1.jl b/challenge-199/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..37c3591611 --- /dev/null +++ b/challenge-199/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,109 @@ +#!/usr/bin/env julia + +#= + +AUTHOR: Robert DiCicco + +DATE : 2023-01-09 + +Challenge 199 Good Pairs ( Julia ) + +=# + + + +using Printf + + + +lists = [[1,2,3,1,1,3],[1,2,3],[1,1,1,1]] + +finalCnt = 0 + + + +for list in lists + + global finalCnt + + @printf("Input: @list = %s\n", list) + + beginner = 1 + + ender = length(list) + + cnt = beginner + 1 + + while beginner < ender + + while cnt <= ender + + if list[cnt] == list[beginner] + + @printf("%d,%d\n",beginner-1,cnt-1) + + finalCnt += 1 + + end + + cnt += 1 + + end + + beginner += 1 + + cnt = beginner + 1 + + end + + @printf("Output: %d\n\n", finalCnt) + + finalCnt = 0 + +end + + + +#= + +SAMPLE OUTPUT + +julia .\GoodPairs.jl + +Input: @list = [1, 2, 3, 1, 1, 3] + +0,3 + +0,4 + +2,5 + +3,4 + +Output: 4 + + + +Input: @list = [1, 2, 3] + +Output: 0 + + + +Input: @list = [1, 1, 1, 1] + +0,1 + +0,2 + +0,3 + +1,2 + +1,3 + +2,3 + +Output: 6 + +=# diff --git a/challenge-199/robert-dicicco/perl/ch-1.pl b/challenge-199/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..0d5bad394b --- /dev/null +++ b/challenge-199/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,113 @@ +#!/usr/bin/env perl + +=begin + +AUTHOR: Robert DiCicco + +DATE : 2023-01-09 + +Challenge 199 Good Pairs ( Perl ) + +=cut + + + +use strict; + +use warnings; + +use feature qw/say/; + + + +my @lists = ([1,2,3,1,1,3],[1,2,3],[1,1,1,1]); + +my $finalCnt = 0; + + + +for my $list (@lists) { + + print "Input: \@list = [@$list]\n"; + + my $begin = 0; + + my $ender = scalar @$list - 1; + + my $cnt = $begin + 1; + + + + while($begin < $ender){ + + while($cnt <= $ender ) { + + if ($list->[$cnt] == $list->[$begin]){ + + print("($begin,$cnt)\n"); + + $finalCnt++; + + } + + $cnt++; + + } + + $begin++; + + $cnt = $begin + 1; + + } + + print "Output: $finalCnt\n\n"; + + $finalCnt = 0; + +} + + + +=begin + +SAMPLE OUTPUT + +perl .\GoodPairs.pl + +Input: @list = [1 2 3 1 1 3] + +(0,3) + +(0,4) + +(2,5) + +(3,4) + +Output: 4 + + + +Input: @list = [1 2 3] + +Output: 0 + + + +Input: @list = [1 1 1 1] + +(0,1) + +(0,2) + +(0,3) + +(1,2) + +(1,3) + +(2,3) + +Output: 6 + +=cut diff --git a/challenge-199/robert-dicicco/python/ch-1.py b/challenge-199/robert-dicicco/python/ch-1.py new file mode 100644 index 0000000000..1ef638bb42 --- /dev/null +++ b/challenge-199/robert-dicicco/python/ch-1.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +''' + +AUTHOR: Robert DiCicco + +DATE : 2023-01-09 + +Challenge 199 Good Pairs ( Python ) + +''' + + + +lists = [[1,2,3,1,1,3],[1,2,3],[1,1,1,1]] + +finalCnt = 0 + + + +for list in lists: + + print(f"Input: @list = {list}") + + beginner = 0 + + ender = len(list) - 1 + + cnt = beginner + 1 + + while beginner < ender: + + while cnt <= ender: + + if list[cnt] == list[beginner]: + + print(f"{beginner},{cnt}") + + finalCnt += 1 + + cnt += 1 + + beginner += 1 + + cnt = beginner + 1 + + print(f"Output: {finalCnt}\n") + + finalCnt = 0 + + + +''' + +SAMPLE OUTPOUT + +python .\GoodPairs.py + +Input: @list = [1, 2, 3, 1, 1, 3] + +0,3 + +0,4 + +2,5 + +3,4 + +Output: 4 + + + +Input: @list = [1, 2, 3] + +Output: 0 + + + +Input: @list = [1, 1, 1, 1] + +0,1 + +0,2 + +0,3 + +1,2 + +1,3 + +2,3 + +Output: 6 + +''' diff --git a/challenge-199/robert-dicicco/raku/ch-1.raku b/challenge-199/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..c3aa287435 --- /dev/null +++ b/challenge-199/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,103 @@ +use v6; + +#`{ + +AUTHOR: Robert DiCicco + +DATE : 2023-01-09 + +Challenge 199 Good Pairs ( Raku ) + +} + + + +my @lists = ([1,2,3,1,1,3],[1,2,3],[1,1,1,1]); + +my $finalCnt = 0; + + + +for (@lists) -> @list { + + print "Input: \@list = [",@list,"]\n"; + + my $begin = 0; + + my $ender = @list.elems - 1; + + my $cnt = $begin + 1; + + while ($begin < $ender) { + + while ( $cnt <= $ender ) { + + if (@list[$cnt] == @list[$begin]) { + + print("($begin,$cnt)\n"); + + $finalCnt++; + + } + + $cnt++; + + } + + $begin++; + + $cnt = $begin + 1; + + } + + print "Output: $finalCnt\n\n"; + + $finalCnt = 0; + +} + + + +#`{ + +SAMPLE OUTPUT + +raku .\GoodPairs.rk + +Input: @list = [1 2 3 1 1 3] + +(0,3) + +(0,4) + +(2,5) + +(3,4) + +Output: 4 + + + +Input: @list = [1 2 3] + +Output: 0 + + + +Input: @list = [1 1 1 1] + +(0,1) + +(0,2) + +(0,3) + +(1,2) + +(1,3) + +(2,3) + +Output: 6 + +} diff --git a/challenge-199/robert-dicicco/ruby/ch-1.rb b/challenge-199/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..4f2205939f --- /dev/null +++ b/challenge-199/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,107 @@ +#!/usr/bin/env ruby + +=begin + +AUTHOR: Robert DiCicco + +DATE : 2023-01-09 + +Challenge 199 Good Pairs ( Ruby ) + +=end + + + + + +lists = [[1,2,3,1,1,3],[1,2,3],[1,1,1,1]] + +finalCnt = 0 + + + +lists.each do |list| + + puts "Input: @list = #{list}" + + beginner = 0 + + ender = list.length() - 1 + + cnt = beginner + 1 + + while beginner < ender + + while cnt <= ender + + if (list[cnt] == list[beginner]) then + + puts("#{beginner},#{cnt}") + + finalCnt += 1 + + end + + cnt += 1 + + end + + beginner += 1 + + cnt = beginner + 1 + + end + + puts("Output: #{finalCnt}") + + puts(" ") + + finalCnt = 0 + +end + + + +=begin + +SAMPLE OUTPUT + +ruby .\GoodPairs.rb + +Input: @list = [1, 2, 3, 1, 1, 3] + +0,3 + +0,4 + +2,5 + +3,4 + +Output: 4 + + + +Input: @list = [1, 2, 3] + +Output: 0 + + + +Input: @list = [1, 1, 1, 1] + +0,1 + +0,2 + +0,3 + +1,2 + +1,3 + +2,3 + +Output: 6 + +=end diff --git a/challenge-199/ziameraj16/java/GoodPairs.java b/challenge-199/ziameraj16/java/GoodPairs.java new file mode 100644 index 0000000000..fb76bea61d --- /dev/null +++ b/challenge-199/ziameraj16/java/GoodPairs.java @@ -0,0 +1,20 @@ +import java.util.*; +import java.util.stream.Collectors; + +public class GoodPairs { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter comma separated values"); + List<Integer> list = Arrays.stream(scanner.nextLine().split(",")).map(Integer::valueOf).collect(Collectors.toList()); + int count = 0; + for (int i = 1; i < list.size(); i++) { + for (int j = 0; j < i; j++) { + if (list.get(i) == list.get(j)) { + count++; + } + } + } + System.out.println(count); + } +} |
