From ec6cd1c30040e2337fd679057608aba79aa17427 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Fri, 22 Aug 2025 00:14:43 +0100 Subject: - Added solutions by Ulrich Rieke. --- challenge-335/ulrich-rieke/cpp/ch-1.cpp | 76 +++++++++++++++++++++ challenge-335/ulrich-rieke/cpp/ch-2.cpp | 86 ++++++++++++++++++++++++ challenge-335/ulrich-rieke/haskell/ch-1.hs | 45 +++++++++++++ challenge-335/ulrich-rieke/haskell/ch-2.hs | 81 +++++++++++++++++++++++ challenge-335/ulrich-rieke/perl/ch-1.pl | 60 +++++++++++++++++ challenge-335/ulrich-rieke/perl/ch-2.pl | 103 +++++++++++++++++++++++++++++ challenge-335/ulrich-rieke/raku/ch-1.raku | 25 +++++++ challenge-335/ulrich-rieke/raku/ch-2.raku | 93 ++++++++++++++++++++++++++ challenge-335/ulrich-rieke/rust/ch-1.rs | 47 +++++++++++++ challenge-335/ulrich-rieke/rust/ch-2.rs | 81 +++++++++++++++++++++++ stats/pwc-current.json | 21 +++++- stats/pwc-language-breakdown-2019.json | 2 +- stats/pwc-language-breakdown-2020.json | 2 +- stats/pwc-language-breakdown-2021.json | 2 +- stats/pwc-language-breakdown-2022.json | 2 +- stats/pwc-language-breakdown-2023.json | 2 +- stats/pwc-language-breakdown-2024.json | 2 +- stats/pwc-language-breakdown-2025.json | 8 +-- stats/pwc-language-breakdown-summary.json | 6 +- stats/pwc-leaders.json | 8 +-- stats/pwc-summary-1-30.json | 2 +- stats/pwc-summary-121-150.json | 2 +- stats/pwc-summary-151-180.json | 2 +- stats/pwc-summary-181-210.json | 2 +- stats/pwc-summary-211-240.json | 2 +- stats/pwc-summary-241-270.json | 2 +- stats/pwc-summary-271-300.json | 2 +- stats/pwc-summary-301-330.json | 6 +- stats/pwc-summary-31-60.json | 2 +- stats/pwc-summary-61-90.json | 2 +- stats/pwc-summary-91-120.json | 2 +- stats/pwc-summary.json | 8 +-- stats/pwc-yearly-language-summary.json | 8 +-- 33 files changed, 755 insertions(+), 39 deletions(-) create mode 100755 challenge-335/ulrich-rieke/cpp/ch-1.cpp create mode 100755 challenge-335/ulrich-rieke/cpp/ch-2.cpp create mode 100755 challenge-335/ulrich-rieke/haskell/ch-1.hs create mode 100755 challenge-335/ulrich-rieke/haskell/ch-2.hs create mode 100755 challenge-335/ulrich-rieke/perl/ch-1.pl create mode 100755 challenge-335/ulrich-rieke/perl/ch-2.pl create mode 100755 challenge-335/ulrich-rieke/raku/ch-1.raku create mode 100755 challenge-335/ulrich-rieke/raku/ch-2.raku create mode 100755 challenge-335/ulrich-rieke/rust/ch-1.rs create mode 100755 challenge-335/ulrich-rieke/rust/ch-2.rs diff --git a/challenge-335/ulrich-rieke/cpp/ch-1.cpp b/challenge-335/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..e516fd314a --- /dev/null +++ b/challenge-335/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include + +std::vector split( const std::string & text , char delimiter) { + std::vector tokens ; + std::istringstream istr { text } ; + std::string word ; + while ( std::getline( istr , word , delimiter )) + tokens.push_back( word ) ; + return tokens ; +} + +std::string findCommonCharacters( const std::string & aWord , + const std::string & bWord ) { + std::string common ; + for ( auto l : aWord ) { + if ( bWord.find( l ) != std::string::npos ) { + common.push_back( l ) ; + } + } + std::sort( common.begin( ) , common.end( ) ) ; + auto last = std::unique( common.begin( ) , common.end( ) ) ; + common.erase( last , common.end( ) ) ; + return common ; +} + +int main( ) { + std::cout << "Enter some words separated by whitespace!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + auto tokens { split( line , ' ' ) } ; + std::map> letterfrequencies ; + std::string common { findCommonCharacters( tokens[0] , + tokens[1]) } ; + for ( int i = 1 ; i < tokens.size( ) ; i++ ) { + common = findCommonCharacters( common , tokens[i] ) ; + } + if ( common.empty( ) ) { + std::cout << "()\n" ; + } + else { + for ( auto w : tokens ) { + std::map frequency_in_word ; + for ( auto l : w ) { + if ( common.find( l ) != std::string::npos ) { + frequency_in_word[l]++ ; + } + } + for ( auto it = frequency_in_word.begin( ) ; it != + frequency_in_word.end( ) ; ++it ) { + letterfrequencies[it->first].push_back( it->second ) ; + } + } + std::vector result ; + std::sort( common.begin( ) , common.end( ) ) ; + for ( char l : common ) { + auto foundFrequencies = letterfrequencies.find( l )->second ; + int howmany = *std::min_element( foundFrequencies.begin( ) , + foundFrequencies.end( ) ) ; + for ( int i = 0 ; i < howmany ; i++ ) { + result.push_back( l ) ; + } + } + std::cout << "( " ; + for ( char l : result ) { + std::cout << l << ' ' ; + } + std::cout << ")\n" ; + } + return 0 ; +} diff --git a/challenge-335/ulrich-rieke/cpp/ch-2.cpp b/challenge-335/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..d80899b5dc --- /dev/null +++ b/challenge-335/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +#include + +int main( ) { + std::cout << "Enter some integers between 0 and 2 in brackets, separated by ,!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::string for_number ( "\\d" ) ; + std::regex np { for_number } ; + std::vector numbers ; + auto end = std::sregex_token_iterator{} ; + for ( auto it = std::sregex_token_iterator{ std::begin( line ) , + std::end( line ) , np } ; it != end ; ++it ) { + numbers.push_back( std::stoi( *it ) ) ; + } + std::vector> boardpoints ; + int len = numbers.size( ) ; + for ( int i = 0 ; i < len - 1 ; i += 2 ) + boardpoints.push_back( std::make_pair( numbers[i] , numbers[i + 1] ) ) ; + //tictactoe board as an array of characters + std::array row ; + row.fill( '_' ) ; + std::array , 3> tictactoe ; + tictactoe.fill( row ) ; + for ( int i = 0 ; i < boardpoints.size( ) ; i++ ) { + int row = boardpoints[i].first ; + int column = boardpoints[i].second ; + if ( i % 2 == 0 ) { + tictactoe[row][column] = 'A' ; + } + else { + tictactoe[row][column] = 'B' ; + } + } + //one row with equal characters ? + auto rit = std::find_if( tictactoe.begin( ) , tictactoe.end( ) , []( const auto & r) + { char c = r[0] ; return std::all_of( r.begin( ) , r.end( ) , [c]( auto + letter) { return letter == c && letter != '_' ; } ) ;}) ; + if ( rit != tictactoe.end( ) ) { + std::cout << (*rit)[0] << '\n' ; + return 0 ; + } + //one column with equal characters ? + std::vector column ; + std::vector> transposed ; + for ( int c = 0 ; c < 3 ; c++ ) { + for ( int r = 0 ; r < 3 ; r++ ) { + column.push_back( tictactoe[r][c] ) ; + } + transposed.push_back( column ) ; + } + auto it = std::find_if( transposed.begin( ) , transposed.end( ) , []( const auto r ) + { char head = r[0] ; return std::all_of( r.begin( ) , r.end( ) , [head]( auto + letter ) { return letter == head && letter != '_' ; } ) ;}) ; + if ( it != transposed.end( )) { + std::cout << (*it)[0] << '\n' ; + return 0 ; + } + //is one diagonal filled with the same characters ? + if ( tictactoe[0][0] == tictactoe[1][1] && tictactoe[1][1] == tictactoe[2][2] && + tictactoe[1][1] != '_' ) { + std::cout << tictactoe[0][0] << '\n' ; + return 0 ; + } + //what about the other diagonal ? + if ( tictactoe[2][0] == tictactoe[1][1] && tictactoe[1][1] == tictactoe[0][2] && + tictactoe[1][1] != '_' ) { + std::cout << tictactoe[2][0] << '\n' ; + return 0 ; + } + //no decision so far and all fields filled with letters => draw! + if ( std::all_of( tictactoe.begin( ) , tictactoe.end( ) , []( const auto & r ) { + return std::all_of( r.begin( ) , r.end( ) , []( const auto letter ) { + return (letter == 'A' || letter == 'B') ; }) ;})) { + std::cout << "Draw\n" ; + return 0 ; + } + //if we haven't returned up to this point it's pending + std::cout << "Pending\n" ; + return 0 ; +} diff --git a/challenge-335/ulrich-rieke/haskell/ch-1.hs b/challenge-335/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..6d7ac4be65 --- /dev/null +++ b/challenge-335/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,45 @@ +module Challenge355 + where +import qualified Data.Set as S +import Data.List ( sortOn , groupBy , intersperse) + +findCommonChars :: [String] -> [Char] +findCommonChars = S.toList . foldl1 S.intersection . map S.fromList + +count :: Eq a => a -> [a] -> Int +count _ [] = 0 +count d (x:xs) + |d == x = 1 + count d xs + |otherwise = count d xs + +wordFrequencies :: String -> String -> [(Char , Int)] +wordFrequencies aWord common = map (\l -> (l , count l aWord )) $ filter + (\l -> elem l common ) aWord + +consolidate :: [[(Char , Int)]] -> [(Char , [Int])] +consolidate frequencies = + let consolidated = concat frequencies + sorted = sortOn fst consolidated + grouped = groupBy(\a b -> fst a == fst b ) sorted + in map(\subli -> ( fst $ head subli, map snd subli)) grouped + +findFrequencies :: [String] -> [(Char , [Int])] +findFrequencies theWords = + let commonChars = findCommonChars theWords + frequenciesInWords = map (\w -> wordFrequencies w commonChars ) + theWords + in consolidate frequenciesInWords + +printResult :: [(Char , [Int])] -> String +printResult letterlists = intersperse ',' $ concat $ map (\p -> + replicate ( snd p )( fst p )) $ map (\p -> ( fst p , minimum $ snd p )) + $ sortOn fst letterlists + +main :: IO ( ) +main = do + putStrLn "Enter some words separated by whitespace!" + wordline <- getLine + print $ printResult $ findFrequencies $ words wordline + + + diff --git a/challenge-335/ulrich-rieke/haskell/ch-2.hs b/challenge-335/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..ad06867aa3 --- /dev/null +++ b/challenge-335/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,81 @@ +{-# LANGUAGE MultiWayIf #-} +module Challenge335_2 + where +import Data.List ( (!!) , transpose , findIndex , findIndices) +import Data.Char ( digitToInt ) +import Data.List.Split ( chunksOf ) + +parseEntryLine :: String -> [(Int , Int)] +parseEntryLine line = map (\i -> ( digitToInt (line !! (i + 1 )) , digitToInt (line !! (i + 3 )))) + $ findIndices ( == '[' ) line + +tictacboard :: [String] +tictacboard = ["___" , "___" , "___"] + +modifyBoard :: [String] -> (Int , (Int , Int)) -> [String] +modifyBoard board (n , p ) + |even n = if + |offset == 0 -> chunksOf 3 ( "A" ++ drop 1 letterrow ) + |offset > 0 && offset < 8 -> chunksOf 3 ( take offset letterrow ++ "A" ++ drop ( offset + 1 ) + letterrow ) + |offset == 8 -> chunksOf 3 ( take 8 letterrow ++ "A" ) + |otherwise = if + |offset == 0 -> chunksOf 3 ( "B" ++ drop 1 letterrow ) + |offset > 0 && offset < 8 -> chunksOf 3 ( take offset letterrow ++ "B" ++ drop ( offset + 1 ) + letterrow ) + |offset == 0 -> chunksOf 3 ( take 8 letterrow ++ "B" ) + where + letterrow = concat board + offset = fst p * 3 + snd p + +modifyTictacBoard coordinates = + let zipped = zip [0 , 1 ..] coordinates + in foldl modifyBoard tictacboard zipped + +rowEqual :: [String] -> Bool +rowEqual board = any (\r -> all (\l -> l == r !! 0 && l /= '_' ) r ) board + +columnEqual :: [String] -> Bool +columnEqual = rowEqual . transpose + +oneDiagonal :: [String] -> Bool +oneDiagonal board = and [board !! 0 !! 0 == board !! 1 !! 1 , board !! 1 !! 1 == + board !! 2 !! 2 , board !! 1 !! 1 /= '_' ] + +otherDiagonal :: [String] -> Bool +otherDiagonal board = and [board !! 2 !! 0 == board !! 1 !! 1 , board !! 1 !! 1 == + board !! 0 !! 2 , board !! 1 !! 1 /= '_' ] + +isDraw :: [String] -> Bool +isDraw board = + let values = [rowEqual board , columnEqual board , oneDiagonal board , otherDiagonal board] + in all (== False ) values && all (\r -> all ( (/= '_') ) r ) board + +isPending :: [String] -> Bool +isPending board = + let values = [rowEqual board , columnEqual board , oneDiagonal board, otherDiagonal board, + isDraw board] + in all (== False ) values + +findOutput :: [String] -> String +findOutput board + |rowEqual board = case findIndex (\r -> all (\l -> l == (r !! 0)) r ) board of + Just i -> [board !! i !! 0] + Nothing -> " " + |columnEqual board = case findIndex(\r -> all (\l -> l == ( r !! 0 )) r ) transposed of + Just i -> [transposed !! i !! 0] + Nothing -> " " + |oneDiagonal board = [board !! 0 !! 0] + |otherDiagonal board = [board !! 2 !! 0 ] + |isDraw board = "Draw" + |isPending board = "Pending" + where + transposed = transpose board + +main :: IO ( ) +main = do + putStrLn "Enter some numbers between 0 and 2 in brackets separated by commas!" + numberline <- getLine + let pairs = parseEntryLine numberline + board = modifyTictacBoard pairs + print $ findOutput board diff --git a/challenge-335/ulrich-rieke/perl/ch-1.pl b/challenge-335/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..a85f5c9b69 --- /dev/null +++ b/challenge-335/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use List::Util qw ( min ) ; + +#common letters of two words +sub intersect { + my $first = shift ; + my $second = shift ; + my %firstfreq ; + my %secondfreq ; + my %common ; + map { $firstfreq{$_}++ } split( // , $first ) ; + map {$secondfreq{$_}++ } split( // , $second ) ; + for my $letter( keys %firstfreq ) { + if ( exists( $secondfreq{$letter} ) ) { + $common{$letter}++ ; + } + } + return join( '' , keys %common ) ; +} + +say "Enter some words separated by whitespace!" ; +my $line = ; +chomp $line ; +my @words = split( /\s+/ , $line ) ; +my $len = scalar( @words ) ; +#find common letters of all words , if there are any +my $common = intersect( $words[0] , $words[1] ) ; +for my $i ( 1..$len - 2 ) { + $common = intersect( $common , $words[$i + 1] ) ; +} +my %commonfrequencies ;#for every letter common to all words , it holds + #their respective frequencies +for my $w ( @words ) { + my %wordfrequencies ;#frequencies of the common letters + for my $letter( split( // , $w ) ) { + if ( index( $common , $letter ) != -1 ) { + $wordfrequencies{$letter}++ ; + } + } + for my $letter( keys %wordfrequencies ) { + push( @{$commonfrequencies{$letter}} , $wordfrequencies{$letter} ) ; + } +} +if ( $common ) {#do we have common letters ? + my @solution ; + my @sorted = sort split( // , $common ) ; + for my $letter( split( // , $common ) ) { + my $times = min ( @{$commonfrequencies{$letter}} ) ; + for (1..$times) { + push( @solution , $letter ) ; + } + } + say '('. join( ',' , @solution ) . ')' ; +} +else { + say "()" ; +} diff --git a/challenge-335/ulrich-rieke/perl/ch-2.pl b/challenge-335/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..688d90b3bf --- /dev/null +++ b/challenge-335/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use List::Util qw ( all ) ; + +say "Enter some numbers between 0 and 2 in brackets!" ; +my $line = ; +chomp $line ; +my @pairs ; +while ( $line =~ /\[\s*(\d+)\s*\,\s*(\d+)\s*\]/cg ) { + push ( @pairs , [$1 , $2] ) ; +} +my @tictactoe ; #an array of strings as a substitute for the board +for (1..3 ) { + push( @tictactoe , "___" ) ; +} +my $counter = 0 ; +for my $pair( @pairs ) { + if ( $counter % 2 == 0 ) { + substr( $tictactoe[$pair->[0]] , $pair->[1] , 1 ) = 'A' ; + } + else { + substr( $tictactoe[$pair->[0]] , $pair->[1] , 1 ) = 'B' ; + } + $counter++ ; +} +my $row_equal = 0 ; # all letters in a row equal ? supposed to be wrong +for my $str( @tictactoe ) { + if ( $str eq "AAA" || $str eq "BBB" ) { + $row_equal = 1 ; + } +} +my @transposed ; #transpose the tictactoe field +for my $col( 0..2 ) { + my $transpo ; + for my $row( 0..2 ) { + $transpo .= substr( $tictactoe[$row] , $col , 1 ) ; + } + push( @transposed , $transpo ) ; +} +my $column_equal = 0 ;#are all columns equal ? supposed to be wrong +for my $str( @transposed ) { + if ( $str eq "AAA" || $str eq "BBB" ) { + $column_equal = 1 ; + } +} +my $first_diagonal .= substr($tictactoe[0] , 0 , 1 ) . substr( $tictactoe[1] , 1 , + 1 ) . substr( $tictactoe[2] , 2 , 1 ) ; +my $left_diagonal_down = 0 ; +if ( $first_diagonal eq "AAA" || $first_diagonal eq "BBB" ) { + $left_diagonal_down = 1 ; +} +my $second_diagonal .= substr( $tictactoe[2] , 0 , 1 ) . substr( $tictactoe[1] , + 1 , 1 ) . substr( $tictactoe[0] , 2 , 1 ) ; +my $from_left_up = 0 ; +if ( $second_diagonal eq "AAA" || $second_diagonal eq "BBB" ) { + $from_left_up = 1 ; +} +my $maybe_drawn = 0 ; +if (all { $_ == 0 } ($column_equal , $row_equal , $left_diagonal_down , + $from_left_up )) { + $maybe_drawn = 1 ; +} +my $is_drawn = 0 ; +if ( $maybe_drawn) { + if ( all { $_ !~ /_/ } @tictactoe ) { + $is_drawn = 1 ; + } +} +if ( all { $_ == 0 } ( $column_equal , $row_equal , $left_diagonal_down , + $from_left_up , $is_drawn) ) { + say "Pending" ; +} +if ( $row_equal ) { + for my $string( @tictactoe ) { + if ( $string eq "AAA" ) { + say "A" ; + } + if ( $string eq "BBB" ) { + say "B" ; + } + } +} +if ( $column_equal ) { + for my $string( @transposed ) { + if ( $string eq "AAA" ) { + say "A" ; + } + if ( $string eq "BBB" ) { + say "B" ; + } + } +} +if ($left_diagonal_down ) { + say substr( $tictactoe[0] , 0 , 1 ) ; +} +if ( $from_left_up ) { + say substr( $tictactoe[2] , 0 , 1 ) ; +} +if ( $is_drawn ) { + say "Draw" ; +} diff --git a/challenge-335/ulrich-rieke/raku/ch-1.raku b/challenge-335/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..c3ea2d0370 --- /dev/null +++ b/challenge-335/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,25 @@ +use v6 ; + +say "Enter some words separated by whitespace!" ; +my $line = $*IN.get ; +my @singleWords = $line.words ; +my @charSets = @singleWords.map( {$_.comb.Set} ) ; +my $common = [(&)] @charSets ; +my @commonLetters = $common.keys ; +my %frequencies ; +for @singleWords -> $word { + my %wordfreq ; + for $word.comb -> $letter { + %wordfreq{$letter}++ ; + } + for @commonLetters -> $letter { + %frequencies{$letter}.push( %wordfreq{$letter} ) ; + } +} +my @solution ; +for %frequencies.keys -> $l { + for (1..%frequencies{$l}.min( ) ) { + @solution.push( $l ) ; + } +} +say '(' ~ @solution.join( ',' ) ~ ')' ; diff --git a/challenge-335/ulrich-rieke/raku/ch-2.raku b/challenge-335/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..1d4dc0dc3a --- /dev/null +++ b/challenge-335/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,93 @@ +use v6 ; + +say "Enter some numbers between 0 and 2 in brackets separated by ,!" ; +my $line = $*IN.get ; +my @pairs ; +my @parts = $line.split( /\] ',' \s*\[/ ) ; +for @parts -> $pair { + if ($pair ~~ /(\d+)\s* ',' \s* (\d+) / ) { + my $numberpair = [+$0 , +$1] ; + @pairs.push( $numberpair ) ; + } +} +#define the tictactoe as an array of strings, for simplicity +my @tictactoe ; +for (1..3) { + @tictactoe.push( "___") ; +} +my $counter = 0 ; +for @pairs -> $pair { + if ( $counter %% 2 ) { + @tictactoe[$pair[0]].substr-rw( $pair[1] , 1 ) = 'A' ; + } + else { + @tictactoe[$pair[0]].substr-rw( $pair[1] , 1 ) = 'B' ; + } + $counter++ ; +} +my $row_equal = False ; +for @tictactoe -> $str { + if ( $str eq "AAA" || $str eq "BBB" ) { + $row_equal = True ; + } +} +my @transposed ; +for ( 0..2 ) -> $col { + for (0..2) -> $row { + my $transpo ~= @tictactoe[$row].substr( $col , 1 ) ; + } + @transposed.push( $transpo ) ; +} +my $column_equal = False ; +for @transposed -> $str { + if ( $str eq "AAA" || $str eq "BBB" ) { + $column_equal = True ; + } +} +my $first_diagonal = @tictactoe[0].substr( 0 , 1 ) ~ @tictactoe[1].substr( 1 , 1 ) + ~ @tictactoe[2].substr( 2 , 1 ) ; +my $left_down_diagonal = ( $first_diagonal eq "AAA" || $first_diagonal eq "BBB" ) ; +my $second_diagonal = @tictactoe[2].substr( 0 , 1 ) ~ @tictactoe[1].substr( 1 , 1 ) + ~ @tictactoe[0].substr( 2 , 1 ) ; +my $right_up_diagonal = ( $second_diagonal eq "AAA" || $second_diagonal eq "BBB" ) ; +my $maybe_drawn = ( (not $row_equal) && not ( $column_equal ) && ( not + $left_down_diagonal ) && ( not $right_up_diagonal )) ; +my $is_drawn ; +if ( $maybe_drawn ) { + if ( @tictactoe.grep( {$_ ~~ /^('A' | 'B')+$/ } ).elems == 3 ) { + $is_drawn = True ; + } +} +if (( $column_equal , $row_equal , $left_down_diagonal , $right_up_diagonal , + $is_drawn ).none ) { + say "Pending" ; +} +if $row_equal { + for @tictactoe -> $string { + if ($string eq "AAA" ) { + say "A" ; + } + if ( $string eq "BBB" ) { + say "B" ; + } + } +} +if $column_equal { + for @transposed -> $string { + if ( $string eq "AAA" ) { + say "A" ; + } + if ( $string eq "BBB" ) { + say "B" ; + } + } +} +if $left_down_diagonal { + say @tictactoe[0].substr( 0 , 1 ) ; +} +if ( $right_up_diagonal ) { + say @tictactoe[2].substr( 0 , 1 ) ; +} +if $is_drawn { + say "Draw" ; +} diff --git a/challenge-335/ulrich-rieke/rust/ch-1.rs b/challenge-335/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..07a904cc8f --- /dev/null +++ b/challenge-335/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,47 @@ +use std::io ; +use std::collections::{HashMap , HashSet} ; + +fn count_characters( word : &str ) -> HashMap { + let mut frequencies : HashMap = HashMap::new( ) ; + for c in word.chars( ) { + *frequencies.entry( c ).or_insert( 0 ) += 1 ; + } + frequencies +} + +fn main() { + println!("Enter some words separated by whitespace!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let frequencylist : Vec> = inline.trim( ).split_whitespace( ).map( + |s| count_characters( s ) ).collect( ) ; + let sets : Vec> = frequencylist.iter( ).map( |f| { + let keys = f.keys( ) ; + let mut keyset : HashSet = HashSet::new( ) ; + for c in keys { + keyset.insert( *c ) ; + } + keyset + }).collect( ) ; + let common : HashSet = sets.clone().into_iter( ).fold( sets[0].clone( ) , |mut acc , s| { + acc.retain( |item| s.contains( item ) ) ; + acc + } ) ; + let mut common_frequencies : Vec<(char , usize)> = Vec::new( ) ; + for c in common { + let mut numbers : Vec = Vec::new( ) ; + for f in &frequencylist { + let num = f.get( &c ).unwrap( ) ; + numbers.push( *num ) ; + } + let mini = numbers.into_iter( ).min( ).unwrap( ) ; + common_frequencies.push( (c , mini) ) ; + } + let mut solution : Vec = Vec::new( ) ; + for pair in common_frequencies { + for _ in 0..pair.1 { + solution.push( pair.0 ) ; + } + } + println!("{:?}" , solution ) ; +} diff --git a/challenge-335/ulrich-rieke/rust/ch-2.rs b/challenge-335/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..afd4b3ba6d --- /dev/null +++ b/challenge-335/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,81 @@ +use std::io ; +use regex::Regex ; + +fn parse_pair( bracket : &str ) -> (usize , usize) { + let re = Regex::new( r"([0-9]+)").unwrap( ) ; + let numbers : Vec = re.find_iter( bracket ).map( |m| { + let found = m.as_str( ) ; + let num : usize = found.parse::( ).unwrap( ) ; + num + }).collect( ) ; + (numbers[0] , numbers[1]) +} + +fn main() { + println!("Enter some tictactoe coordinates in brackets separated by ,!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let re = Regex::new( r"\[\s*([0-9]+)\s*\,\s*([0-9]+)\]").unwrap( ) ; + let trimmed = inline.trim( ) ; + let parts : Vec<&str> = re.find_iter(trimmed).map( |m| m.as_str( )). + collect( ) ; + let coordinates : Vec<(usize , usize)> = parts.into_iter( ).map( |s| + parse_pair( s ) ).collect( ) ; + let row : [char ; 3] = ['_' ; 3 ] ; + let mut tictacboard : [[char ; 3] ; 3] = [row ; 3] ; + let mut counter : usize = 0 ; + for p in coordinates { + if counter % 2 == 0 { + tictacboard[p.0][p.1] = 'A' ; + } + else { + tictacboard[p.0][p.1] = 'B' ; + } + counter += 1 ; + } + //test on row equality + let rows_equal : bool = tictacboard.iter( ).any( |r| { + let head : char = r[0] ; + r.iter( ).all( |c| *c == head && *c != '_') + }) ; + let column_equal : bool = { + let heads : [usize ; 3] = [0 , 1 , 2] ; + heads.into_iter( ).any( |p| tictacboard[0][p] == tictacboard[1][p] && + tictacboard[1][p] == tictacboard[2][p] && tictacboard[0][p] != '_') + } ; + let left_down_diagonal : bool = tictacboard[0][0] == tictacboard[1][1] && + tictacboard[1][1] == tictacboard[2][2] && tictacboard[0][0] != '_' ; + let right_up_diagonal : bool = tictacboard[2][0] == tictacboard[1][1] && + tictacboard[1][1] == tictacboard[0][2] && tictacboard[2][0] != '_' ; + let is_drawn : bool = tictacboard.iter( ).all( |r| r.iter( ).all( |c| *c == 'A' + || *c == 'B')) ; + if rows_equal { + let found = tictacboard.iter( ).position( |r| { + let head : char = r[0] ; + r.iter( ).all( |c| *c == head ) + }) ; + let pos = found.unwrap( ) ; + println!("{}" , tictacboard[pos][0] ) ; + } + if column_equal { + let heads = [0 , 1 , 2] ; + let found = heads.into_iter( ).position( |n| tictacboard[0][n] == + tictacboard[1][n] && tictacboard[1][n] == tictacboard[2][n] ) ; + let pos : usize = found.unwrap( ) ; + println!("{}" , tictacboard[0][pos] ) ; + } + if left_down_diagonal { + println!("{}" , tictacboard[0][0] ) ; + } + if right_up_diagonal { + println!("{}" , tictacboard[2][0] ) ; + } + if is_drawn { + println!("Draw") ; + } + let possibilities : Vec = vec![rows_equal , column_equal , + left_down_diagonal , right_up_diagonal , is_drawn ] ; + if possibilities.into_iter( ).all( |p| p == false ) { + println!("Pending") ; + } +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index f217cf5dba..09e32b79aa 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -136,6 +136,20 @@ "id" : "Thomas Kohler", "name" : "Thomas Kohler" }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke" + }, { "data" : [ [ @@ -238,6 +252,11 @@ "name" : "Thomas Kohler", "y" : 4 }, + { + "drilldown" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "y" : 4 + }, { "drilldown" : "W. Luis Mochan", "name" : "W. Luis Mochan", @@ -253,7 +272,7 @@ } ], "subtitle" : { - "text" : "[Champions: 14] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 15] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge - 335" diff --git a/stats/pwc-language-breakdown-2019.json b/stats/pwc-language-breakdown-2019.json index 1d3230008f..6b650dc432 100644 --- a/stats/pwc-language-breakdown-2019.json +++ b/stats/pwc-language-breakdown-2019.json @@ -970,7 +970,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2020.json b/stats/pwc-language-breakdown-2020.json index 18f2750125..d144169cb9 100644 --- a/stats/pwc-language-breakdown-2020.json +++ b/stats/pwc-language-breakdown-2020.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2021.json b/stats/pwc-language-breakdown-2021.json index 80fce3dd15..a182d1e617 100644 --- a/stats/pwc-language-breakdown-2021.json +++ b/stats/pwc-language-breakdown-2021.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2022.json b/stats/pwc-language-breakdown-2022.json index 67ef19f639..6fa24c2481 100644 --- a/stats/pwc-language-breakdown-2022.json +++ b/stats/pwc-language-breakdown-2022.json @@ -1223,7 +1223,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2023.json b/stats/pwc-language-breakdown-2023.json index f66f906621..2bfdb86449 100644 --- a/stats/pwc-language-breakdown-2023.json +++ b/stats/pwc-language-breakdown-2023.json @@ -1200,7 +1200,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2024.json b/stats/pwc-language-breakdown-2024.json index 8e8f82c6c5..a5f6dbb59e 100644 --- a/stats/pwc-language-breakdown-2024.json +++ b/stats/pwc-language-breakdown-2024.json @@ -1246,7 +1246,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-2025.json b/stats/pwc-language-breakdown-2025.json index 2e01f065fc..b3a36c2045 100644 --- a/stats/pwc-language-breakdown-2025.json +++ b/stats/pwc-language-breakdown-2025.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 20 + 22 ], [ "Raku", - 9 + 11 ], [ "Blog", @@ -619,7 +619,7 @@ { "drilldown" : "335", "name" : "335", - "y" : 33 + "y" : 37 }, { "drilldown" : "334", @@ -786,7 +786,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 84bd8a6787..8a0b20c918 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -10,11 +10,11 @@ "data" : [ [ "Perl", - 17274 + 17276 ], [ "Raku", - 9615 + 9617 ], [ "Blog", @@ -37,7 +37,7 @@ } ], "subtitle" : { - "text" : "Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2025]" diff --git a/stats/pwc-leaders.json b/stats/pwc-leaders.json index bccca97b65..1daa99b359 100644 --- a/stats/pwc-leaders.json +++ b/stats/pwc-leaders.json @@ -112,11 +112,11 @@ "data" : [ [ "Perl", - 506 + 508 ], [ "Raku", - 514 + 516 ] ], "id" : "Ulrich Rieke", @@ -827,7 +827,7 @@ { "drilldown" : "Ulrich Rieke", "name" : "7: Ulrich Rieke", - "y" : 2040 + "y" : 2048 }, { "drilldown" : "Flavio Poletti", @@ -1049,7 +1049,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the score breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "Team Leaders (TOP 50)" diff --git a/stats/pwc-summary-1-30.json b/stats/pwc-summary-1-30.json index 07fd17d8b0..188b88e43a 100644 --- a/stats/pwc-summary-1-30.json +++ b/stats/pwc-summary-1-30.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-121-150.json b/stats/pwc-summary-121-150.json index c67722b168..a52c7332ad 100644 --- a/stats/pwc-summary-121-150.json +++ b/stats/pwc-summary-121-150.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-151-180.json b/stats/pwc-summary-151-180.json index ba16da5d65..c94809802f 100644 --- a/stats/pwc-summary-151-180.json +++ b/stats/pwc-summary-151-180.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-181-210.json b/stats/pwc-summary-181-210.json index d8ede7918d..c5e79cd2bd 100644 --- a/stats/pwc-summary-181-210.json +++ b/stats/pwc-summary-181-210.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-211-240.json b/stats/pwc-summary-211-240.json index 4ca410d31c..bcfd4c6a3c 100644 --- a/stats/pwc-summary-211-240.json +++ b/stats/pwc-summary-211-240.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-241-270.json b/stats/pwc-summary-241-270.json index a78bf8ba42..0ee3918a3c 100644 --- a/stats/pwc-summary-241-270.json +++ b/stats/pwc-summary-241-270.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-271-300.json b/stats/pwc-summary-271-300.json index f783f32880..b2122f1c39 100644 --- a/stats/pwc-summary-271-300.json +++ b/stats/pwc-summary-271-300.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-301-330.json b/stats/pwc-summary-301-330.json index 79f30f1f9b..7afe6d1329 100644 --- a/stats/pwc-summary-301-330.json +++ b/stats/pwc-summary-301-330.json @@ -21,7 +21,7 @@ 0, 2, 4, - 506, + 508, 24, 18, 16, @@ -54,7 +54,7 @@ 2, 0, 0, - 514, + 516, 0, 0, 2, @@ -109,7 +109,7 @@ } ], "subtitle" : { - "text" : "[Champions: 28] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 28] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-31-60.json b/stats/pwc-summary-31-60.json index 7ff2ce08b7..fb7c9f33e2 100644 --- a/stats/pwc-summary-31-60.json +++ b/stats/pwc-summary-31-60.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-61-90.json b/stats/pwc-summary-61-90.json index cf19cc0038..5d9a86c9b5 100644 --- a/stats/pwc-summary-61-90.json +++ b/stats/pwc-summary-61-90.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary-91-120.json b/stats/pwc-summary-91-120.json index db83d8dd6b..51bef873af 100644 --- a/stats/pwc-summary-91-120.json +++ b/stats/pwc-summary-91-120.json @@ -115,7 +115,7 @@ } ], "subtitle" : { - "text" : "[Champions: 30] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 30] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-summary.json b/stats/pwc-summary.json index b0fcf60289..9c8ca2f5a7 100644 --- a/stats/pwc-summary.json +++ b/stats/pwc-summary.json @@ -321,7 +321,7 @@ 0, 1, 2, - 275, + 276, 12, 9, 9, @@ -397,8 +397,8 @@ 6, 0, 0, - 1, 9, + 1, 0, 104, 0, @@ -654,7 +654,7 @@ 1, 0, 0, - 276, + 277, 0, 0, 2, @@ -1009,7 +1009,7 @@ } ], "subtitle" : { - "text" : "[Champions: 328] Last updated at 2025-08-20 10:10:14 GMT" + "text" : "[Champions: 328] Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge [2019 - 2025]" diff --git a/stats/pwc-yearly-language-summary.json b/stats/pwc-yearly-language-summary.json index 8ec3c82ca1..f63abeb9b7 100644 --- a/stats/pwc-yearly-language-summary.json +++ b/stats/pwc-yearly-language-summary.json @@ -8,11 +8,11 @@ "data" : [ [ "Perl", - 1503 + 1505 ], [ "Raku", - 745 + 747 ], [ "Blog", @@ -151,7 +151,7 @@ { "drilldown" : "2025", "name" : "2025", - "y" : 2869 + "y" : 2873 }, { "drilldown" : "2024", @@ -188,7 +188,7 @@ } ], "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-20 10:10:14 GMT" + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2025-08-21 23:13:37 GMT" }, "title" : { "text" : "The Weekly Challenge Language" -- cgit