aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-24 18:09:42 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-24 18:09:42 +0100
commitdffe0c209b4764cc5fccdf7d234ce5c611a3ea85 (patch)
tree7e5155ad86c274abcd0651e7a33a3c9c333ae875
parent42a066d2210210663bf7bf7dcbcbafc954839a5b (diff)
downloadperlweeklychallenge-club-dffe0c209b4764cc5fccdf7d234ce5c611a3ea85.tar.gz
perlweeklychallenge-club-dffe0c209b4764cc5fccdf7d234ce5c611a3ea85.tar.bz2
perlweeklychallenge-club-dffe0c209b4764cc5fccdf7d234ce5c611a3ea85.zip
- Added solutions by Lubos Kolouch.
- Added solutions by Ulrich Rieke.
-rwxr-xr-xchallenge-218/eric-cheung/python/ch-1.py26
-rwxr-xr-xchallenge-218/eric-cheung/python/ch-2.py51
-rw-r--r--challenge-218/ulrich-rieke/cpp/ch-1.cpp45
-rw-r--r--challenge-218/ulrich-rieke/cpp/ch-2.cpp176
-rw-r--r--challenge-218/ulrich-rieke/haskell/ch-1.hs22
-rw-r--r--challenge-218/ulrich-rieke/haskell/ch-2.hs55
-rw-r--r--challenge-218/ulrich-rieke/perl/ch-1.pl22
-rw-r--r--challenge-218/ulrich-rieke/perl/ch-2.pl140
-rw-r--r--challenge-218/ulrich-rieke/raku/ch-1.raku21
-rw-r--r--challenge-218/ulrich-rieke/rust/ch-1.rs22
-rw-r--r--stats/pwc-challenge-105.json219
-rw-r--r--stats/pwc-challenge-107.json545
-rw-r--r--stats/pwc-current.json193
-rw-r--r--stats/pwc-language-breakdown-summary.json68
-rw-r--r--stats/pwc-language-breakdown.json1540
-rw-r--r--stats/pwc-leaders.json782
-rw-r--r--stats/pwc-summary-1-30.json114
-rw-r--r--stats/pwc-summary-121-150.json50
-rw-r--r--stats/pwc-summary-151-180.json48
-rw-r--r--stats/pwc-summary-181-210.json48
-rw-r--r--stats/pwc-summary-211-240.json48
-rw-r--r--stats/pwc-summary-241-270.json98
-rw-r--r--stats/pwc-summary-271-300.json50
-rw-r--r--stats/pwc-summary-31-60.json104
-rw-r--r--stats/pwc-summary-61-90.json30
-rw-r--r--stats/pwc-summary-91-120.json42
-rw-r--r--stats/pwc-summary.json614
27 files changed, 2903 insertions, 2270 deletions
diff --git a/challenge-218/eric-cheung/python/ch-1.py b/challenge-218/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..8c79d7a99d
--- /dev/null
+++ b/challenge-218/eric-cheung/python/ch-1.py
@@ -0,0 +1,26 @@
+
+## arrInputList = [3, 1, 2] ## Example 1
+## arrInputList = [4, 1, 3, 2] ## Example 2
+## arrInputList = [-1, 0, 1, 3, 1] ## Example 3
+arrInputList = [-8, 2, -9, 0, -4, 3] ## Example 4
+
+arrInterList = sorted(arrInputList)
+arrNegInterList = [nElem for nElem in arrInterList if nElem < 0]
+
+arrOutputList = []
+if len(arrNegInterList) <= 1:
+ arrOutputList = arrInterList[-3:]
+else:
+ nTempIndx = max(int((len(arrNegInterList) + (0 if len(arrNegInterList) % 2 == 0 else 1)) / 2), 2)
+
+ for nElem in arrNegInterList[:nTempIndx]:
+ arrOutputList.append(nElem)
+
+ for nElem in arrInterList[-3 + len(arrOutputList):]:
+ arrOutputList.append(nElem)
+
+nProduct = 1
+for nElem in arrOutputList:
+ nProduct = nProduct * nElem
+
+print (nProduct)
diff --git a/challenge-218/eric-cheung/python/ch-2.py b/challenge-218/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..682949d9c2
--- /dev/null
+++ b/challenge-218/eric-cheung/python/ch-2.py
@@ -0,0 +1,51 @@
+
+arrMatrix = [[0, 0, 1, 1], [1, 0, 1, 0], [1, 1, 0, 0]]
+## arrMatrix = [[0]] ## Example 2
+
+nMatrixSum = 0
+
+def GetSum (arrInputMat):
+
+ nSum = 0
+
+ for nIndx in range(0, len(arrInputMat)):
+ nSum = nSum + int("".join([str(nElem) for nElem in arrInputMat[nIndx]]), 2)
+
+ return nSum
+
+def SwapAlongRow (arrInputMat, nRowIndx):
+
+ for nIndx in range(0, len(arrMatrix[0])):
+ arrInputMat[nRowIndx][nIndx] = 1 - arrInputMat[nRowIndx][nIndx]
+
+ return
+
+def SwapAlongCol (arrInputMat, nColIndx):
+
+ for nIndx in range(0, len(arrMatrix)):
+ arrInputMat[nIndx][nColIndx] = 1 - arrInputMat[nIndx][nColIndx]
+
+ return
+
+
+if len(arrMatrix) == 1 and len(arrMatrix[0]) == 1:
+ print (1)
+else:
+ ## Swap Along Rows
+ for nRowLoopIndx in range(0, len(arrMatrix)):
+ arrTempMatrix = [arrRow[:] for arrRow in arrMatrix]
+ SwapAlongRow (arrTempMatrix, nRowLoopIndx)
+ if GetSum (arrTempMatrix) > nMatrixSum:
+ SwapAlongRow (arrMatrix, nRowLoopIndx)
+ nMatrixSum = GetSum (arrMatrix)
+
+ ## Swap Along Columns
+ for nColLoopIndx in range(0, len(arrMatrix[0])):
+ arrTempMatrix = [arrRow[:] for arrRow in arrMatrix]
+ SwapAlongCol (arrTempMatrix, nColLoopIndx)
+ if GetSum (arrTempMatrix) > nMatrixSum:
+ SwapAlongCol (arrMatrix, nColLoopIndx)
+ nMatrixSum = GetSum (arrMatrix)
+
+ ## print (arrMatrix)
+ print (nMatrixSum)
diff --git a/challenge-218/ulrich-rieke/cpp/ch-1.cpp b/challenge-218/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..de7fa6670f
--- /dev/null
+++ b/challenge-218/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,45 @@
+#include <iostream>
+#include <string>
+#include <vector>
+#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 ;
+}
+
+int main( ) {
+ std::cout << "Enter at least 3 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 ) ) ;
+ if ( numbers.size( ) == 3 ) {
+ std::cout << std::accumulate( numbers.begin( ) , numbers.end( ) , 1 ,
+ std::multiplies<int>( ) ) << '\n' ;
+ }
+ else {
+ int len = numbers.size( ) ;
+ std::vector<int> products ;
+ for ( int i = 0 ; i < len - 2 ; i++ ) {
+ for ( int j = i + 1 ; j < len - 1 ; j++ ) {
+ for ( int k = j + 1 ; k < len ; k++ ) {
+ products.push_back( numbers[ i ] * numbers[ j ] * numbers[ k ] ) ;
+ }
+ }
+ }
+ std::cout << *max_element( products.begin( ) , products.end( ) ) << '\n' ;
+ }
+ return 0 ;
+}
diff --git a/challenge-218/ulrich-rieke/cpp/ch-2.cpp b/challenge-218/ulrich-rieke/cpp/ch-2.cpp
new file mode 100644
index 0000000000..f448c8ef27
--- /dev/null
+++ b/challenge-218/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,176 @@
+#include <vector>
+#include <string>
+#include <iostream>
+#include <algorithm>
+#include <cmath>
+#include <iterator>
+
+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 ;
+}
+
+std::vector<int> toggle ( const std::vector<int> & aVec ) {
+ std::vector<int> toggled ;
+ for ( int i : aVec ) {
+ if ( i == 0 ) {
+ toggled.push_back( 1 ) ;
+ }
+ else {
+ toggled.push_back( 0 ) ;
+ }
+ }
+ return toggled ;
+}
+
+std::vector<std::vector<int>> toggle_row( const std::vector<std::vector<int>>
+ & input , int row) {
+ std::vector<std::vector<int>> toggled ;
+ int matrixlen = input.size( ) ;
+ for ( int i = 0 ; i < matrixlen ; i++ ) {
+ if ( i == row )
+ toggled.push_back( toggle( input[ i ] )) ;
+ else
+ toggled.push_back( input[ i ] ) ;
+ }
+ return toggled ;
+}
+
+std::vector<std::vector<int>> transpose( const std::vector<std::vector<int>>
+ & matrix ) {
+ int len = matrix.size( ) ;
+ int rowlen = matrix[0].size( ) ;
+ std::vector<int> current_column ;
+ std::vector<std::vector<int>> transposed ;
+ for ( int c = 0 ; c < rowlen ; c++ ) {
+ for ( int r = 0 ; r < len ; r++ ) {
+ current_column.push_back( matrix[ r ][ c ] ) ;
+ }
+ transposed.push_back( current_column ) ;
+ current_column.clear( ) ;
+ }
+ return transposed ;
+}
+
+int to_binary_sum( const std::vector<std::vector<int>> & matrix ) {
+ int sum = 0 ;
+ int len = matrix[0].size( ) ;
+ for ( int r = 0 ; r < matrix.size( ) ; r++ ) {
+ for ( int i = 0 ; i < len ; i++ ) {
+ double result = std::pow( 2.0 , static_cast<double>( len - i - 1 ) ) *
+ matrix[r][i] ;
+ sum += static_cast<int>( result ) ;
+ }
+ }
+ return sum ;
+}
+
+int main( ) {
+ std::cout << "Please enter some 1 and 0 , separated by blanks, end to end!\n" ;
+ std::vector<std::vector<int>> matrix ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ while ( line != "end" ) {
+ std::vector<std::string> numbers ( split( line , " " ) ) ;
+ std::vector<int> row ;
+ for ( auto s : numbers ) {
+ row.push_back( std::stoi( s ) ) ;
+ }
+ matrix.push_back( row ) ;
+ std::getline( std::cin , line ) ;
+ }
+ int matrixlen = matrix.size( ) ;
+ if ( matrixlen == 1 ) {
+ std::vector<int> toggled ( toggle( matrix[ 0 ] ) ) ;
+ int sum = 0 ;
+ int rowlen = toggled.size( ) ;
+ for ( int i = 0 ; i < rowlen ; i++ ) {
+ double result = std::pow( 2.0 , static_cast<double>( rowlen
+ - i - 1 )) * toggled[ i ] ;
+ sum += static_cast<int>( result ) ;
+ }
+ std::cout << sum << std::endl ;
+ return 1 ;
+ }
+ else {
+ std::vector<int> binary_row_sums ; //for the sums of binary rows for
+ //the toggling of every row and column
+ std::vector<int> all_maxima ; //for the maximal values of all toggled
+ //matrices
+ int rowlen = matrix[0].size( ) ;
+ int startvalue = to_binary_sum( matrix ) ;
+ //if all toggling results in a binary sum that is less than startvalue
+ //we can stop
+ for ( int r = 0 ; r < matrixlen ; r++ ) {
+ std::vector<std::vector<int>> toggled ( toggle_row( matrix , r ) ) ;
+ binary_row_sums.push_back( to_binary_sum( toggled ) ) ;
+ }
+ std::vector<std::vector<int>> transposed ( transpose( matrix ) ) ;
+ for ( int c = 0 ; c < rowlen ; c++ ) {
+ std::vector<std::vector<int>> transpo_toggle ( toggle_row(
+ transposed , c ) ) ;
+ std::vector<std::vector<int>> toggled( transpose( transpo_toggle )) ;
+ binary_row_sums.push_back( to_binary_sum( toggled )) ;
+ }
+ int maximum = *std::max_element( binary_row_sums.begin( ) ,
+ binary_row_sums.end( ) ) ;
+ if ( maximum < startvalue ) { //we're done and can stop toggling
+ std::cout << maximum << std::endl ;
+ return 0 ;
+ }
+ else {
+ all_maxima.push_back( maximum ) ;
+ std::vector<std::vector<int>> current_matrix( matrix ) ;
+ //the matrix that corresponds to the maximum binary sum is
+ //reconstructed as new current matrix. Then we repeat toggling
+ //every row and column and find the new maximum. As long as the
+ //new maximum is greater than the last maximum, we carry on ;
+ //otherwise, we return the second from the end of all_maxima
+ while ( all_maxima.size( ) == 1 || all_maxima.back( ) >
+ all_maxima[ all_maxima.size( ) - 2] ) {
+ auto found = std::find( binary_row_sums.begin( ) ,
+ binary_row_sums.end( ) , maximum ) ;
+ int max_pos = static_cast<int>( std::distance(
+ binary_row_sums.begin( ) , found )) ;
+ if ( max_pos < matrixlen ) { //maximum resulted from row toggle
+ std::vector<std::vector<int>> temp_matrix( toggle_row(
+ current_matrix , max_pos )) ;
+ current_matrix = temp_matrix ;
+ }
+ else { //maximum resulted from column toggle
+ transposed = transpose( current_matrix ) ;
+ std::vector<std::vector<int>> transpo_toggled =
+ toggle_row( transposed , max_pos - matrixlen ) ;
+ current_matrix = transpose( transpo_toggled ) ;
+ }
+ binary_row_sums.clear( ) ; //we start toggling anew, new sums!
+ for ( int r = 0 ; r < matrixlen ; r++ ) {
+ std::vector<std::vector<int>> toggled =
+ toggle_row( current_matrix , r ) ;
+ binary_row_sums.push_back( to_binary_sum( toggled )) ;
+ }
+ transposed = transpose( current_matrix ) ;
+ for ( int c = 0 ; c < rowlen ; c++ ) {
+ std::vector<std::vector<int>> transpo_toggled =
+ toggle_row( transposed , c ) ;
+ std::vector<std::vector<int>> toggled (transpose(
+ transpo_toggled )) ;
+ binary_row_sums.push_back( to_binary_sum( toggled ) ) ;
+ }
+ maximum = *std::max_element( binary_row_sums.begin( ) ,
+ binary_row_sums.end( ) ) ;
+ all_maxima.push_back( maximum ) ;
+ }
+ std::cout << all_maxima[ all_maxima.size( ) - 2] << std::endl ;
+ }
+ }
+ return 0 ;
+}
diff --git a/challenge-218/ulrich-rieke/haskell/ch-1.hs b/challenge-218/ulrich-rieke/haskell/ch-1.hs
new file mode 100644
index 0000000000..5b86d64696
--- /dev/null
+++ b/challenge-218/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,22 @@
+module Challenge218
+ where
+import Data.List ( (!!) )
+
+combi_of_three :: [Int] -> [[Int]]
+combi_of_three list = [[list !! i , list !! j , list !! k] | i <- [0..l - 3] ,
+j <- [i + 1..l - 2] , k <- [j + 1..l - 1]]
+where
+ l :: Int
+ l = length list
+
+solution :: [Int] -> Int
+solution list
+ |length list == 3 = product list
+ |otherwise = maximum $ map product $ combi_of_three list
+
+main :: IO ( )
+main = do
+ putStrLn "Enter at least 3 integers, separated by blanks!"
+ numberstring <- getLine
+ let numbers = map read $ words numberstring
+ print $ solution numbers
diff --git a/challenge-218/ulrich-rieke/haskell/ch-2.hs b/challenge-218/ulrich-rieke/haskell/ch-2.hs
new file mode 100644
index 0000000000..b40991078f
--- /dev/null
+++ b/challenge-218/ulrich-rieke/haskell/ch-2.hs
@@ -0,0 +1,55 @@
+module Challenge218_2
+ where
+import Data.List ( (!!) , transpose , sortOn )
+import Control.Monad.State.Lazy
+
+toggle :: [Int] -> [Int]
+toggle list = map (\n -> if n == 1 then 0 else 1 ) list
+
+to_row_sum :: [Int] -> Int
+to_row_sum list = sum $ map (\i -> 2 ^ i * ( list !! (l - i - 1)))
+[0..l - 1]
+where
+ l :: Int
+ l = length list
+
+do_all_toggles :: [[Int]] -> [[[Int]]]
+do_all_toggles matrix = map (\i -> toggleRow i matrix) [0..length matrix - 1]
+++ map (\n -> toggleColumn n matrix ) [0..(length ( matrix !! 0 ) - 1)]
+ where
+ toggleRow :: Int -> [[Int]] -> [[Int]]
+ toggleRow aRow aMatrix = map (\i -> if i == aRow then
+ toggle ( matrix !! i ) else matrix !! i ) [0..length aMatrix - 1]
+
+toggleColumn :: Int -> [[Int]] -> [[Int]]
+toggleColumn column matrix = transpose $ map (\i -> if i == column then toggle
+( transposed !! i ) else transposed !! i ) [0..length transposed - 1]
+ where
+ transposed :: [[Int]]
+ transposed = transpose matrix
+
+find_maximum_toggle :: [[[Int]]] -> (Int , [[Int]])
+find_maximum_toggle allTogglings = last $ sortOn fst $ map (\aMatrix ->
+ (matrixSum aMatrix , aMatrix )) allTogglings
+ where
+ matrixSum :: [[Int]] -> Int
+ matrixSum someMatrix = sum $ map to_row_sum someMatrix
+
+findMaxSum :: State ((Int , [[Int]] ),[Int] ) Int
+findMaxSum = do
+ ((maxVal , matrix) , allmaxima) <- get
+ let l = length allmaxima
+ if l > 1 && (allmaxima !! ( l - 1 )) < ( allmaxima !!
+ ( l - 2 ))
+ then
+ return $ allmaxima !! (l - 2)
+ else do
+ let (m , toggles ) = find_maximum_toggle $ do_all_toggles matrix
+ put (( m , toggles ) , allmaxima ++ [m] )
+ findMaxSum
+
+solution :: [[Int]] -> Int
+solution input
+ |length input == 1 = to_row_sum $ toggle $ input !! 0
+ |otherwise = evalState findMaxSum ( find_maximum_toggle $
+ do_all_toggles input , [] )
diff --git a/challenge-218/ulrich-rieke/perl/ch-1.pl b/challenge-218/ulrich-rieke/perl/ch-1.pl
new file mode 100644
index 0000000000..f9527b9713
--- /dev/null
+++ b/challenge-218/ulrich-rieke/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use Algorithm::Combinatorics qw ( combinations ) ;
+use List::Util qw ( product max ) ;
+
+say "Enter at least 3 integers, separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s/ , $line ) ;
+if ( scalar( @numbers ) == 3 ) {
+ say product( @numbers ) ;
+}
+else {
+ my @products ;
+ my $iter = combinations( \@numbers , 3 ) ;
+ while ( my $c = $iter->next ) {
+ push @products , product( @{$c} ) ;
+ }
+ say max( @products ) ;
+}
diff --git a/challenge-218/ulrich-rieke/perl/ch-2.pl b/challenge-218/ulrich-rieke/perl/ch-2.pl
new file mode 100644
index 0000000000..fa66a62438
--- /dev/null
+++ b/challenge-218/ulrich-rieke/perl/ch-2.pl
@@ -0,0 +1,140 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( max ) ;
+
+sub toggle_row {
+ my $array = shift ;
+ my $row = shift ;
+ my @changed_array = @{$array} ;#dereference to preserve the original array!
+ my @subarray = @{$changed_array[$row]} ;
+ for my $i ( 0..scalar(@subarray) - 1 ) {
+ if ( $subarray[ $i ] == 0 ) {
+ $subarray[ $i ] = 1 ;
+ }
+ else {
+ $subarray[ $i ] = 0 ;
+ }
+ }
+ $changed_array[ $row ] = [ @subarray ] ;
+ return @changed_array ;
+}
+
+sub toggle_column {
+ my $array = shift ;
+ my $column = shift ;
+ my @changed_array ;
+ for my $ar ( @{$array} ) {
+ my @subarray = @{$ar} ;
+ if ( $subarray[ $column ] == 0 ) {
+ $subarray[ $column ] = 1 ;
+ }
+ else {
+ $subarray[ $column ] = 0 ;
+ }
+ push @changed_array , [ @subarray ] ;
+ }
+ return @changed_array ;
+}
+
+sub find_index {
+ my $searched = shift ;
+ my $array = shift ;
+ my $pos = 0 ;
+ while ( $array->[$pos] != $searched ) {
+ $pos++ ;
+ }
+ return $pos ;
+}
+
+sub to_binary_sum {
+ my $array = shift ;
+ my $sum = 0 ;
+ for my $subarray( @{$array} ) {
+ my $sublen = scalar( @{$subarray} ) ;
+ for my $i (0..$sublen - 1 ) {
+ $sum += 2 ** ($sublen - 1 - $i ) * $subarray->[ $i ] ;
+ }
+ }
+ return $sum ;
+}
+
+
+say "Enter an m x n array of 0 and 1 only, blanks to separate!" ;
+say "Enter end to end!" ;
+my @matrix ;
+my $line = <STDIN> ;
+my $maximum ; #the maximum of all moves of a given matrix
+chomp $line ;
+while ( $line ne "end" ) {
+ my @numbers = split( /\s/ , $line ) ;
+ push @matrix, \@numbers ;
+ $line = <STDIN> ;
+ chomp $line ;
+}
+my $matrixlen = scalar( @matrix ) ;
+my $rowlen = scalar( @{$matrix[0]} ) ;
+if ( $matrixlen == 1 ) {
+ my @toggled = toggle_row( \@matrix , 0 ) ;
+ say to_binary_sum( \@toggled ) ;
+}
+else {
+ my @matrix_bin_sums ; #holds the binary row sums of all transformations of a
+#given matrix
+ my @all_maxima ; #holds the maxima of all transformations
+ for my $r (0..$matrixlen - 1 ) {
+ my @toggled = toggle_row( \@matrix , $r ) ;
+ push @matrix_bin_sums , to_binary_sum( \@toggled ) ;
+ }
+ for my $c (0..$rowlen - 1) {
+ my @toggled = toggle_column( \@matrix , $c ) ;
+ push @matrix_bin_sums , to_binary_sum( \@toggled ) ;
+ }
+ $maximum = max(@matrix_bin_sums) ;
+ push @all_maxima, $maximum ;
+ if ( $maximum < to_binary_sum( \@matrix )) { #we don't improve on toggling
+ say $maximum ;
+ }
+ else {
+#we find the maximum binary sum which results from toggling every row and every
+#column of a given matrix. Once we've got it, we reconstruct the matrix that
+#produces that maximum. For that , we find the position of the maximum in the
+#@matrix_bin_sums array. Since we toggle the rows first and the columns next, we
+#can derive the matrix that produced the maximum. It becomes our new current matrix.
+#We continue until the values of the maxima begin to fall. We then return the former
+#greatest maximum
+ my @current_matrix ;
+ for my $ar ( @matrix ) { #we duplicate the start matrix to have a current
+#matrix which we keep changing until the above condition is fulfilled
+ push @current_matrix , $ar ;
+ }
+ while ( scalar( @all_maxima ) == 1 || $all_maxima[-1] > $all_maxima[ -2 ] ) {
+ my $pos = find_index( $maximum , \@matrix_bin_sums ) ;
+ my @toggled ;
+ if ( $pos < $matrixlen ) {
+ @toggled = toggle_row( \@current_matrix, $pos ) ;
+ }
+ else {
+ @toggled = toggle_column( \@current_matrix, $pos - $matrixlen ) ;
+ }
+ @current_matrix = ( ) ; #we must unset this variable to overwrite with the
+#toggle position that produced the maximum
+ @matrix_bin_sums = ( ) ; #new matrix , new binary row sums!
+ for my $ar( @toggled ) {
+ push @current_matrix , $ar ;
+ }
+ for my $r (0..$matrixlen - 1 ) {
+ @toggled = toggle_row( \@current_matrix , $r ) ;
+ push @matrix_bin_sums, to_binary_sum( \@toggled ) ;
+ }
+ for my $c (0..$rowlen - 1 ) {
+ @toggled = toggle_column( \@current_matrix, $c ) ;
+ push @matrix_bin_sums , to_binary_sum( \@toggled ) ;
+ }
+ $maximum = max( @matrix_bin_sums ) ;
+ push @all_maxima , $maximum ;
+ }
+ say $all_maxima[-2] ;
+ }
+}
diff --git a/challenge-218/ulrich-rieke/raku/ch-1.raku b/challenge-218/ulrich-rieke/raku/ch-1.raku
new file mode 100644
index 0000000000..1a02fe2f5b
--- /dev/null
+++ b/challenge-218/ulrich-rieke/raku/ch-1.raku
@@ -0,0 +1,21 @@
+use v6 ;
+
+say "Please enter at least 3 integers, separated by blanks!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+if ( @numbers.elems == 3 ) {
+ say [*] @numbers ;
+}
+else {
+ my @products ;
+ my @combinations = @numbers.combinations( 3 ) ;
+ for @combinations -> $combi {
+ my $prod = 1 ;
+ for (0..2) -> $i {
+ $prod *= $combi[ $i ] ;
+ }
+ @products.push( $prod ) ;
+ }
+ my @sorted = @products.sort( { $^b <=> $^a } ) ;
+ say @sorted[ 0 ] ;
+}
diff --git a/challenge-218/ulrich-rieke/rust/ch-1.rs b/challenge-218/ulrich-rieke/rust/ch-1.rs
new file mode 100644
index 0000000000..a23cffc9e4
--- /dev/null
+++ b/challenge-218/ulrich-rieke/rust/ch-1.rs
@@ -0,0 +1,22 @@
+use std::io ;
+use itertools::Itertools ;
+
+fn main() {
+ println!("Enter at least 3 integers, separated by blanks!");
+ let mut inline : String = String::new( ) ;
+ io::stdin( ).read_line( &mut inline ).unwrap( ) ;
+ let entered_line : &str = &*inline ;
+ let numbers : Vec<i32> = entered_line.split_whitespace( ).map ( | s |
+ s.trim( ).parse::<i32>( ).unwrap( ) ).collect( ) ;
+ if numbers.len( ) == 3 {
+ println!("{}" , numbers.iter( ).product::<i32>( ) ) ;
+ }
+ else {
+ let mut products : Vec<i32> = Vec::new( ) ;
+ let it = numbers.into_iter( ).combinations( 3 ) ;
+ for a_vec in it {
+ products.push( a_vec.iter( ).product( ) ) ;
+ }
+ println!("{}" , products.iter( ).max( ).unwrap( ) ) ;
+ }
+}
diff --git a/stats/pwc-challenge-105.json b/stats/pwc-challenge-105.json
index 62c8a1db32..b0678c0e2b 100644
--- a/stats/pwc-challenge-105.json
+++ b/stats/pwc-challenge-105.json
@@ -1,13 +1,24 @@
{
- "subtitle" : {
- "text" : "[Champions: 26] Last updated at 2021-07-04 09:37:10 GMT"
- },
- "xAxis" : {
- "type" : "category"
+ "tooltip" : {
+ "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>",
+ "followPointer" : 1,
+ "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>"
},
"chart" : {
"type" : "column"
},
+ "plotOptions" : {
+ "series" : {
+ "dataLabels" : {
+ "enabled" : 1,
+ "format" : "{point.y}"
+ },
+ "borderWidth" : 0
+ }
+ },
+ "xAxis" : {
+ "type" : "category"
+ },
"legend" : {
"enabled" : 0
},
@@ -16,38 +27,39 @@
"text" : "Total Solutions"
}
},
+ "subtitle" : {
+ "text" : "[Champions: 27] Last updated at 2023-05-24 16:59:49 GMT"
+ },
"title" : {
"text" : "The Weekly Challenge - 105"
},
"series" : [
{
- "name" : "The Weekly Challenge - 105",
- "colorByPoint" : 1,
"data" : [
{
- "y" : 3,
"drilldown" : "Aaron Smith",
- "name" : "Aaron Smith"
+ "name" : "Aaron Smith",
+ "y" : 3
},
{
- "name" : "Abigail",
"drilldown" : "Abigail",
- "y" : 3
+ "y" : 3,
+ "name" : "Abigail"
},
{
"drilldown" : "Adam Russell",
- "name" : "Adam Russell",
- "y" : 3
+ "y" : 3,
+ "name" : "Adam Russell"
},
{
"name" : "Arne Sommer",
- "drilldown" : "Arne Sommer",
- "y" : 5
+ "y" : 5,
+ "drilldown" : "Arne Sommer"
},
{
"name" : "Cheok-Yin Fung",
- "drilldown" : "Cheok-Yin Fung",
- "y" : 1
+ "y" : 1,
+ "drilldown" : "Cheok-Yin Fung"
},
{
"drilldown" : "Colin Crain",
@@ -61,8 +73,8 @@
},
{
"drilldown" : "Dave Jacoby",
- "name" : "Dave Jacoby",
- "y" : 3
+ "y" : 3,
+ "name" : "Dave Jacoby"
},
{
"y" : 2,
@@ -70,18 +82,18 @@
"drilldown" : "Duncan C. White"
},
{
- "name" : "E. Choroba",
"drilldown" : "E. Choroba",
+ "name" : "E. Choroba",
"y" : 2
},
{
- "drilldown" : "Flavio Poletti",
+ "y" : 4,
"name" : "Flavio Poletti",
- "y" : 4
+ "drilldown" : "Flavio Poletti"
},
{
- "y" : 5,
"drilldown" : "Jaldhar H. Vyas",
+ "y" : 5,
"name" : "Jaldhar H. Vyas"
},
{
@@ -90,49 +102,54 @@
"y" : 3
},
{
+ "name" : "Jan Krnavek",
"y" : 1,
- "drilldown" : "Jan Krnavek",
- "name" : "Jan Krnavek"
+ "drilldown" : "Jan Krnavek"
},
{
- "y" : 2,
"drilldown" : "Joan Mimosinnet",
+ "y" : 2,
"name" : "Joan Mimosinnet"
},
{
+ "y" : 2,
"name" : "Jorg Sommrey",
- "drilldown" : "Jorg Sommrey",
- "y" : 2
+ "drilldown" : "Jorg Sommrey"
},
{
"y" : 5,
- "drilldown" : "Laurent Rosenfeld",
- "name" : "Laurent Rosenfeld"
+ "name" : "Laurent Rosenfeld",
+ "drilldown" : "Laurent Rosenfeld"
+ },
+ {
+ "drilldown" : "Lubos Kolouch",
+ "y" : 2,
+ "name" : "Lubos Kolouch"
},
{
- "name" : "Luca Ferrari",
"drilldown" : "Luca Ferrari",
- "y" : 4
+ "y" : 4,
+ "name" : "Luca Ferrari"
},
{
- "drilldown" : "Mark Anderson",
"name" : "Mark Anderson",
- "y" : 2
+ "y" : 2,
+ "drilldown" : "Mark Anderson"
},
{
+ "drilldown" : "Niels van Dijke",
"y" : 1,
- "name" : "Niels van Dijke",
- "drilldown" : "Niels van Dijke"
+ "name" : "Niels van Dijke"
},
{
"name" : "Paulo Custodio",
- "drilldown" : "Paulo Custodio",
- "y" : 2
+ "y" : 2,
+ "drilldown" : "Paulo Custodio"
},
{
"y" : 2,
- "drilldown" : "Pete Houston",
- "name" : "Pete Houston"
+ "name" : "Pete Houston",
+ "drilldown" : "Pete Houston"
},
{
"y" : 5,
@@ -141,36 +158,24 @@
},
{
"drilldown" : "Stuart Little",