aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-04-03 02:26:32 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-04-03 02:26:32 +0100
commit2ab30f5a76565588dfe64ff9efc2abeafed0e813 (patch)
treebc0fe454df07f039cece23dc0286de3c0ecfb7b1
parent2ee6aa405be90f379f95597ad94e97d1a7985f1d (diff)
downloadperlweeklychallenge-club-2ab30f5a76565588dfe64ff9efc2abeafed0e813.tar.gz
perlweeklychallenge-club-2ab30f5a76565588dfe64ff9efc2abeafed0e813.tar.bz2
perlweeklychallenge-club-2ab30f5a76565588dfe64ff9efc2abeafed0e813.zip
- Added solutions by Simon Green.
- Added solutions by W. Luis Mochan. - Added solutions by E. Choroba. - Added solutions by David Ferrone. - Added solutions by Mark Anderson. - Added solutions by Lubos Kolouch. - Added solutions by Paulo Custodio. - Added solutions by Roger Bell_West. - Added solutions by Thomas Kohler. - Added solutions by Peter Campbell Smith. - Added solutions by Athanasius. - Added solutions by Robbie Hatley. - Added solutions by Luca Ferrari. - Added solutions by Avery Adams. - Added solutions by Bob Lied. - Added solutions by Mariano Spadaccini. - Added solutions by Jorg Sommrey. - Added solutions by Cheok-Yin Fung. - Added solutions by Flavio Poletti. - Added solutions by Solathian. - Added solutions by Matthias Muth. - Added solutions by Carlos Oliveira. - Added solutions by Robert Ransbottom. - Added solutions by Matthew Neleigh. - Added solutions by Arne Sommer. - Added solutions by Jan Krnavek. - Added solutions by Pip Stuart. - Added solutions by James Smith. - Added solutions by Shimon Bollinger. - Added solutions by Peter Meszaros. - Added solutions by Ulrich Rieke. - Added solutions by Robert DiCicco.
-rwxr-xr-xchallenge-210/eric-cheung/python/ch-1.py7
-rwxr-xr-xchallenge-210/eric-cheung/python/ch-2.py28
-rw-r--r--challenge-210/robert-dicicco/julia/ch-1.jl64
-rw-r--r--challenge-210/robert-dicicco/perl/ch-1.pl67
-rw-r--r--challenge-210/robert-dicicco/python/ch-1.py53
-rw-r--r--challenge-210/robert-dicicco/raku/ch-1.raku59
-rw-r--r--challenge-210/robert-dicicco/ruby/ch-1.rb62
-rw-r--r--challenge-210/ulrich-rieke/cpp/ch-1.cpp47
-rw-r--r--challenge-210/ulrich-rieke/cpp/ch-2.cpp84
-rw-r--r--challenge-210/ulrich-rieke/haskell/ch-1.hs13
-rw-r--r--challenge-210/ulrich-rieke/haskell/ch-2.hs31
-rw-r--r--challenge-210/ulrich-rieke/perl/ch-1.pl23
-rw-r--r--challenge-210/ulrich-rieke/perl/ch-2.pl61
-rw-r--r--challenge-210/ulrich-rieke/raku/ch-1.raku21
-rw-r--r--challenge-210/ulrich-rieke/raku/ch-2.raku57
-rw-r--r--challenge-210/ulrich-rieke/rust/ch-1.rs24
-rw-r--r--challenge-210/ulrich-rieke/rust/ch-2.rs58
-rw-r--r--members.json1
-rw-r--r--stats/pwc-challenge-043.json405
-rw-r--r--stats/pwc-challenge-044.json517
-rw-r--r--stats/pwc-challenge-163.json581
-rw-r--r--stats/pwc-challenge-164.json295
-rw-r--r--stats/pwc-challenge-165.json409
-rw-r--r--stats/pwc-challenge-166.json439
-rw-r--r--stats/pwc-challenge-167.json249
-rw-r--r--stats/pwc-challenge-168.json299
-rw-r--r--stats/pwc-challenge-169.json581
-rw-r--r--stats/pwc-challenge-170.json557
-rw-r--r--stats/pwc-challenge-171.json323
-rw-r--r--stats/pwc-challenge-172.json529
-rw-r--r--stats/pwc-challenge-173.json591
-rw-r--r--stats/pwc-challenge-174.json555
-rw-r--r--stats/pwc-challenge-175.json575
-rw-r--r--stats/pwc-challenge-176.json551
-rw-r--r--stats/pwc-challenge-177.json257
-rw-r--r--stats/pwc-challenge-178.json211
-rw-r--r--stats/pwc-challenge-179.json239
-rw-r--r--stats/pwc-challenge-180.json615
-rw-r--r--stats/pwc-challenge-181.json509
-rw-r--r--stats/pwc-challenge-182.json293
-rw-r--r--stats/pwc-challenge-183.json453
-rw-r--r--stats/pwc-challenge-184.json571
-rw-r--r--stats/pwc-challenge-185.json647
-rw-r--r--stats/pwc-challenge-186.json347
-rw-r--r--stats/pwc-challenge-187.json569
-rw-r--r--stats/pwc-challenge-188.json345
-rw-r--r--stats/pwc-challenge-189.json643
-rw-r--r--stats/pwc-challenge-190.json299
-rw-r--r--stats/pwc-challenge-191.json319
-rw-r--r--stats/pwc-challenge-192.json357
-rw-r--r--stats/pwc-challenge-193.json307
-rw-r--r--stats/pwc-challenge-209.json683
-rw-r--r--stats/pwc-current.json399
-rw-r--r--stats/pwc-language-breakdown-summary.json62
-rw-r--r--stats/pwc-language-breakdown.json2875
-rw-r--r--stats/pwc-leaders.json832
-rw-r--r--stats/pwc-summary-1-30.json114
-rw-r--r--stats/pwc-summary-121-150.json54
-rw-r--r--stats/pwc-summary-151-180.json60
-rw-r--r--stats/pwc-summary-181-210.json104
-rw-r--r--stats/pwc-summary-211-240.json56
-rw-r--r--stats/pwc-summary-241-270.json66
-rw-r--r--stats/pwc-summary-271-300.json68
-rw-r--r--stats/pwc-summary-31-60.json106
-rw-r--r--stats/pwc-summary-61-90.json38
-rw-r--r--stats/pwc-summary-91-120.json48
-rw-r--r--stats/pwc-summary.json704
67 files changed, 11672 insertions, 9794 deletions
diff --git a/challenge-210/eric-cheung/python/ch-1.py b/challenge-210/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..53345fd3d4
--- /dev/null
+++ b/challenge-210/eric-cheung/python/ch-1.py
@@ -0,0 +1,7 @@
+
+## arrList = [2, 3, 1] ## Example 1
+arrList = [1, 1, 2, 2, 2, 3] ## Example 2
+
+nTotalPoints = sum(arrList)
+
+print (nTotalPoints)
diff --git a/challenge-210/eric-cheung/python/ch-2.py b/challenge-210/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..864545c9e8
--- /dev/null
+++ b/challenge-210/eric-cheung/python/ch-2.py
@@ -0,0 +1,28 @@
+
+## arrInputList = [2, 3, -1] ## Example 1:
+## arrInputList = [3, 2, -4] ## Example 2:
+arrInputList = [1, -1] ## Example 3:
+
+arrTempList = arrInputList[:]
+
+while len(arrTempList) > 0:
+
+ arrPosIndx = [nIndx for nIndx, nElemLoop in enumerate(arrTempList) if nElemLoop >= 0]
+ if len(arrPosIndx) == 0 or len(arrPosIndx) == len(arrTempList):
+ break
+
+ arrNegIndx = [nIndx for nIndx, nElemLoop in enumerate(arrTempList) if nElemLoop < 0]
+ nFirstNegIndx = arrNegIndx[0]
+
+ if nFirstNegIndx == 0:
+ break
+
+ if arrTempList[nFirstNegIndx - 1] == abs(arrTempList[nFirstNegIndx]):
+ del arrTempList[nFirstNegIndx]
+ del arrTempList[nFirstNegIndx - 1]
+ elif arrTempList[nFirstNegIndx - 1] < abs(arrTempList[nFirstNegIndx]):
+ del arrTempList[nFirstNegIndx - 1]
+ else:
+ del arrTempList[nFirstNegIndx]
+
+print (arrTempList)
diff --git a/challenge-210/robert-dicicco/julia/ch-1.jl b/challenge-210/robert-dicicco/julia/ch-1.jl
new file mode 100644
index 0000000000..a7e7a8d3f9
--- /dev/null
+++ b/challenge-210/robert-dicicco/julia/ch-1.jl
@@ -0,0 +1,64 @@
+#!/usr/bin/env julia
+#=
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-03-28
+Challenge 210 Kill&Win ( Julia )
+--------------------------------------
+=#
+using Printf
+
+myint =[[2,3,1],[1,1,2,2,2,3]]
+total_score = 0;
+max_score = 0;
+max_possible = 0;
+
+function Score(arr)
+ global total_score,max_possible,max_score
+ for testx in arr
+ println("trying ",testx)
+ for val in arr
+ if ((val == testx) || (val == testx-1) || (val == testx+1))
+ total_score += val
+ end
+ end
+ if total_score == max_possible
+ println("Output: ",total_score)
+ println("")
+ return
+ end
+ if total_score > max_score
+ max_score = total_score
+ end
+ total_score = 0
+ end
+ println("Output: ",max_score)
+end
+
+for a in myint
+ global max_possible
+ println("Input: @int = ",a)
+ max_possible = sum(a)
+ println("max possible = ",max_possible)
+ Score(a)
+end
+
+#=
+--------------------------------------
+SAMPLE OUTPUT
+julia .\KillWin.jl
+Input: @int = [2, 3, 1]
+max possible = 6
+trying 2
+Output: 6
+
+Input: @int = [1, 1, 2, 2, 2, 3]
+max possible = 11
+trying 1
+trying 1
+trying 2
+Output: 11
+--------------------------------------
+=#
+
+
diff --git a/challenge-210/robert-dicicco/perl/ch-1.pl b/challenge-210/robert-dicicco/perl/ch-1.pl
new file mode 100644
index 0000000000..a52d55be49
--- /dev/null
+++ b/challenge-210/robert-dicicco/perl/ch-1.pl
@@ -0,0 +1,67 @@
+#!/usr/bin/env perl
+=begin comment
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-03-28
+Challenge 210 Kill&Win ( Perl )
+--------------------------------------
+=cut
+use strict;
+use warnings;
+use feature 'say';
+use List::Util 'sum';
+
+my @int = ([2,3,1],[1,1,2,2,2,3]);
+my $total_score = 0;
+my $max_score = 0;
+my $max_possible = 0;
+
+sub Score {
+ my $a = shift;
+
+ for my $testx (@$a) {
+ say "trying $testx...";
+
+ for my $val (@$a) {
+ $total_score += $val if (($val == $testx) || ($val == $testx-1) || ($val == $testx+1));
+ }
+
+ if ($total_score == $max_possible) {
+ say "Output: $total_score\n";
+ return;
+ }
+ if ($total_score > $max_score) {
+ $max_score = $total_score;
+ }
+
+ $total_score = 0;
+ }
+ say "Output: $max_score\n";
+}
+
+for my $i (@int) {
+ my @arr = @$i;
+ say "Input: \@int = (@arr)";
+ $max_possible = sum(@arr[0..$#arr]);
+ say "max_possible = $max_possible";
+ Score(\@arr);
+}
+=begin comment
+--------------------------------------
+SAMPLE OUTPUT
+perl .\KillWin.pl
+Input: @int = (2 3 1)
+max_possible = 6
+trying 2...
+Output: 6
+
+Input: @int = (1 1 2 2 2 3)
+max_possible = 11
+trying 1...
+trying 1...
+trying 2...
+Output: 11
+--------------------------------------
+=cut
+
+
diff --git a/challenge-210/robert-dicicco/python/ch-1.py b/challenge-210/robert-dicicco/python/ch-1.py
new file mode 100644
index 0000000000..886bd689e5
--- /dev/null
+++ b/challenge-210/robert-dicicco/python/ch-1.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+'''
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-03-28
+Challenge 210 Kill&Win ( Python )
+--------------------------------------
+'''
+myint =[[2,3,1],[1,1,2,2,2,3]]
+
+def Score(arr):
+ global total_score,max_score;
+ total_score = 0
+ max_score = 0
+
+ for testx in arr:
+ print(f"trying {testx}")
+ for val in arr:
+ if ((val == testx) or (val == testx-1) or (val == testx+1)) :
+ total_score += val
+ if total_score == max_possible:
+ print(f"Output: {total_score}")
+ print("")
+ return
+ if total_score > max_score:
+ max_score = total_score
+ total_score = 0
+
+for a in myint:
+ global max_possible;
+ print(f"Input: @int = {a}")
+ max_possible = sum(a)
+ print(f"max_possible = {max_possible}")
+ Score(a)
+'''
+--------------------------------------
+SAMPLE OUTPUT
+python .\KillWin.py
+Input: @int = [2, 3, 1]
+max_possible = 6
+trying 2
+Output: 6
+
+Input: @int = [1, 1, 2, 2, 2, 3]
+max_possible = 11
+trying 1
+trying 1
+trying 2
+Output: 11
+--------------------------------------
+'''
+
+
diff --git a/challenge-210/robert-dicicco/raku/ch-1.raku b/challenge-210/robert-dicicco/raku/ch-1.raku
new file mode 100644
index 0000000000..fab7235ae5
--- /dev/null
+++ b/challenge-210/robert-dicicco/raku/ch-1.raku
@@ -0,0 +1,59 @@
+#!/usr/bin/env raku
+use v6;
+#`{
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-03-28
+Challenge 210 Kill&Win ( Raku )
+--------------------------------------
+}
+my @int = ([2,3,1],[1,1,2,2,2,3]);
+my $total_score = 0;
+my $max_score = 0;
+my $max_possible = 0;
+
+sub Score(@a) {
+ for (@a) -> $testx {
+ say "trying $testx";
+ for (@a) -> $val {
+ $total_score += $val if (($val == $testx) || ($val == $testx-1) || ($val == $testx+1));
+ }
+ if ($total_score == $max_possible) {
+ say "Output: $total_score\n";
+ return;
+ }
+ if ($total_score > $max_score) {
+ $max_score = $total_score;
+ }
+ $total_score = 0;
+ }
+ say "Output: $max_score\n";
+}
+
+
+for (@int) -> @arr {
+ #my @arr = @$i;
+ say "Input: \@int = ("~@arr~")";
+ $max_possible = sum(@arr[0..@arr.end]);
+ say "max_possible = $max_possible";
+ Score(@arr);
+}
+
+#`{
+--------------------------------------
+raku .\KillWin.rk
+Input: @int = (2 3 1)
+max_possible = 6
+trying 2
+Output: 6
+
+Input: @int = (1 1 2 2 2 3)
+max_possible = 11
+trying 1
+trying 1
+trying 2
+Output: 11
+--------------------------------------
+}
+
+
diff --git a/challenge-210/robert-dicicco/ruby/ch-1.rb b/challenge-210/robert-dicicco/ruby/ch-1.rb
new file mode 100644
index 0000000000..54007d4a9d
--- /dev/null
+++ b/challenge-210/robert-dicicco/ruby/ch-1.rb
@@ -0,0 +1,62 @@
+#!/usr/bin/env ruby
+=begin
+--------------------------------------
+AUTHOR: Robert DiCicco
+DATE : 2023-03-28
+Challenge 210 Kill&Win ( Ruby )
+--------------------------------------
+=end
+
+myint =[[2,3,1],[1,1,2,2,2,3]]
+$total_score = 0;
+$max_score = 0;
+$max_possible = 0;
+
+def Score(arr)
+ arr.each do |testx|
+ testx = testx.to_i
+ puts("trying #{testx}")
+ arr.each do |val|
+ val = val.to_i
+ $total_score += val if ((val == testx) || (val == testx-1) || (val == testx+1))
+ end
+ if ($total_score == $max_possible)
+ puts("Output: #{$total_score}")
+ puts("")
+ return
+ end
+ if $total_score > $max_score
+ $max_score = $total_score
+ end
+ $total_score = 0
+ end
+ puts("Output: #{$max_score}\n")
+ puts("")
+end
+
+myint.each do |a|
+ puts("Input: @int = #{a}")
+ $max_possible = a.sum
+ puts("max possible = #{$max_possible}")
+ Score(a)
+end
+
+=begin
+--------------------------------------
+SAMPLE OUTPUT
+ruby .\KillWin.rb
+Input: @int = [2, 3, 1]
+max possible = 6
+trying 2
+Output: 6
+
+Input: @int = [1, 1, 2, 2, 2, 3]
+max possible = 11
+trying 1
+trying 1
+trying 2
+Output: 11
+--------------------------------------
+=end
+
+
diff --git a/challenge-210/ulrich-rieke/cpp/ch-1.cpp b/challenge-210/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..013b52b5c7
--- /dev/null
+++ b/challenge-210/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <vector>
+#include <string>
+#include <algorithm>
+#include <list>
+
+std::vector<std::string> split( const std::string & startline ,
+ const std::string & sep ) {
+ std::vector<std::string> separated ;
+ std::string::size_type start { 0 } ;
+ std::string::size_type pos ;
+ do {
+ pos = startline.find_first_of( sep , start ) ;
+ separated.push_back( startline.substr(start , pos - start )) ;
+ start = pos + 1 ;
+ } while ( pos != std::string::npos ) ;
+ return separated ;
+}
+
+int main( ) {
+ std::cout << "Please enter some integers, separated by a blank!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> numberstrings( split( line , " " ) ) ;
+ std::vector<int> numbers ;
+ for ( auto s : numberstrings )
+ numbers.push_back( std::stoi( s ) ) ;
+ std::sort( numbers.begin( ) , numbers.end( ) ) ;
+ std::list<int> theNumbers ;
+ for ( int i : numbers )
+ theNumbers.push_back( i ) ;
+ theNumbers.sort( ) ;
+ theNumbers.unique( ) ;
+ std::vector<int> allSums ;
+ for ( auto it = theNumbers.begin( ) ; it != theNumbers.end( ) ; it++ ) {
+ int sum = 0 ;
+ int ct = std::count( numbers.begin( ) , numbers.end( ) , *it - 1) ;
+ sum += ct * (*it - 1) ;
+ ct = std::count( numbers.begin( ) , numbers.end( ) , *it ) ;
+ sum += ct * *it ;
+ ct = std::count( numbers.begin( ) , numbers.end( ) , *it + 1 ) ;
+ sum += ct * (*it + 1 ) ;
+ allSums.push_back( sum ) ;
+ }
+ std::cout<< *max_element( allSums.begin( ) , allSums.end( ) ) << std::endl ;
+ return 0 ;
+}
diff --git a/challenge-210/ulrich-rieke/cpp/ch-2.cpp b/challenge-210/ulrich-rieke/cpp/ch-2.cpp
new file mode 100644
index 0000000000..52f7112565
--- /dev/null
+++ b/challenge-210/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,84 @@
+#include <iostream>
+#include <vector>
+#include <string>
+#include <algorithm>
+#include <numeric>
+
+std::vector<std::string> split( const std::string & startline ,
+ const std::string & sep ) {
+ std::vector<std::string> separated ;
+ std::string::size_type start { 0 } ;
+ std::string::size_type pos ;
+ do {
+ pos = startline.find_first_of( sep , start ) ;
+ separated.push_back( startline.substr(start , pos - start )) ;
+ start = pos + 1 ;
+ } while ( pos != std::string::npos ) ;
+ return separated ;
+}
+
+bool isValid( const std::vector<int> & numbers ) {
+ int len = numbers.size( ) ;
+ if ( len == 0 || len == 1 )
+ return true ;
+ else {
+ if ( len == 2 ) {
+ return ( ! ( (numbers[ 0 ] > 0 ) && ( numbers[ 1 ] < 0 ) ) ) ;
+ }
+ else {
+ std::vector<int> indices ( numbers.size( ) - 2 ) ;
+ std::iota( indices.begin( ) , indices.end( ) , 0 ) ;
+ return std::none_of( indices.begin( ) , indices.end( ) , [numbers]( int i ) {
+ return (numbers[i] > 0 && numbers[ i + 1 ] < 0 ) ; } ) ;
+ }
+ }
+}
+
+std::vector<int> eliminate( const std::vector<int> & numbers ) {
+ std::vector<int> afterElimination ;
+ int len = numbers.size( ) ;
+ int pos = 0 ;
+ while ( ! ( numbers[ pos ] > 0 && numbers[ pos + 1 ] < 0 ) ) {
+ afterElimination.push_back( numbers[ pos ] ) ;
+ pos++ ;
+ }
+ int diff = abs( numbers[ pos ] ) - abs( numbers[ pos + 1 ] ) ;
+ if ( diff > 0 )
+ afterElimination.push_back( numbers[ pos ] ) ;
+ if ( diff == 0 ) {
+ }
+ if ( diff < 0 ) {
+ afterElimination.push_back( numbers[ pos + 1 ] ) ;
+ }
+ pos += 2 ;
+ if ( pos < len ) {
+ while ( pos < len ) {
+ afterElimination.push_back( numbers[ pos ] ) ;
+ pos++ ;
+ }
+ }
+ return afterElimination ;
+}
+
+int main( ) {
+ std::cout << "Enter some positive and negative integers, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> numberstrings( split( line, " " ) ) ;
+ std::vector<int> numbers ;
+ for ( auto s : numberstrings )
+ numbers.push_back( std::stoi( s ) ) ;
+ std::vector<int> afterEliminate = eliminate( numbers ) ;
+ while ( ! isValid( afterEliminate ) ) {
+ afterEliminate = eliminate( afterEliminate ) ;
+ }
+ if ( afterEliminate.size( ) > 0 ) {
+ std::cout << '(' ;
+ for ( int i : afterEliminate )
+ std::cout << i << " " ;
+ std::cout << ")\n" ;
+ }
+ else
+ std::cout << "()\n" ;
+ return 0 ;
+}
diff --git a/challenge-210/ulrich-rieke/haskell/ch-1.hs b/challenge-210/ulrich-rieke/haskell/ch-1.hs
new file mode 100644
index 0000000000..527ebf8131
--- /dev/null
+++ b/challenge-210/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,13 @@
+module Challenge210
+ where
+import Data.List ( sort )
+import qualified Data.Set as S
+
+solution :: [Int] -> Int
+solution list = maximum $ map (\[a , b , c] -> a * count a list + b * count b list
+ + c * count c list ) $ map (\i -> [i - 1 , i , i + 1] ) uniques
+ where
+ uniques :: [Int]
+ uniques = sort $ S.toList $ S.fromList list
+ count :: Int -> [Int] -> Int
+ count n l = length $ filter ( == n ) list
diff --git a/challenge-210/ulrich-rieke/haskell/ch-2.hs b/challenge-210/ulrich-rieke/haskell/ch-2.hs
new file mode 100644
index 0000000000..444f063a25
--- /dev/null
+++ b/challenge-210/