aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2023-03-13 12:37:37 +0000
committerGitHub <noreply@github.com>2023-03-13 12:37:37 +0000
commitd18742a481f56afe01099d0a3252810bfbfef65c (patch)
tree6403921b1f962095cb9cfd42e23228b855302606
parent32d3b1d2c7cc578c4347836715cbc8040cc20afb (diff)
parent733b9428a3c65d35f20504ac9d0122379bad71a9 (diff)
downloadperlweeklychallenge-club-d18742a481f56afe01099d0a3252810bfbfef65c.tar.gz
perlweeklychallenge-club-d18742a481f56afe01099d0a3252810bfbfef65c.tar.bz2
perlweeklychallenge-club-d18742a481f56afe01099d0a3252810bfbfef65c.zip
Merge branch 'manwar:master' into master
-rw-r--r--challenge-005/lubos-kolouch/perl/ch-1.pl40
-rw-r--r--challenge-005/lubos-kolouch/perl/ch-2.pl57
-rw-r--r--challenge-005/lubos-kolouch/python/ch-1.py43
-rw-r--r--challenge-005/lubos-kolouch/python/ch-2.py81
-rw-r--r--challenge-006/lubos-kolouch/perl/ch-1.pl72
-rw-r--r--challenge-006/lubos-kolouch/python/ch-1.py50
-rw-r--r--challenge-007/lubos-kolouch/perl/ch-1.pl21
-rw-r--r--challenge-007/lubos-kolouch/perl/ch-2.pl42
-rw-r--r--challenge-007/lubos-kolouch/python/ch-1.py22
-rw-r--r--challenge-007/lubos-kolouch/python/ch-2.py48
-rw-r--r--challenge-008/lubos-kolouch/perl/ch-1.pl32
-rw-r--r--challenge-008/lubos-kolouch/perl/ch-2.pl24
-rw-r--r--challenge-008/lubos-kolouch/python/ch-1.py30
-rw-r--r--challenge-008/lubos-kolouch/python/ch-2.py24
-rw-r--r--challenge-207/bruce-gray/raku/ch-1.raku37
-rw-r--r--challenge-207/bruce-gray/raku/ch-2.raku20
-rw-r--r--challenge-207/carlos-oliveira/raku/ch-1.raku22
-rw-r--r--challenge-207/carlos-oliveira/raku/ch-2.raku14
-rw-r--r--challenge-207/deadmarshal/cpp/ch-1.cpp33
-rw-r--r--challenge-207/deadmarshal/cpp/ch-2.cpp22
-rw-r--r--challenge-207/deadmarshal/d/ch1.d28
-rw-r--r--challenge-207/deadmarshal/d/ch2.d20
-rw-r--r--challenge-207/deadmarshal/modula-3/ch1/src/Ch1.m347
-rw-r--r--challenge-207/deadmarshal/modula-3/ch1/src/m3makefile4
-rw-r--r--challenge-207/deadmarshal/modula-3/ch2/src/Ch2.m320
-rw-r--r--challenge-207/deadmarshal/modula-3/ch2/src/m3makefile4
-rw-r--r--challenge-207/deadmarshal/nim/ch1.nim18
-rw-r--r--challenge-207/deadmarshal/nim/ch2.nim7
-rw-r--r--challenge-207/deadmarshal/oberon/Ch1.Mod54
-rw-r--r--challenge-207/deadmarshal/oberon/Ch2.Mod28
-rw-r--r--challenge-207/deadmarshal/pascal/ch1.pas46
-rw-r--r--challenge-207/deadmarshal/pascal/ch2.pas20
-rw-r--r--challenge-207/deadmarshal/perl/ch-1.pl25
-rw-r--r--challenge-207/deadmarshal/perl/ch-2.pl12
-rw-r--r--challenge-207/deadmarshal/raku/ch-1.raku21
-rw-r--r--challenge-207/deadmarshal/raku/ch-2.raku12
-rw-r--r--challenge-207/duncan-c-white/C/.cbuild4
-rw-r--r--challenge-207/duncan-c-white/C/Makefile18
-rw-r--r--challenge-207/duncan-c-white/C/README12
-rw-r--r--challenge-207/duncan-c-white/C/args.c207
-rw-r--r--challenge-207/duncan-c-white/C/args.h11
-rw-r--r--challenge-207/duncan-c-white/C/ch-1.c90
-rw-r--r--challenge-207/duncan-c-white/C/ch-2.c63
-rw-r--r--challenge-207/duncan-c-white/C/parseints.c114
-rw-r--r--challenge-207/duncan-c-white/C/parseints.h1
-rw-r--r--challenge-207/duncan-c-white/C/printarray.c39
-rw-r--r--challenge-207/duncan-c-white/C/printarray.h1
-rw-r--r--challenge-207/duncan-c-white/README83
-rwxr-xr-xchallenge-207/duncan-c-white/perl/ch-1.pl64
-rwxr-xr-xchallenge-207/duncan-c-white/perl/ch-2.pl69
-rw-r--r--challenge-207/ealvar3z/blog.txt1
-rw-r--r--challenge-207/ealvar3z/js/ch-1.js31
-rw-r--r--challenge-207/ealvar3z/rust/.gitignore3
-rw-r--r--challenge-207/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-207/jaldhar-h-vyas/perl/ch-1.pl25
-rwxr-xr-xchallenge-207/jaldhar-h-vyas/perl/ch-2.pl14
-rwxr-xr-xchallenge-207/jaldhar-h-vyas/raku/ch-1.raku20
-rwxr-xr-xchallenge-207/jaldhar-h-vyas/raku/ch-2.raku16
-rw-r--r--challenge-207/james-smith/README.md110
-rw-r--r--challenge-207/james-smith/blog.txt1
-rw-r--r--challenge-207/james-smith/perl/ch-1.pl22
-rw-r--r--challenge-207/james-smith/perl/ch-2.pl21
-rw-r--r--challenge-207/lubos-kolouch/20230311_Weekly_challenge_207.md121
-rw-r--r--challenge-207/pip/perl/ch-1.pl40
-rw-r--r--challenge-207/pip/perl/ch-2.pl26
-rw-r--r--challenge-207/pip/raku/ch-1.raku40
-rw-r--r--challenge-207/pip/raku/ch-2.raku26
-rw-r--r--challenge-207/roger-bell-west/blog.txt1
-rw-r--r--challenge-207/sgreen/README.md4
-rw-r--r--challenge-207/sgreen/blog.txt1
-rwxr-xr-xchallenge-207/sgreen/perl/ch-1.pl17
-rwxr-xr-xchallenge-207/sgreen/perl/ch-2.pl28
-rwxr-xr-xchallenge-207/sgreen/python/ch-1.py17
-rwxr-xr-xchallenge-207/sgreen/python/ch-2.py24
-rw-r--r--challenge-207/wambash/raku/ch-1.raku20
-rw-r--r--challenge-207/wambash/raku/ch-2.raku21
-rw-r--r--stats/pwc-challenge-005.json229
-rw-r--r--stats/pwc-challenge-006.json401
-rw-r--r--stats/pwc-challenge-200.json305
-rw-r--r--stats/pwc-current.json468
-rw-r--r--stats/pwc-language-breakdown-summary.json70
-rw-r--r--stats/pwc-language-breakdown.json1482
-rw-r--r--stats/pwc-leaders.json416
-rw-r--r--stats/pwc-summary-1-30.json118
-rw-r--r--stats/pwc-summary-121-150.json32
-rw-r--r--stats/pwc-summary-151-180.json94
-rw-r--r--stats/pwc-summary-181-210.json114
-rw-r--r--stats/pwc-summary-211-240.json50
-rw-r--r--stats/pwc-summary-241-270.json44
-rw-r--r--stats/pwc-summary-271-300.json70
-rw-r--r--stats/pwc-summary-31-60.json112
-rw-r--r--stats/pwc-summary-61-90.json44
-rw-r--r--stats/pwc-summary-91-120.json40
-rw-r--r--stats/pwc-summary.json610
94 files changed, 4828 insertions, 2398 deletions
diff --git a/challenge-005/lubos-kolouch/perl/ch-1.pl b/challenge-005/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..01c8817f8c
--- /dev/null
+++ b/challenge-005/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+sub print_anagrams {
+ my $word = shift;
+ my %freq;
+
+ # Count the frequency of each letter in the word
+ $freq{$_}++ for split //, $word;
+
+ # Recursively generate all anagrams
+ sub generate_anagrams {
+ my ( $prefix, $freq_ref ) = @_;
+
+ # Base case: no more letters left to add
+ if ( length $prefix == length $word ) {
+ print "$prefix\n";
+ return;
+ }
+
+ # Recursive case: add one more letter to the prefix
+ for my $letter ( keys %$freq_ref ) {
+ if ( $freq_ref->{$letter} > 0 ) {
+ $freq_ref->{$letter}--;
+ generate_anagrams( $prefix . $letter, $freq_ref );
+ $freq_ref->{$letter}++;
+ }
+ }
+ }
+
+ # Start generating anagrams with an empty prefix and the frequency hash
+ generate_anagrams( "", \%freq );
+}
+
+# Test the function with some example words
+print_anagrams("hello");
+print_anagrams("pear");
+print_anagrams("racecar");
diff --git a/challenge-005/lubos-kolouch/perl/ch-2.pl b/challenge-005/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..918be4654e
--- /dev/null
+++ b/challenge-005/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# This program finds the sequence of characters that has the most anagrams.
+
+=head1 SYNOPSIS
+
+This program finds the sequence of characters that has the most anagrams.
+
+=cut
+
+# Function to find the sequence of characters that has the most anagrams
+sub find_most_anagrams {
+ my ($str) = @_;
+
+ # Create a hash to store all the anagrams
+ my %anagrams;
+
+ # Iterate over each substring of the given string
+ for my $substring ( substrings($str) ) {
+
+ # Sort the characters of the substring
+ my $sorted_substring = join '', sort split //, $substring;
+
+ # Add the substring to the anagrams hash
+ push @{ $anagrams{$sorted_substring} }, $substring;
+ }
+
+ # Find the sequence with the most anagrams
+ my $max_anagrams = 0;
+ my $max_sequence = "";
+ for my $sequence ( keys %anagrams ) {
+ my $count = scalar @{ $anagrams{$sequence} };
+ if ( $count > $max_anagrams ) {
+ $max_anagrams = $count;
+ $max_sequence = $sequence;
+ }
+ }
+
+ return $max_sequence;
+}
+
+# Function to generate all substrings of a given string
+sub substrings {
+ my ($str) = @_;
+
+ my @substrings;
+ for my $i ( 0 .. length($str) - 1 ) {
+ for my $j ( $i .. length($str) ) {
+ push @substrings, substr( $str, $i, $j - $i );
+ }
+ }
+
+ return @substrings;
+}
diff --git a/challenge-005/lubos-kolouch/python/ch-1.py b/challenge-005/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..131d7f5333
--- /dev/null
+++ b/challenge-005/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+This program prints all anagrams of a given word.
+
+Input:
+word - a string representing the word to find anagrams of
+
+Output:
+A list of all anagrams of the given word
+
+"""
+
+import itertools
+
+
+def get_anagrams(word: str) -> set:
+ """
+ This function takes a word and finds all anagrams of it
+
+ Input:
+ word - a string representing the word to find anagrams of
+
+ Output:
+ A list of all anagrams of the given word
+
+ """
+
+ # generate all permutations of the given word
+ permutations = itertools.permutations(word)
+
+ # convert the permutations to strings
+ anagrams = ["".join(p) for p in permutations]
+
+ # remove duplicates
+ anagrams = list(set(anagrams))
+
+ return set(anagrams)
+
+
+# tests
+assert get_anagrams("cat") == {"tca", "tac", "act", "atc", "cta", "cat"}
diff --git a/challenge-005/lubos-kolouch/python/ch-2.py b/challenge-005/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..c5d59cd975
--- /dev/null
+++ b/challenge-005/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+This program finds the sequence of characters that has the most anagrams.
+
+Input:
+A string of any length
+
+Output:
+The sequence of characters that has the most anagrams
+
+"""
+
+import itertools
+
+
+def find_anagrams(string):
+ """
+ This function takes a string and returns a list of all its anagrams.
+
+ Parameters:
+ string (str): The string to be used
+
+ Returns:
+ anagrams (list): A list of all the anagrams of the input string
+ """
+
+ all_permutations = list(itertools.permutations(string))
+ anagrams = []
+
+ for permutation in all_permutations:
+ anagram = "".join(permutation)
+ anagrams.append(anagram)
+
+ return anagrams
+
+
+def most_anagrams(string):
+ """
+ This function takes a string and returns the sequence of characters that has the most anagrams.
+
+ Parameters:
+ string (str): The string to be used
+
+ Returns:
+ most_anagrams (str): The sequence of characters that has the most anagrams
+ """
+
+ all_anagrams = []
+
+ for i in range(1, len(string) + 1):
+ all_anagrams.append(find_anagrams(string[:i]))
+
+ max_length = 0
+ most_anagrams = ""
+
+ for anagrams in all_anagrams:
+ if len(anagrams) > max_length:
+ max_length = len(anagrams)
+ most_anagrams = anagrams[0]
+
+ return most_anagrams
+
+
+# Tests
+
+
+def test_find_anagrams():
+ assert find_anagrams("cat") == ["cat", "cta", "act", "atc", "tca", "tac"]
+
+
+def test_most_anagrams():
+ assert most_anagrams("cat") == "ca"
+
+
+if __name__ == "__main__":
+ string = input("Please enter a string: ")
+ print(
+ f"The sequence of characters that has the most anagrams is: {most_anagrams(string)}"
+ )
diff --git a/challenge-006/lubos-kolouch/perl/ch-1.pl b/challenge-006/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..03722cf548
--- /dev/null
+++ b/challenge-006/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+=head1 DESCRIPTION
+
+This script takes a list of numbers from command line and print the same in the compact form.
+
+For example, if you pass “1,2,3,4,9,10,14,15,16” then it should print the compact form like “1-4,9,10,14-16”.
+
+=cut
+
+# Get the list of numbers from command line
+my @numbers = @ARGV;
+
+# Sort the list of numbers in ascending order
+@numbers = sort { $a <=> $b } @numbers;
+
+# Initializing variables
+my @compact_list;
+my $first_num = $numbers[0];
+my $last_num = $numbers[0];
+
+# Generate the compact list
+foreach my $num (@numbers) {
+ if ( $num == $last_num + 1 ) {
+
+ # If the current number is 1 more than the last number,
+ # update the last number
+ $last_num = $num;
+ }
+ else {
+ # If the current number is not 1 more than the last number,
+ # add the range of numbers to the compact list
+ if ( $first_num == $last_num ) {
+ push @compact_list, $first_num;
+ }
+ else {
+ push @compact_list, "$first_num-$last_num";
+ }
+
+ # Reset the variables
+ $first_num = $num;
+ $last_num = $num;
+ }
+}
+
+# Add the last range of numbers to the compact list
+if ( $first_num == $last_num ) {
+ push @compact_list, $first_num;
+}
+else {
+ push @compact_list, "$first_num-$last_num";
+}
+
+# Print the compact list
+print join( ',', @compact_list );
+
+=head1 TESTING
+
+=over 4
+
+=item *
+
+Input: 1,2,3,4,9,10,14,15,16
+
+Expected Output: 1-4,9,10,14-16