diff options
34 files changed, 3850 insertions, 3278 deletions
diff --git a/challenge-276/eric-cheung/python/ch-1.py b/challenge-276/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..abb3112347 --- /dev/null +++ b/challenge-276/eric-cheung/python/ch-1.py @@ -0,0 +1,12 @@ +
+from itertools import combinations
+
+## arrHours = [12, 12, 30, 24, 24] ## Example 1
+## arrHours = [72, 48, 24, 5] ## Example 2
+arrHours = [12, 18, 24] ## Example 3
+
+arrComb = combinations(arrHours, 2)
+
+arrOutput = [arrLoop for arrLoop in list(arrComb) if sum(arrLoop) % 24 == 0]
+
+print (len(arrOutput))
diff --git a/challenge-276/eric-cheung/python/ch-2.py b/challenge-276/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..1f41b77181 --- /dev/null +++ b/challenge-276/eric-cheung/python/ch-2.py @@ -0,0 +1,9 @@ +
+## arrInt = [1, 2, 2, 4, 1, 5] ## Example 1
+arrInt = [1, 2, 3, 4, 5] ## Example 2
+
+arrFreq = [arrInt.count(nLoop) for nLoop in set(arrInt)]
+
+nMaxFreq = max(arrFreq)
+
+print (nMaxFreq * arrFreq.count(nMaxFreq))
diff --git a/challenge-276/mgo1977/perl/ch1.pl b/challenge-276/mgo1977/perl/ch-1.pl index 7fbb808b0b..7fbb808b0b 100644 --- a/challenge-276/mgo1977/perl/ch1.pl +++ b/challenge-276/mgo1977/perl/ch-1.pl diff --git a/challenge-276/mgo1977/perl/ch2.pl b/challenge-276/mgo1977/perl/ch-2.pl index 136f80de1a..136f80de1a 100644 --- a/challenge-276/mgo1977/perl/ch2.pl +++ b/challenge-276/mgo1977/perl/ch-2.pl diff --git a/challenge-276/perlboy1967/perl/ch1.pl b/challenge-276/perlboy1967/perl/ch-1.pl index 9ff82133f6..9ff82133f6 100755 --- a/challenge-276/perlboy1967/perl/ch1.pl +++ b/challenge-276/perlboy1967/perl/ch-1.pl diff --git a/challenge-276/perlboy1967/perl/ch2.pl b/challenge-276/perlboy1967/perl/ch-2.pl index d19bebae7e..d19bebae7e 100755 --- a/challenge-276/perlboy1967/perl/ch2.pl +++ b/challenge-276/perlboy1967/perl/ch-2.pl diff --git a/challenge-276/ulrich-rieke/cpp/ch-1.cpp b/challenge-276/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..2802cb5600 --- /dev/null +++ b/challenge-276/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,21 @@ +#include <iostream>
+#include <vector>
+#include <iterator>
+#include <utility>
+#include <algorithm>
+
+int main( ) {
+ std::cout << "Enter some positive integers , separated by blanks, 'e' to end!\n" ;
+ std::vector<int> numbers { std::istream_iterator<int>( std::cin ) ,
+ std::istream_iterator<int>( ) } ;
+ std::vector<std::pair<int , int>> combinations ;
+ int len = numbers.size( ) ;
+ for ( int i = 0 ; i < len - 1 ; i++ ) {
+ for ( int j = i + 1 ; j < len ; j++ ) {
+ combinations.push_back( std::make_pair( numbers[i] , numbers[j] ) ) ;
+ }
+ }
+ std::cout << std::count_if( combinations.begin( ) , combinations.end( ) , []
+ ( const auto & p ) { return (p.first + p.second) % 24 == 0 ; } ) << '\n' ;
+ return 0 ;
+}
diff --git a/challenge-276/ulrich-rieke/cpp/ch-2.cpp b/challenge-276/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..a3c5d7e345 --- /dev/null +++ b/challenge-276/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,29 @@ +#include <vector>
+#include <iostream>
+#include <iterator>
+#include <map>
+
+int main( ) {
+ std::cout << "Enter some integers, separated by blanks, 'e' to end!\n" ;
+ std::vector<int> numbers { std::istream_iterator<int>( std::cin ) ,
+ std::istream_iterator<int>( ) } ;
+ std::map<int , int> frequencies ;
+ for ( int i : numbers ) {
+ frequencies[i]++ ;
+ }
+ int elements = 0 ;//elements with maximum frequency
+ int maximum = 0 ;//maximum frequency
+ for ( auto p : frequencies ) {
+ if ( p.second > maximum )
+ maximum = p.second ;
+ }
+ for ( auto p : frequencies ) {
+ if ( p.second == maximum )
+ elements++ ;
+ }
+ //we want the product of maximum frequency and the number of elements that have it
+ std::cout << elements * maximum << '\n' ;
+ return 0 ;
+}
+
+
diff --git a/challenge-276/ulrich-rieke/haskell/ch-1.hs b/challenge-276/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..c133891922 --- /dev/null +++ b/challenge-276/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,18 @@ +module Challenge276
+ where
+import Data.List ( nub , (!!) )
+
+combinations :: Int -> [a] -> [[a]]
+combinations 0 _ = [[]]
+combinations n xs = [ xs !! i : x | i <- [0..(length xs ) - 1 ] ,
+ x <- combinations (n - 1 ) ( drop ( i + 1 ) xs ) ]
+
+solution :: [Int] -> Int
+solution list = length $ filter (\subli -> mod ( sum subli ) 24 == 0 ) $ nub $
+ combinations 2 list
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some positive integers, separated by blanks!"
+ numberline <- getLine
+ print $ solution $ map read $ words numberline
diff --git a/challenge-276/ulrich-rieke/haskell/ch-2.hs b/challenge-276/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..4c06361f5a --- /dev/null +++ b/challenge-276/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,19 @@ +module Challenge276_2
+ where
+import Data.List ( sort , sortOn , group )
+
+solution :: [Int] -> Int
+solution list =
+ let sorted = sort list
+ grouped = group sorted
+ groupedLengths = sortOn length grouped
+ maxLen = length $ last groupedLengths -- maximum frequency
+ howmany = length $ filter ( (== maxLen ) . length ) grouped --elements with
+ --maximum frequency
+ in howmany * maxLen --their product
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some positive integers, separated by blanks!"
+ numberline <- getLine
+ print $ solution $ map read $ words numberline
diff --git a/challenge-276/ulrich-rieke/perl/ch-1.pl b/challenge-276/ulrich-rieke/perl/ch-1.pl new file mode 100755 index 0000000000..9fb2cc7793 --- /dev/null +++ b/challenge-276/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use Algorithm::Combinatorics qw ( combinations ) ;
+
+say "Enter some positive integers , separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s+/ , $line ) ;
+my $total = 0 ;
+my $iter = combinations( \@numbers , 2 ) ;
+while ( my $c = $iter->next ) {
+ if ( ($c->[0] + $c->[1]) % 24 == 0 ) {
+ $total++ ;
+ }
+}
+say $total ;
diff --git a/challenge-276/ulrich-rieke/perl/ch-2.pl b/challenge-276/ulrich-rieke/perl/ch-2.pl new file mode 100755 index 0000000000..6278f6af18 --- /dev/null +++ b/challenge-276/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+use List::Util qw ( max ) ;
+
+say "Enter some integers, separated by blanks!" ;
+my $line = <STDIN> ;
+chomp $line ;
+my @numbers = split( /\s+/ , $line ) ;
+my %frequencies ;
+map { $frequencies{$_}++ } @numbers ;
+my $maximum = max( values( %frequencies ) ) ;
+my $maxElements = scalar( grep { $frequencies{ $_ } == $maximum } keys %frequencies ) ;
+#what we are interested in is the product of maximum frequency and the number of element
+#that are that frequent
+say ( $maxElements * $maximum ) ;
diff --git a/challenge-276/ulrich-rieke/raku/ch-1.raku b/challenge-276/ulrich-rieke/raku/ch-1.raku new file mode 100755 index 0000000000..5e250b40cc --- /dev/null +++ b/challenge-276/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,6 @@ +use v6 ;
+
+say "Enter some positive integers, separated by blanks!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+say @numbers.combinations( 2 ).grep( { $_.sum %% 24 } ).elems ;
diff --git a/challenge-276/ulrich-rieke/raku/ch-2.raku b/challenge-276/ulrich-rieke/raku/ch-2.raku new file mode 100755 index 0000000000..246fe012e1 --- /dev/null +++ b/challenge-276/ulrich-rieke/raku/ch-2.raku @@ -0,0 +1,14 @@ +use v6 ;
+
+say "Enter some integers, separated by blanks!" ;
+my $line = $*IN.get ;
+my @numbers = $line.words.map( {.Int} ) ;
+my %frequencies ;
+@numbers.map( {%frequencies{$_}++} ) ;
+my $maximum = %frequencies.values.max ;
+my @keys = %frequencies.keys ;
+my $number = @keys.grep( {%frequencies{$_} == $maximum} ).elems ;#number of element
+#with maximum frequency
+#what we look for is the product of maximum frequency and the number of elements that
+#have that maximum frequency!
+say ( $number * $maximum ) ;
diff --git a/challenge-276/ulrich-rieke/rust/ch-1.rs b/challenge-276/ulrich-rieke/rust/ch-1.rs new file mode 100755 index 0000000000..b743e9bc77 --- /dev/null +++ b/challenge-276/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,15 @@ +use std::io ; +use itertools::Itertools ; + +fn main() { + println!("Enter some positive integers, separated by blanks!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = inline.as_str( ).trim( ) ; + let numbers : Vec<u32> = entered_line.split_whitespace( ).map( | s | + s.parse::<u32>( ).unwrap( ) ).collect( ) ; + let solution = numbers.into_iter( ).combinations( 2 ).filter( | vec | { + (vec[0] + vec[1]) % 24 == 0 + } ).count( ) ; + println!("{}" , solution ) ; +} diff --git a/challenge-276/ulrich-rieke/rust/ch-2.rs b/challenge-276/ulrich-rieke/rust/ch-2.rs new file mode 100755 index 0000000000..f395f112a0 --- /dev/null +++ b/challenge-276/ulrich-rieke/rust/ch-2.rs @@ -0,0 +1,23 @@ +use std::io ; +use std::collections::HashMap ; + +fn main() { + println!("Enter some positive integers!"); + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( &mut inline ).unwrap( ) ; + let entered_line : &str = inline.as_str( ).trim( ) ; + let numbers : Vec<u32> = entered_line.split_whitespace( ).map( | s | + s.parse::<u32>( ).unwrap( ) ).collect( ) ; + let mut frequencies : HashMap<u32 , usize> = HashMap::new( ) ; + for i in numbers { + frequencies.entry( i ).and_modify( |n| {*n += 1} ).or_insert( 1 ) ; + } + let max_freq : usize = *frequencies.values( ).max( ).unwrap( ) ; + let mut number : usize = 0 ; //how many numbers have maximum frequency ? + for (_ , v) in &frequencies { + if *v == max_freq { + number += 1 ; + } + } + println!("{}" , number * max_freq) ; +} diff --git a/members.json b/members.json index df615030f2..e1e03f3c4f 100644 --- a/members.json +++ b/members.json @@ -160,6 +160,7 @@ "luc65r" : "Lucas Ransan", "luiz-felipe" : "Luiz Felipe", "manfredi" : "Leo Manfredi", + "mgo1977" : "Mariano Ortega", "massa" : "Humberto Massa", "mauke" : "mauke", "miguel-prz" : "Miguel Prz", diff --git a/stats/pwc-challenge-275.json b/stats/pwc-challenge-275.json new file mode 100644 index 0000000000..7eb11235f3 --- /dev/null +++ b/stats/pwc-challenge-275.json @@ -0,0 +1,638 @@ +{ + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "xAxis" : { + "type" : "category" + }, + "title" : { + "text" : "The Weekly Challenge - 275" + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "series" : [ + { + "data" : [ + { + "y" : 2, + "name" : "Andrew Schneider", + "drilldown" : "Andrew Schneider" + }, + { + "y" : 3, + "name" : "Arne Sommer", + "drilldown" : "Arne Sommer" + }, + { + "name" : "Athanasius", + "y" : 4, + "drilldown" : "Athanasius" + }, + { + "name" : "BarrOff", + "y" : 1, + "drilldown" : "BarrOff" + }, + { + "drilldown" : "Bob Lied", + "name" : "Bob Lied", + "y" : 2 + }, + { + "drilldown" : "Bruce Gray", + "y" : 2, + "name" : "Bruce Gray" + }, + { + "name" : "Cheok-Yin Fung", + "y" : 2, + "drilldown" : "Cheok-Yin Fung" + }, + { + "y" : 2, + "name" : "Dave Jacoby", + "drilldown" : "Dave Jacoby" + }, + { + "drilldown" : "David Ferrone", + "name" : "David Ferrone", + "y" : 2 + }, + { + "name" : "E. Choroba", + "y" : 2, + "drilldown" : "E. Choroba" + }, + { + "name" : "Feng Chang", + "y" : 2, + "drilldown" : "Feng Chang" + }, + { + "name" : "Jaldhar H. Vyas", + "y" : 5, + "drilldown" : "Jaldhar H. Vyas" + }, + { + "drilldown" : "Jan Krnavek", + "y" : 2, + "name" : "Jan Krnavek" + }, + { + "y" : 4, + "name" : "Joelle Maslak", + "drilldown" : "Joelle Maslak" + }, + { + "y" : 3, + "name" : "Jorg Sommrey", + "drilldown" : "Jorg Sommrey" + }, + { + "drilldown" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld", + "y" : 3 + }, + { + "y" : 11, + "name" : "Luca Ferrari", + "drilldown" : "Luca Ferrari" + }, + { + "y" : 2, + "name" : "Mariano Spadaccini", + "drilldown" : "Mariano Spadaccini" + }, + { + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson", + "y" : 2 + }, + { + "name" : "Matthew Neleigh", + "y" : 2, + "drilldown" : "Matthew Neleigh" + }, + { + "drilldown" : "Matthias Muth", + "y" : 3, + "name" : "Matthias Muth" + }, + { + "drilldown" : "Nelo Tovar", + "y" : 2, + "name" : "Nelo Tovar" + }, + { + "y" : 2, + "name" : "Niels van Dijke", + "drilldown" : "Niels van Dijke" + }, + { + "drilldown" : "Packy Anderson", + "name" : "Packy Anderson", + "y" : 5 + }, + { + "drilldown" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", + "y" : 3 + }, + { + "drilldown" : "Peter Meszaros", + "y" : 2, + "name" : "Peter Meszaros" + }, + { + "name" : "Reinier Maliepaard", + "y" : 3, + "drilldown" : "Reinier Maliepaard" + }, + { + "y" : 3, + "name" : "Robbie Hatley", + "drilldown" : "Robbie Hatley" + }, + { + "y" : 1, + "name" : "Robert Ransbottom", + "drilldown" : "Robert Ransbottom" + }, + { + "y" : 5, + "name" : "Roger Bell_West", + "drilldown" : "Roger Bell_West" + }, + { + "drilldown" : "Simon Green", + "name" : "Simon Green", + "y" : 3 + }, + { + "y" : 4, + "name" : "Thomas Kohler", + "drilldown" : "Thomas Kohler" + }, + { + "name" : "W. Luis Mochan", + "y" : 3, + "drilldown" : "W. Luis Mochan" + }, + { + "drilldown" : "Wanderdoc", + "name" : "Wanderdoc", + "y" : 2 + } + ], + "colorByPoint" : 1, + "name" : "The Weekly Challenge - 275" + } + ], + "tooltip" : { + "followPointer" : 1, + "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>", + "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>" + }, + "subtitle" : { + "text" : "[Champions: 34] Last updated at 2024-07-02 12:11:04 GMT" + }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : 0 + }, + "drilldown" : { + "series" : [ + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Andrew Schneider", + "name" : "Andrew Schneider" + }, + { + "id" : "Arne Sommer", + "name" : "Arne Sommer", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "name" : "Athanasius", + "id" : "Athanasius" + }, + { + "id" : "BarrOff", + "name" : "BarrOff", + "data" : [ + [ + "Raku", + 1 + ] + ] + }, + { + "name" : "Bob Lied", + "id" : "Bob Lied", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Bruce Gray", + "id" : "Bruce Gray", + "data" : [ + [ + "Raku", + 2 + ] + ] + }, + { + "name" : "Cheok-Yin Fung", + "id" : "Cheok-Yin Fung", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Dave Jacoby", + "id" : "Dave Jacoby", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "David Ferrone", + "name" : "David Ferrone" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "E. Choroba", + "name" : "E. Choroba" + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Feng Chang", + "id" : "Feng Chang" + }, + { + "name" : "Jaldhar H. Vyas", + "id" : "Jaldhar H. Vyas", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "name" : "Jan Krnavek", + "id" : "Jan Krnavek", + "data" : [ + [ + "Raku", + 2 + ] + ] + }, + { + "id" : "Joelle Maslak", + "name" : "Joelle Maslak", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ] + }, + { + "id" : "Jorg Sommrey", + "name" : "Jorg Sommrey", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "id" : "Laurent Rosenfeld", + "name" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 9 + ] + ], + "name" : "Luca Ferrari", + "id" : "Luca Ferrari" + }, + { + "id" : "Mariano Spadaccini", + "name" : "Mariano Spadaccini", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Mark Anderson", + "name" : "Mark Anderson" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Matthew Neleigh", + "name" : "Matthew Neleigh" + }, + { + "name" : "Matthias Muth", + "id" : "Matthias Muth", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Nelo Tovar", + "name" : "Nelo Tovar" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Niels van Dijke", + "name" : "Niels van Dijke" + }, + { + "name" : "Packy Anderson", + "id" : "Packy Anderson", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "id" : "Peter Campbell Smith", + "name" : "Peter Campbell Smith", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "name" : "Peter Meszaros", + "id" : "Peter Meszaros", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Reinier Maliepaard", + "name" : "Reinier Maliepaard" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Robbie Hatley", + "name" : "Robbie Hatley" + |
