From 24c7e5b7eb1ec5089dbda89f99e7490bf7a30851 Mon Sep 17 00:00:00 2001 From: Timofey Potapov Date: Mon, 7 Nov 2022 11:53:33 +0100 Subject: Challenge 190. --- challenge-190/tim-potapov/perl/ch-1.pl | 66 ++++++++++++++++++++ challenge-190/tim-potapov/perl/ch-2.pl | 109 +++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100755 challenge-190/tim-potapov/perl/ch-1.pl create mode 100755 challenge-190/tim-potapov/perl/ch-2.pl (limited to 'challenge-190') diff --git a/challenge-190/tim-potapov/perl/ch-1.pl b/challenge-190/tim-potapov/perl/ch-1.pl new file mode 100755 index 0000000000..f920870b5e --- /dev/null +++ b/challenge-190/tim-potapov/perl/ch-1.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; + +=pod + +Task 1: Capital Detection +You are given a string with alphabetic characters only: +A..Z and a..z. + +Write a script to find out if the usage of Capital is +appropriate if it satisfies at least one of the following rules: + +1) Only first letter is capital and all others are small. +2) Every letter is small. +3) Every letter is capital. + +=cut + +sub is_capital { + my ( $s ) = @_; + + 0 + $s =~ / # Make it return 0 or 1. + ^ (?: + + [A-Z][a-z]* # 1) Only first letter is capital and all others are small. + | [a-z]+ # 2) Every letter is small. + | [A-Z]+ # 3) Every letter is capital. + + ) $ + /x; +} + +my @cases = ( + { + Name => 'Example 1', + Input => 'Perl', + Output => 1, + }, + { + + Name => 'Example 2', + Input => 'TPF', + Output => 1, + + }, + { + Name => 'Example 3', + Input => 'PyThon', + Output => 0, + + }, + { + Name => 'Example 4', + Input => 'raku', + Output => 1, + }, +); + +for ( @cases ) { + is is_capital( $_->{Input} ), $_->{Output}, "$_->{Name} - $_->{Input}"; +} + +done_testing(); diff --git a/challenge-190/tim-potapov/perl/ch-2.pl b/challenge-190/tim-potapov/perl/ch-2.pl new file mode 100755 index 0000000000..7dd6dc1cd7 --- /dev/null +++ b/challenge-190/tim-potapov/perl/ch-2.pl @@ -0,0 +1,109 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use List::Util qw( uniq ); +use v5.32; +use Mojo::Util qw( dumper ); + +=pod + +Task 2: Decoded List +You are given an encoded string consisting of a +sequence of numeric characters: 0..9, $s. + +Write a script to find the all valid different decodings in sorted order. + +Encoding is simply done by mapping A,B,C,D,… to 1,2,3,4,… etc. + +=cut + +my @mapping = ( + undef, # Skip index 0. + 'A' .. 'Z', # 1 .. 26. +); +my $letters = $#mapping; + +sub decode_list { + my ( $s ) = @_; + + # Build pattern based on how many letters we got. + my $is_letter = '(.+)' # First regex. + . '(.*)' x (length($s)-1); # Rest are optional. + + # Collect combinations. + my @list_raw; + $s =~ / + ^ # Start. + $is_letter # Dynamic pattern. + $ # End. + (?{ + push @list_raw, # Collect combo. + join ",", + @{^CAPTURE} # Instead of doing ($1,$2,...$N) + }) + (?!) # Fail and try other options. + /xg; + + # Cleanup the list and convert. + my @list = + sort + map { + join "", + map { $mapping[$_] } @$_ # Convert to letter. + } + grep { # All parts must be in range. + @$_ == grep { + $_ and $_ >= 1 and $_ <= $letters + } @$_; + } + map { [ split /,/ ] } # Split into parts. + uniq # Skip duplicates. + grep { $_ } # Not empty. + @list_raw; + + \@list; +} + +my @cases = ( + { + Name => 'Example 0', + Input => '123', + Output => [ 'ABC', 'AW', 'LC' ], + }, + { + Name => 'Example 1', + Input => '11', + Output => [ 'AA', 'K' ], + + # 11 can be decoded as (1 1) or (11) i.e. AA or K + }, + { + Name => 'Example 2', + Input => '1115', + Output => [ 'AAAE', 'AAO', 'AKE', 'KAE', 'KO' ], + + # Possible decoded data are: + # (1 1 1 5) => (AAAE) + # (1 1 15) => (AAO) + # (1 11 5) => (AKE) + # (11 1 5) => (KAE) + # (11 15) => (KO) + }, + { + Name => 'Example 3', + Input => '127', + Output => [ 'ABG', 'LG' ], + + # Possible decoded data are: + # (1 2 7) => (ABG) + # (12 7) => (LG) + }, +); + +for ( @cases ) { + is_deeply decode_list( $_->{Input} ), $_->{Output}, $_->{Name}; +} + +done_testing(); -- cgit From d7686aa865c9fd31ee8dd4e28a461f212541d663 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 7 Nov 2022 12:42:04 -0600 Subject: Solve PWC190 --- challenge-190/wlmb/blog.txt | 1 + challenge-190/wlmb/perl/ch-1.pl | 15 +++++++++++++ challenge-190/wlmb/perl/ch-2.pl | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 challenge-190/wlmb/blog.txt create mode 100755 challenge-190/wlmb/perl/ch-1.pl create mode 100755 challenge-190/wlmb/perl/ch-2.pl (limited to 'challenge-190') diff --git a/challenge-190/wlmb/blog.txt b/challenge-190/wlmb/blog.txt new file mode 100644 index 0000000000..b26859dcd3 --- /dev/null +++ b/challenge-190/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io//2022/11/07/PWC190.org diff --git a/challenge-190/wlmb/perl/ch-1.pl b/challenge-190/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..a5b52f2cd9 --- /dev/null +++ b/challenge-190/wlmb/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# Perl weekly challenge 190 +# Task 1: Capital Detection +# +# See https://wlmb.github.io/2022/11/07/PWC190/#task-1-capital-detection +use v5.36; +use List::Util qw(any); +die <<"EOF" unless @ARGV; +Usage: $0 W1 [W2...] +to test appropriate case for the words W1, W2,... +EOF +for my $word(@ARGV){ + say "$word -> ", + (any {$word eq $_} lc $word, uc $word, ucfirst lc $word) + ? "appropriate": "inappropriate"} diff --git a/challenge-190/wlmb/perl/ch-2.pl b/challenge-190/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..a91f330b1a --- /dev/null +++ b/challenge-190/wlmb/perl/ch-2.pl @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +# Perl weekly challenge 190 +# Task 2: Decoded List +# +# See https://wlmb.github.io/2022/11/07/PWC190/#task-2-decoded-list +use v5.36; +use experimental qw(try); +die <<"EOF" unless @ARGV; +Usage: $0 N1 [N2...] +to decode the numbers N1, N2... +EOF +my @letters=("", "A".."Z"); # Base 1 array of ascii letters +sub iterator($n){ #Create an iterator for all decodings of the number $n + my $counter=0; + my $length=length $n; # number of digits + my @digits0=split "", $n; + sub { + COUNTER: while($counter<2**$length){ + my @digits=@digits0; # copy digits + my @bits=split "", + my $bits=sprintf "%0.${length}b", $counter++; # convert to binary, advance counter + next COUNTER if $bits=~/11/; # Don't stick more than 2 consecutive letters + my @output; + while(@bits && @digits){ + my $bit=pop @bits; + next COUNTER if @digits<2 && $bit==1; # Not enough digits to join + splice(@digits,-2,2,$digits[-2].$digits[-1]),next if $bit==1; # Join last two digits + unshift @output, my $m=pop @digits if $bit==0; # or pop last number + next COUNTER if $m==0 or $m>=@letters; # Number too large or too small, restart + } + return @letters[@output]; # Found a decoding. Convert numbers to letters and return them + } + (); # Didn't find another decoding, return a null list + } +} +for(@ARGV){ + try { + die "Only digits allowed: $_" unless /^\d*$/; + die "Empty input" unless /./; + my $it=iterator($_); + print "$_ -> "; + my @decoded; + print @decoded," " while(@decoded=$it->()); # Print all possible decodings + say ""; + } + catch($m){ + say "Error: $m"; + } +} -- cgit From 57b1ca83cb7e4fc9d4500d09486e8ce6c37fa162 Mon Sep 17 00:00:00 2001 From: Peter Campbell Smith Date: Mon, 7 Nov 2022 18:54:56 +0000 Subject: Week 190 tasks completed --- challenge-190/peter-campbell-smith/blog.txt | 1 + challenge-190/peter-campbell-smith/perl/ch-1.pl | 26 +++++++ challenge-190/peter-campbell-smith/perl/ch-2.pl | 93 +++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 challenge-190/peter-campbell-smith/blog.txt create mode 100755 challenge-190/peter-campbell-smith/perl/ch-1.pl create mode 100755 challenge-190/peter-campbell-smith/perl/ch-2.pl (limited to 'challenge-190') diff --git a/challenge-190/peter-campbell-smith/blog.txt b/challenge-190/peter-campbell-smith/blog.txt new file mode 100644 index 0000000000..0aa7e6346d --- /dev/null +++ b/challenge-190/peter-campbell-smith/blog.txt @@ -0,0 +1 @@ +https://pjcs-pwc.blogspot.com/2022/11/capital-test-and-ambiguous-encoding.html diff --git a/challenge-190/peter-campbell-smith/perl/ch-1.pl b/challenge-190/peter-campbell-smith/perl/ch-1.pl new file mode 100755 index 0000000000..a4b4a01566 --- /dev/null +++ b/challenge-190/peter-campbell-smith/perl/ch-1.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +# Peter Campbell Smith - 2022-11-07 +# PWC 190 task 1 + +use v5.28; +use utf8; +use warnings; +binmode(STDOUT, ':utf8'); + +# You are given a string with alphabetic characters only: A..Z and a..z. Write a script to find out if the usage of +# capital letters is appropriate if it satisfies at least one of the following rules: +# 1) Only first letter is capital and all others are small. +# 2) Every letter is small. +# 3) Every letter is capital. + +# Blog: https://pjcs-pwc.blogspot.com/2022/11/capital-test-and-ambiguous-encoding.html + +my (@tests, $test); + +@tests = qw[Perl PWC PyThon raku Byron ShakesSpeare miltoN KEATS 123 6-fold Hello! a A]; + +# loop over tests + while ($test = shift @tests) { + say qq[\nInput: $test\nOutput: ] . ($test =~ m/^[A-Z]?([a-z]*|[A-Z]*)$/ ? 1 : 0); +} diff --git a/challenge-190/peter-campbell-smith/perl/ch-2.pl b/challenge-190/peter-campbell-smith/perl/ch-2.pl new file mode 100755 index 0000000000..542854322e --- /dev/null +++ b/challenge-190/peter-campbell-smith/perl/ch-2.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +# Peter Campbell Smith - 2022-11-07 +# PWC 190 task 1 + +use v5.28; +use utf8; +use warnings; +binmode(STDOUT, ':utf8'); + +# You are given a string consisting of a sequence of numeric characters: 0..9. The string is a concatenation +# of encoded letters A-Z, where A = 1, B = 2 ... Z = 26. Write a script to find the all valid different decodings +# in sorted order. Example: Input: $s = 11; Ouput: AA, K + +# Blog: https://pjcs-pwc.blogspot.com/2022/11/capital-test-and-ambiguous-encoding.html + +my (@tests, $base, $string, $answer, %answers, $test); + +@tests = qw[11 1115 127 16518122051920]; +$base = ord('A') - 1; # so that we can convert a number to a character as $char = chr($base + $number) + +# loop over tests +while ($test = shift @tests) { + + # analyse the input string + say qq[\nInput: $test]; + %answers = (); + analyse('', $test); + + # format and output the answers + $string = ''; + for $answer (sort keys %answers) { + $string .= $answer . ', '; + } + say qq[Output: ] . substr($string, 0, -2); +} + +sub analyse { + + my ($so_far, $test, $test_length, $first_two); + + # recursively tries taking the first 1 or 2 digits off test and adding them as a character to $so_far + + $so_far = $_[0]; # the character string so far + $test = $_[1]; # the remaining digit string + $test_length = length($test); + return if substr($test, 0, 1) eq '0'; # won't happen for a valid $test + + # take the first digit of $test and add the corresponding character to so_far + $so_far .= chr($base + substr($test, 0, 1)); + + # if anything remains in $test, analyse(the new $so_far, the rest of $test) + if ($test_length > 1) { + analyse($so_far, substr($test, 1)) if length($test) > 1; + + # else we've exhausted $test and found an answer + } else { + $answers{$so_far} = 1; + return; + } + + # if $test is >= 2 digits and they are 10-26 then add them as a character to $so_far + $so_far = $_[0]; + $first_two = substr($test, 0, 2); + if ($test_length >= 2 and $first_two ge '10' and $first_two le '26') { + $so_far .= chr($base + $first_two); + + # if anything remains in $test analyse(the new $so_far, the rest of $test) + if (length($test) > 2) { + analyse($so_far, substr($test, 2)); + + # else we've exhausted $test and found an answer + } else { + $answers{$so_far} = 1; + return; + } + } +} + + + + + + + + + + + + + + + -- cgit From d0c94dedc2635ed4ff7e3fd0ac367ccc9c65d2ae Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 7 Nov 2022 19:15:17 +0000 Subject: - Added guest contribution by Mohammad Meraj Zia. --- challenge-190/ziameraj16/java/CapitalDetection.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-190/ziameraj16/java/CapitalDetection.java (limited to 'challenge-190') diff --git a/challenge-190/ziameraj16/java/CapitalDetection.java b/challenge-190/ziameraj16/java/CapitalDetection.java new file mode 100644 index 0000000000..af7c9c30a8 --- /dev/null +++ b/challenge-190/ziameraj16/java/CapitalDetection.java @@ -0,0 +1,19 @@ +import java.util.Scanner; + +public class CapitalDetection { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter word"); + String word = scanner.nextLine(); + if (word.toUpperCase().equals(word)) { + System.out.println("Output: 1"); + } else if (word.toLowerCase().equals(word)) { + System.out.println("Output: 1"); + } else if (Character.isUpperCase(word.charAt(0)) && word.substring(1).toLowerCase().equals(word.substring(1))) { + System.out.println("Output: 1"); + } else { + System.out.println("Output: 0"); + } + } +} -- cgit From 932f8001da0046a9da141a3ee9b149199e8187e3 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 7 Nov 2022 19:26:33 +0000 Subject: - Added solutions by Robert DiCicco. --- challenge-190/robert-dicicco/perl/ch-1.pl | 99 +++++++++++++++++++++++++++++ challenge-190/robert-dicicco/raku/ch-1.raku | 95 +++++++++++++++++++++++++++ challenge-190/robert-dicicco/ruby/ch-1.rb | 85 +++++++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 challenge-190/robert-dicicco/perl/ch-1.pl create mode 100644 challenge-190/robert-dicicco/raku/ch-1.raku create mode 100644 challenge-190/robert-dicicco/ruby/ch-1.rb (limited to 'challenge-190') diff --git a/challenge-190/robert-dicicco/perl/ch-1.pl b/challenge-190/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..0947e18fb7 --- /dev/null +++ b/challenge-190/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,99 @@ +#!/usr/bin/env perl + +=begin pod + +AUTHOR: Robert DiCicco + +DATE: 2022-11-07 + +Challenge 190 Capital Detection ( Perl ) + + + +You are given a string with alphabetic characters only: A..Z and a..z. + +Write a script to find out if the usage of Capital is appropriate + +if it satisfies at least one of the following rules: + + + +1) Only first letter is capital and all others are small. + +2) Every letter is small. + +3) Every letter is capital. + + + +=cut + + + +use strict; + +use warnings; + + + +my @words = ("Perl", "TPF", "PyThon", "raku"); + + + +for my $s (@words) { + + print "Input: \$s = \'$s\'\n"; + + if ($s =~ /^[A-Z][a-z]*$/) { + + print "Output: 1\n"; + + } elsif ( $s =~ /^[a-z]*$/) { + + print "Output: 2\n"; + + } elsif ( $s =~ /^[A-Z]*$/) { + + print "Output: 3\n"; + + } else { + + print "Output: 0\n"; + + } + + print "\n"; + +} + + + +=begin pod + +PS G:\Projects\Perl\Challenges> perl .\CapitalDetection.pl + +Input: $s = 'Perl' + +Output: 1 + + + +Input: $s = 'TPF' + +Output: 3 + + + +Input: $s = 'PyThon' + +Output: 0 + + + +Input: $s = 'raku' + +Output: 2 + + + +=cut diff --git a/challenge-190/robert-dicicco/raku/ch-1.raku b/challenge-190/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..3d63098436 --- /dev/null +++ b/challenge-190/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,95 @@ +use v6; + +=begin comment + +AUTHOR: Robert DiCicco + +DATE: 2022-11-07 + +Challenge 190 Capital Detection ( Raku ) + + + +You are given a string with alphabetic characters only: A..Z and a..z. + +Write a script to find out if the usage of Capital is appropriate + +if it satisfies at least one of the following rules: + + + +1) Only first letter is capital and all others are small. + +2) Every letter is small. + +3) Every letter is capital. + + + +=end comment + + + +my @words = ("Perl", "TPF", "PyThon", "raku"); + + + +for (@words) -> $s { + + say "Input: \$s = \'$s'"; + + if ($s ~~ /^<:Lu><:Ll>*$/) { + + say "Output: 1"; + + } elsif ( $s ~~ /^<:Ll>*$/) { + + say "Output: 2"; + + } elsif ($s ~~ /^<:Lu>*$/) { + + say "Output: 3"; + + } else { + + say "Output: 0"; + + } + + say " "; + +} + + + +=begin comment + +SAMPLE OUTPUT + +PS G:\Projects\Perl\Challenges> raku .\CapitalDetection.rk + +Input: $s = 'Perl' + +Output: 1 + + + +Input: $s = 'TPF' + +Output: 3 + + + +Input: $s = 'PyThon' + +Output: 0 + + + +Input: $s = 'raku' + +Output: 2 + + + +=end comment diff --git a/challenge-190/robert-dicicco/ruby/ch-1.rb b/challenge-190/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..aaf02305b6 --- /dev/null +++ b/challenge-190/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,85 @@ +#!/usr/bin/envruby + +=begin + +AUTHOR: Robert DiCicco + +DATE: 2022-11-07 + +Challenge 190 Capital Detection ( Ruby ) + + + +You are given a string with alphabetic characters only: A..Z and a..z. + +Write a script to find out if the usage of Capital is appropriate + +if it satisfies at least one of the following rules: + + + +1) Only first letter is capital and all others are small. + +2) Every letter is small. + +3) Every letter is capital. + + + +SAMPLE OUTPUT + +Input: $s = "Perl" + +Output: 1 + + + +Input: $s = "TPF" + +Output: 3 + + + +Input: $s = "PyThon" + +Output: 0 + + + +Input: $s = "raku" + +Output: 2 + +=end + + + +words = ["Perl", "TPF", "PyThon", "raku"] + + + +words.each do |s| + + puts "Input: $s = \"#{s}\"" + + if s.match(/^[A-Z][a-z]*$/) + + puts "Output: 1" + + elsif s.match(/^[a-z]*$/) + + puts "Output: 2" + + elsif s.match(/^[A-Z]*$/) + + puts "Output: 3" + + else + + puts "Output: 0" + + end + + puts " " + +end -- cgit From bff965b2cc342cab42f417f19d719a197d591f9b Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 7 Nov 2022 13:28:31 -0600 Subject: Fix blog ref. --- challenge-190/wlmb/blog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'challenge-190') diff --git a/challenge-190/wlmb/blog.txt b/challenge-190/wlmb/blog.txt index b26859dcd3..02200c0225 100644 --- a/challenge-190/wlmb/blog.txt +++ b/challenge-190/wlmb/blog.txt @@ -1 +1 @@ -https://wlmb.github.io//2022/11/07/PWC190.org +https://wlmb.github.io//2022/11/07/PWC190/ -- cgit From 6bdbf9ab9127cdae91f53d71b7e13a33137e706d Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 7 Nov 2022 13:29:22 -0600 Subject: Fix blog --- challenge-190/wlmb/blog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'challenge-190') diff --git a/challenge-190/wlmb/blog.txt b/challenge-190/wlmb/blog.txt index 02200c0225..2f3360d6eb 100644 --- a/challenge-190/wlmb/blog.txt +++ b/challenge-190/wlmb/blog.txt @@ -1 +1 @@ -https://wlmb.github.io//2022/11/07/PWC190/ +https://wlmb.github.io/2022/11/07/PWC190/ -- cgit From 787cb33b3af40ad2061b6401c37f4224f324f184 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 7 Nov 2022 19:34:46 +0000 Subject: - Added more guest contribution by Robert DiCicco. --- challenge-190/robert-dicicco/julia/ch-1.jl | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 challenge-190/robert-dicicco/julia/ch-1.jl (limited to 'challenge-190') diff --git a/challenge-190/robert-dicicco/julia/ch-1.jl b/challenge-190/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..c506d00621 --- /dev/null +++ b/challenge-190/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,87 @@ +#!/usr/bin/env julia + +#= + +AUTHOR: Robert DiCicco + +DATE: 2022-11-07 + +Challenge 190 Capital Detection ( Julia ) + + + +You are given a string with alphabetic characters only: A..Z and a..z. + +Write a script to find out if the usage of Capital is appropriate + +if it satisfies at least one of the following rules: + + + +1) Only first letter is capital and all others are small. + +2) Every letter is small. + +3) Every letter is capital. + + + +SAMPLE OUTPUT + +Input: $s = "Perl" + +Output: 1 + + + +Input: $s = "TPF" + +Output: 3 + + + +Input: $s = "PyThon" + +Output: 0 + + + +Input: $s = "raku" + +Output: 2 + +=# + + + +using Printf + +words = ["Perl", "TPF", "PyThon", "raku"] + + + +for s in words + + @printf("Input: \$s = \"%s\"\n",s) + + if occursin(r"^[A-Z][a-z]*$", s ) + + @printf("Output: 1\n") + + elseif occursin(r"^[a-z]*$", s) + + @printf("Output: 2\n") + + elseif occursin(r"^[A-Z]*$", s) + + @printf("Output: 3\n") + + else + + @printf("Output: 0\n") + + end + + println(" ") + +end -- cgit From 15c399a9ae502133ca20e017266bdc6358819919 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 7 Nov 2022 23:23:08 +0100 Subject: Add solutions to 190: Capital Detection & Decoded List by E. Choroba --- challenge-190/e-choroba/perl/ch-1.pl | 17 +++++++++++++++++ challenge-190/e-choroba/perl/ch-2.pl | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 challenge-190/e-choroba/perl/ch-1.pl create mode 100755 challenge-190/e-choroba/perl/ch-2.pl (limited to 'challenge-190') diff --git a/challenge-190/e-choroba/perl/ch-1.pl b/challenge-190/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..ac63d714ae --- /dev/null +++ b/challenge-190/e-choroba/perl/ch-1.pl @@ -0,0 +1,17 @@ +#! /usr/bin/perl +use warnings; +use strict; +use experimental 'signatures'; + +sub capital_detection ($string) { + $string !~ /[[:lower:]][[:upper:]]/ ? 1 : 0 +} + +use Test::More tests => 4 + 1; + +is capital_detection('Perl'), 1, 'Example 1'; +is capital_detection('TPF'), 1, 'Example 2'; +is capital_detection('PyThon'), 0, 'Example 3'; +is capital_detection('raku'), 1, 'Example 4'; + +is capital_detection(""), 1, 'Empty'; diff --git a/challenge-190/e-choroba/perl/ch-2.pl b/challenge-190/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..18050ce183 --- /dev/null +++ b/challenge-190/e-choroba/perl/ch-2.pl @@ -0,0 +1,33 @@ +#! /usr/bin/perl +use warnings; +use strict; +use experimental 'signatures'; +use Memoize; + +my %to_char = ("" => "", + map { $_ => chr $_ - 1 + ord 'A'} 1 .. 26); +memoize('decoded_list'); +sub decoded_list ($digits) { + return [] if '0' eq substr $digits, 0, 1; + + return [$to_char{$digits}] if 1 >= length $digits; + + return [map { + my $prefix = $_; + map $to_char{$prefix} . $_, + @{ decoded_list(substr($digits, length $prefix)) } + } grep exists $to_char{$_}, + map substr($digits, 0, $_), 1, 2] +} + +use Test2::V0; +plan 3 + 4; + +is decoded_list('11'), [qw[ AA K ]], 'Example 1'; +is decoded_list('1115'), [qw[ AAAE AAO AKE KAE KO ]], 'Example 2'; +is decoded_list('127'), [qw[ ABG LG ]], 'Example 3'; + +is decoded_list(""), [""], 'Empty'; +is decoded_list('01'), [], 'Initial zero'; +is decoded_list('101'), ['JA'], 'Later zero'; # No /^A/. +is decoded_list('1001'), [], 'Later zeros'; # 00 can't be decoded. -- cgit From 3ada633e21976e512042ff6ed651f4c62cc67852 Mon Sep 17 00:00:00 2001 From: CY Fung Date: Tue, 8 Nov 2022 07:25:31 +0800 Subject: Week 190 Perl solutions --- challenge-190/cheok-yin-fung/perl/ch-1.pl | 20 +++++++++ challenge-190/cheok-yin-fung/perl/ch-2.pl | 74 +++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 challenge-190/cheok-yin-fung/perl/ch-1.pl create mode 100644 challenge-190/cheok-yin-fung/perl/ch-2.pl (limited to 'challenge-190') diff --git a/challenge-190/cheok-yin-fung/perl/ch-1.pl b/challenge-190/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..6536cf090f --- /dev/null +++ b/challenge-190/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,20 @@ +# The Weekly Challenge 190 +# Task 1 Capital Detection +use v5.30.0; + +my $c1 = '^[A-Z][a-z]*$'; +my $c2 = '^[a-z]+$'; +my $c3 = '^[A-Z]+$'; + +say good($ARGV[0]) if $ARGV[0]; + +sub good { + return 1 if $_[0] =~ m/$c1/ || $_[0] =~ m/$c2/ || $_[0] =~ m/$c3/; + return 0; +} + +use Test::More tests=>4; +ok good('Perl'); +ok good('TPF'); +ok !good('PyThon'); +ok good('raku'); diff --git a/challenge-190/cheok-yin-fung/perl/ch-2.pl b/challenge-190/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..6b8b73cc92 --- /dev/null +++ b/challenge-190/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,74 @@ +# The Weekly Challenge 190 +# Task 2 Decoded List +use v5.30.0; +use warnings; +use Algorithm::Combinatorics qw /combinations/; +use List::Util qw/all/; + +say join "\n", decode($ARGV[0]) if defined($ARGV[0]) && $ARGV[0] =~ m/\d+/; + +sub decode { + my $c1 = '^[1-9]$'; + my $c2 = '^1[0-9]$'; + my $c3 = '^2[0-6]$'; + + my $ciphertext = $_[0]; + my @plaintexts; + + # split the string into bites of ones and twos; + # using codes from TWC 112 Climb Stairs + my $n = length $ciphertext; + + my @possibilies; + + for my $i ($n%2+$n/2 .. $n-1) { + my $iter = combinations([0..$i-1] , ($n-$i) ); + my $str = "1" x $i; + while (my $c = $iter->next) { + my $str_clone = $str; + substr($str_clone, $_, 1) = "2" for (@{$c}); + push @possibilies, $str_clone; + } + } + push @possibilies , "1" x $n; + + foreach my $onetwoseq (@possibilies) { + my @ABCDE_in_nmrc = divide_string($ciphertext, $onetwoseq); + next unless all { $_ =~ m/$c1/ + || $_ =~ m/$c2/ + || $_ =~ m/$c3/ } @ABCDE_in_nmrc; + push @plaintexts, join "", map {OneToA($_)} @ABCDE_in_nmrc; + } + return @plaintexts; +} + +sub divide_string { + my $text = $_[0]; + my $nums = $_[1]; + my @temp = split "", $text; + my @digits = split "", $nums; + my @result; + my $i = 0; + for (@digits) { + my $k = $_; + my $w = ""; + while ($k != 0) { + $w .= $temp[$i]; + $i++; + $k--; + } + push @result, $w; + } + return @result; +} + +sub OneToA { + return chr( ord('A') - 1 + $_[0] ); +} + + + +# checking +say " 11: ", join ", ", decode("11"); # "AA", "K" +say "1115: ", join ", ", decode("1115"); # "AAAE", "AAO", "AKE", "KAE", "KO" +say " 127: ", join ", ", decode("127"); #"ABG", "LG" -- cgit From 47f90edd7f8967abf70a611862f40ed05a05ec9a Mon Sep 17 00:00:00 2001 From: Polgár Márton Date: Tue, 8 Nov 2022 00:44:19 +0100 Subject: Weeklies no. 190 by 2colours --- challenge-190/2colours/raku/ch-1.raku | 11 +++++++++++ challenge-190/2colours/raku/ch-2.raku | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 challenge-190/2colours/raku/ch-1.raku create mode 100755 challenge-190/2colours/raku/ch-2.raku (limited to 'challenge-190') diff --git a/challenge-190/2colours/raku/ch-1.raku b/challenge-190/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..4e557f39c2 --- /dev/null +++ b/challenge-190/2colours/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku + +subset AsciiWord of Str where /^ <[a..zA..Z]>* $/; + +sub MAIN(AsciiWord $s) { + $s andthen + $_ eq any(.tclc, .lc, .uc) andthen + .so + .Int + .say; +} \ No newline at end of file diff --git a/challenge-190/2colours/raku/ch-2.raku b/challenge-190/2colours/raku/ch-2.raku new file mode 100755 index 0000000000..8aaa409c5f --- /dev/null +++ b/challenge-190/2colours/raku/ch-2.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku + +#NOTE: disallowing leading zeros and completely empty input + +subset Encoding of Str where /^ <[1..9]><[0..9]>* $/; + +use experimental :cached; + +sub nth-letter($n) { chr(ord('A') + $n - 1) } + + +proto decodings(@content) is cached {*} +multi decodings(() --> '') {} +multi decodings(('0', ) --> Empty) {} +multi decodings(($codepoint, )) { nth-letter $codepoint } +multi decodings(('0', $, **@) --> Empty) {} +multi decodings(($first, $next, **@rest)) { + slip (nth-letter($first) <<~<< decodings(($next, |@rest))), + slip (.&nth-letter <<~<< decodings(@rest) if $_ <= 26 given $first ~ $next) +} + + + +sub MAIN(Encoding $s) { + $s.comb.&decodings.sort.join(', ').say; +} \ No newline at end of file -- cgit From f4096abb2329c645192d43e30c0b8726c43189fa Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 8 Nov 2022 07:37:11 +0000 Subject: Challenge 190 do-over (Raku) --- challenge-190/mark-anderson/raku/ch-1.raku | 2 +- challenge-190/mark-anderson/raku/ch-2.raku | 38 +++++++++++++++++------------- 2 files changed, 23 insertions(+), 17 deletions(-) (limited to 'challenge-190') diff --git a/challenge-190/mark-anderson/raku/ch-1.raku b/challenge-190/mark-anderson/raku/ch-1.raku index 16b5ff297a..00301d78f5 100644 --- a/challenge-190/mark-anderson/raku/ch-1.raku +++ b/challenge-190/mark-anderson/raku/ch-1.raku @@ -8,5 +8,5 @@ ok capital-detection("raku"); sub capital-detection($s) { - any($s eq $s.tclc, $s eq $s.lc, $s eq $s.uc) + $s eq any($s.tclc, $s.lc, $s.uc) } diff --git a/challenge-190/mark-anderson/raku/ch-2.raku b/challenge-190/mark-anderson/raku/ch-2.raku index be1685915e..9f049c1bab 100644 --- a/challenge-190/mark-anderson/raku/ch-2.raku +++ b/challenge-190/mark-anderson/raku/ch-2.raku @@ -1,24 +1,30 @@ #!/usr/bin/env raku use Test; -is-deeply decode-counts(11), < AA K >; -is-deeply decode-counts(1115), < AAAE AAO AKE KAE KO >; -is-deeply decode-counts(127), < ABG LG >; +is-deeply decoded-list(11), < AA K >; +is-deeply decoded-list(1115), < AAAE AAO AKE KAE KO >; +is-deeply decoded-list(127), < ABG LG >; +is-deeply decoded-list(1002005), < ABE JBE JTE >; -# Not sure how to deal with zeros but this is what the program does. -is-deeply decode-counts(1002001), < ABA ATA JBA JTA >; +sub decoded-list($n is copy) +{ + $n ~~ s:g/0+/0/; # Ignoring leading zeros to make things easy. + + ones-and-twos($n.chars).map({ $n.comb.rotor($_)>>.join>>.Int }) + .grep({ all($_) ~~ 1..26 }) + .deepmap({ chr($_ + 64) }) + .map({ .join }); +} -sub decode-counts($n) +sub ones-and-twos($n) { - sub composition($_) - { - gather .fmt('%0' ~ $n.chars ~ 'b') ~~ m:g/(.)$0* / - } + my $start = ((0,0,1) xx *).flat.head($n).join.parse-base(2); + my $stop = ((0,1,1) xx *).flat.head($n).join.parse-base(2); - sort map - { - my $c := $n.comb.rotor(composition($_))>>.join>>.Int; - next unless all($c) ~~ 1..26; - [~] $c.map({ chr($_+64) }); - }, ^2**($n.chars-1) + sort map + { + my $b = .fmt('%0' ~ $n ~ 'b'); + next if $b ~~ /000|111/; + gather $b ~~ m:g/(.)$0? / + }, $start..$stop } -- cgit From 03d34bb7eee80f0a306e7e059ea8b34867fdc2f8 Mon Sep 17 00:00:00 2001 From: 冯昶 Date: Tue, 8 Nov 2022 18:16:14 +0800 Subject: challenge #190, raku solutions --- challenge-190/feng-chang/raku/ch-1.raku | 4 ++++ challenge-190/feng-chang/raku/ch-2.raku | 9 +++++++++ challenge-190/feng-chang/raku/ch-2a.raku | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100755 challenge-190/feng-chang/raku/ch-1.raku create mode 100755 challenge-190/feng-chang/raku/ch-2.raku create mode 100755 challenge-190/feng-chang/raku/ch-2a.raku (limited to 'challenge-190') diff --git a/challenge-190/feng-chang/raku/ch-1.raku b/challenge-190/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..820deb0b18 --- /dev/null +++ b/challenge-190/feng-chang/raku/ch-1.raku @@ -0,0 +1,4 @@ +#!/bin/env raku + +unit sub MAIN(Str:D \s); +put +so s eq s.lc.tc|s.lc|s.uc; diff --git a/challenge-190/feng-chang/raku/ch-2.raku b/challenge-190/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..f8820083c5 --- /dev/null +++ b/challenge-190/feng-chang/raku/ch-2.raku @@ -0,0 +1,9 @@ +#!/bin/env raku + +unit sub MAIN(UInt:D \N); + +my $len = N.chars - 1; +for ^2**$len -> \n { + my @A = (N.comb »Z~» n.fmt("\%0{$len}b").comb».trans(<0 1> => ('',' '))).join.comb(/\d+/); + put @A».&{ chr($_ - 1 + 'A'.ord) }.join if 1 ≤ @A.all ≤ 26; +} diff --git a/challenge-190/feng-chang/raku/ch-2a.raku b/challenge-190/feng-chang/raku/ch-2a.raku new file mode 100755 index 0000000000..f8ea148f07 --- /dev/null +++ b/challenge-190/feng-chang/raku/ch-2a.raku @@ -0,0 +1,15 @@ +#!/bin/env raku + +unit sub MAIN(UInt:D \N); + +my $len = N.chars - 1; +(^2**$len) + .map(-> \n { + (N.comb »Z~» n.fmt("\%0{$len}b").comb».trans(<0 1> => ('',' '))) + .join + .comb(/\d+/) + }) + .grep({ 1 ≤ @$_.all ≤ 26 }) + .map(-> $a { + @$a».&{ chr( $_ - 1 + 'A'.ord ) }.join.put + }); -- cgit From 87997719ba499f2b60ab4307bb4b56a5a4eb9f00 Mon Sep 17 00:00:00 2001 From: Humberto Massa Date: Tue, 8 Nov 2022 08:28:12 -0300 Subject: decode-counts gave me some trouble --- challenge-190/massa/raku/ch-1.raku | 31 ++++++++++++++++++++++++++++++ challenge-190/massa/raku/ch-2.raku | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 challenge-190/massa/raku/ch-1.raku create mode 100644 challenge-190/massa/raku/ch-2.raku (limited to 'challenge-190') diff --git a/challenge-190/massa/raku/ch-1.raku b/challenge-190/massa/raku/ch-1.raku new file mode 100644 index 0000000000..1de5f81ce8 --- /dev/null +++ b/challenge-190/massa/raku/ch-1.raku @@ -0,0 +1,31 @@ + +#!/usr/bin/env raku + +=begin pod + +Week 190: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-190 + +Task #1: Capital Detection + + Write a script to find out if the usage of Capital is appropriate if it satisfies at least one of the following rules: + + 1) Only first letter is capital and all others are small. + 2) Every letter is small. + 3) Every letter is capital. + +=end pod + +use Test; + +my regex capital-detection { ^ [ * | + | + ] $ } + +ok 'Perl' ~~ //; +ok 'TPF' ~~ //; +nok 'PyThon' ~~ //; +ok 'raku' ~~ //; + +done-testing; + + diff --git a/challenge-190/massa/raku/ch-2.raku b/challenge-190/massa/raku/ch-2.raku new file mode 100644 index 0000000000..f59da3aef9 --- /dev/null +++ b/challenge-190/massa/raku/ch-2.raku @@ -0,0 +1,39 @@ + +#!/usr/bin/env raku + +=begin pod + +Week 190: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-190 + +Task #2: Decoded List + + You are given an encoded string consisting of a sequence of numeric + characters: C<0..9>, C<$s>. + + Write a script to find the all valid different decodings in sorted order. + + Encoding is simply done by mapping A,B,C,D,… to 1,2,3,4,… etc. + + +=end pod + +use Test; + +is-deeply , decoded-list 11; +is-deeply , decoded-list 1115; +is-deeply , decoded-list 127; + +done-testing; + +sub decoded-list(Str() $_) { + combinations(.chars + 1, .chars div 2 .. .chars + 1)».\ # all the combinations + rotor(2=>-1)».Array».map({.[0] ..^ .[1]})».Array.\ # transformed in contiguous subsets + grep(*».elems.all == 1|2).\ # subsets must be of size one or two + grep(*».elems.sum == .chars)».\ # and they must cover the whole string + map(-> @s { .comb[@s].join })».\ # map to the original string's chars + trans([1..26] => ['A'..'Z'])».join.\ # decode + sort.unique +} + -- cgit From b6d45e9220a927ff4c90680007f656d891552529 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:37:09 +0000 Subject: still working on ch-2.raku --- challenge-190/mark-anderson/raku/ch-2.raku | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 challenge-190/mark-anderson/raku/ch-2.raku (limited to 'challenge-190') diff --git a/challenge-190/mark-anderson/raku/ch-2.raku b/challenge-190/mark-anderson/raku/ch-2.raku deleted file mode 100644 index 9f049c1bab..0000000000 --- a/challenge-190/mark-anderson/raku/ch-2.raku +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env raku -use Test; - -is-deeply decoded-list(11), < AA K >; -is-deeply decoded-list(1115), < AAAE AAO AKE KAE KO >; -is-deeply decoded-list(127), < ABG LG >; -is-deeply decoded-list(1002005), < ABE JBE JTE >; - -sub decoded-list($n is copy) -{ - $n ~~ s:g/0+/0/; # Ignoring leading zeros to make things easy. - - ones-and-twos($n.chars).map({ $n.comb.rotor($_)>>.join>>.Int }) - .grep({ all($_) ~~ 1..26 }) - .deepmap({ chr($_ + 64) }) - .map({ .join }); -} - -sub ones-and-twos($n) -{ - my $start = ((0,0,1) xx *).flat.head($n).join.parse-base(2); - my $stop = ((0,1,1) xx *).flat.head($n).join.parse-base(2); - - sort map - { - my $b = .fmt('%0' ~ $n ~ 'b'); - next if $b ~~ /000|111/; - gather $b ~~ m:g/(.)$0? / - }, $start..$stop -} -- cgit From 2b107c0a1007dc904822ac1a2c19d76d697fc559 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 9 Nov 2022 20:22:05 +0000 Subject: - Added solutions by Ulrich Rieke. --- challenge-190/ulrich-rieke/cpp/ch-1.cpp | 22 ++++++++ challenge-190/ulrich-rieke/haskell/ch-1.hs | 7 +++ challenge-190/ulrich-rieke/haskell/ch-2.hs | 37 ++++++++++++ challenge-190/ulrich-rieke/java/Challenge190.java | 19 +++++++ challenge-190/ulrich-rieke/perl/ch-1.pl | 19 +++++++ challenge-190/ulrich-rieke/perl/ch-2.pl | 68 +++++++++++++++++++++++ challenge-190/ulrich-rieke/raku/ch-1.raku | 14 +++++ challenge-190/ulrich-rieke/rust/ch-1.rs | 19 +++++++ 8 files changed, 205 insertions(+) create mode 100644 challenge-190/ulrich-rieke/cpp/ch-1.cpp create mode 100644 challenge-190/ulrich-rieke/haskell/ch-1.hs create mode 100644 challenge-190/ulrich-rieke/haskell/ch-2.hs create mode 100644 challenge-190/ulrich-rieke/java/Challenge190.java create mode 100644 challenge-190/ulrich-rieke/perl/ch-1.pl create mode 100644 challenge-190/ulrich-rieke/perl/ch-2.pl create mode 100644 challenge-190/ulrich-rieke/raku/ch-1.raku create mode 100644 challenge-190/ulrich-rieke/rust/ch-1.rs (limited to 'challenge-190') diff --git a/challenge-190/ulrich-rieke/cpp/ch-1.cpp b/challenge-190/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..c013223bfe --- /dev/null +++ b/challenge-190/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +int main( ) { + std::cout << "Please enter a word!\n" ; + std::string line ; + std::cin >> line ; + if ( (std::isupper( static_cast( line[0] )) && + std::all_of( line.begin( ) + 1 , line.end( ) , []( char c ) + {return std::islower( static_cast( c )) ; } )) || + std::all_of( line.begin( ) , line.end( ) , []( char c ) + { return std::isupper( static_cast( c )) ; }) || + std::all_of( line.begin( ) , line.end( ) , []( char c ) + { return std::islower( static_cast( c )) ; }) ) + std::cout << 1 ; + else + std::cout << 0 ; + std::cout << std::endl ; + return 0 ; +} diff --git a/challenge-190/ulrich-rieke/haskell/ch-1.hs b/challenge-190/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..c058635a08 --- /dev/null +++ b/challenge-190/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,7 @@ +module Challenge190 + where +import Data.Char ( isUpper , isLower ) + +solution :: String -> Int +solution input = if (all isUpper input || all isLower input || ( isUpper +( head input ) && all isLower (tail input) )) then 1 else 0 diff --git a/challenge-190/ulrich-rieke/haskell/ch-2.hs b/challenge-190/ulrich-rieke/haskell/ch-2.hs new file mode 100644 index 0000000000..419a3f3f11 --- /dev/null +++ b/challenge-190/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,37 @@ +module Challenge190_2 + where +import qualified Data.Set as S +import Data.List ( permutations , sort ) +import Data.List.Split ( divvy ) +import Data.Char ( chr ) + +--find all sublists of 1's and 2's that add up to a given integer +findSublists :: Int -> [[Int]] +findSublists l = [replicate t 2 ++ replicate ( l - 2 * t ) 1 | +t <- [ 0 .. div l 2 ]] + +findAllPermutations :: [[Int]] -> [[Int]] +findAllPermutations list = (S.toList $ S.fromList $ concat $ +map permutations $ filter (\li -> elem 2 li ) list) ++ +[head list] + +findSubstring :: String -> Int -> Int -> String +findSubstring str from to = take ( to - from ) $ drop from str + +findNumberlist :: String -> [Int] -> [Int] +findNumberlist s thePartitions = map read $ map (\li -> findSubstring s +( head li ) ( last li )) $ divvy 2 1 $ scanl ( + ) 0 thePartitions + +findWord :: [Int] -> String +findWord list = if any ( > 26 ) list then "" else map ( chr . (+ 64 )) list + +solution :: String -> [String] +solution number = sort $ filter ( not . null ) $ map findWord $ +map (\li -> findNumberlist number li ) +$ findAllPermutations $ findSublists ( length number ) + +main :: IO ( ) +main = do + putStrLn "Enter a string consisting only of digits!" + numberstring <- getLine + print $ solution numberstring diff --git a/challenge-190/ulrich-rieke/java/Challenge190.java b/challenge-190/ulrich-rieke/java/Challenge190.java new file mode 100644 index 0000000000..7a3eaaadcd --- /dev/null +++ b/challenge-190/ulrich-rieke/java/Challenge190.java @@ -0,0 +1,19 @@ +import java.util.Scanner ; +import java.util.regex.* ; + +public class Challenge190 { + public static void main( String[] args ) { + Scanner sc = new Scanner( System.in ) ; + String reg1 = "^[A-Z][a-z]+$" ; + String reg2 = "^[A-Z]+$" ; + String reg3 = "^[a-z]+$" ; + System.out.println( "Please enter a line consisting of letters only!" ) ; + String line = sc.nextLine( ) ; + if ( line.matches( reg1 ) || line.matches( reg2 ) || line.matches( reg3) ){ + System.out.println( 1 ) ; + } + else { + System.out.println( 0 ) ; + } + } +} diff --git a/challenge-190/ulrich-rieke/perl/ch-1.pl b/challenge-190/ulrich-rieke/perl/ch-1.pl new file mode 100644 index 0000000000..d9250c5a44 --- /dev/null +++ b/challenge-190/ulrich-rieke/perl/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; + +say "Enter a string consisting of letters only!" ; +my $s = ; +chomp $s ; +while ( $s !~ /^[a-zA-Z]+$/ ) { + say "string must consist of letters only! Re-enter!" ; + $s = ; + chomp $s ; +} +if ( $s =~ /^[A-Z]+$/ || $s =~ /^[a-z]+$/ || $s =~ /^[A-Z][a-z]+$/) { + say 1 ; +} +else { + say 0 ; +} diff --git a/challenge-190/ulrich-rieke/perl/ch-2.pl b/challenge-190/ulrich-rieke/perl/ch-2.pl new file mode 100644 index 0000000000..00c6e88377 --- /dev/null +++ b/challenge-190/ulrich-rieke/perl/ch-2.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; +use feature 'say' ; +use Algorithm::Combinatorics qw ( variations_with_repetition ) ; +use List::Util qw ( sum all ) ; + +#this task is about finding all combinations of 1 and 2 that add up +#to the total length of $s , the number that is given at the outset. +#There is a maximum of 1's, admixing as many 2's as +#necessary to find a sum of + +#we compute the maximal number of 2's in all combinations of 1 and 2 +#and the minimum amount of 1's. Their sum is the shortest possible +#array of 1's and 2's that adds up to the given length of $s. The +#maximum length is the length of $s , if the array consists of 1's only +sub findCombinations { + my $length = shift ; + my @nums = ( 1 , 2 ) ; + my @allCombinations ; + my $twos = int( $length / 2 ) ;#maximal number of 2's in the array + my $ones = $length - $twos * 2 ;#minimal number of 1's in the array + for my $l ( ($ones + $twos)..$length ) { + my $iter = variations_with_repetition(\@nums , $l ) ; + while ( my $p = $iter->next ) { + if ( sum( @$p ) == $length ) { + push @allCombinations , $p ; + } + } + } + return @allCombinations ; +} + +#function to convert an array of 1's and 2's to a word +sub arrayToWord { + my $array = shift ; + if ( all { $_ < 27 } @$array ) { + my @letters = map { chr( $_ + 64 ) } @$array ; + return join ('' , @letters ) ; + } + else { + return "" ; + } +} + +say "Enter a number string!" ; +my $s = ; +chomp $s ; +while ( $s !~ /^\d+$/ ) { + say "the string must consist of numbers only! Please re-enter!" ; + $s = ; + chomp $s ; +} +my @allCombinations = findCombinations( length $s ) ; +my @words ; +for my $combi ( @allCombinations ) { + my @digits ; + my $pos = 0 ; + for my $num( @$combi ) { + push @digits , substr( $s , $pos , $num ) ; + $pos += $num ; + } + my $word = arrayToWord( \@digits ) ; + if ( $word ) { + push @words , $word ; + } +} +say join( ',' , sort @words ) ; diff --git a/challenge-190/ulrich-rieke/raku/ch-1.raku b/challenge-190/ulrich-rieke/raku/ch-1.raku new file mode 100644 index 0000000000..cc35fa7531 --- /dev/null +++ b/challenge-190/ulrich-rieke/raku/ch-1.raku @@ -0,0 +1,14 @@ +use v6 ; + +say "Please enter a word consisting of letters only!" ; +my $word = $*IN.get ; +while ( $word !~~ /^<[a..zA..Z]>+$/ ) { + say "the word should consist of letters only! Please re-enter!" ; + $word = $*IN.get ; +} +if ( $word ~~ ( /^<[A..Z]>+$/ | /^<[A..Z]><[a..z]>+$/ | /^<[a..z]>+$/ ) ) { + say 1 ; +} +else { + say 0 ; +} diff --git a/challenge-190/ulrich-rieke/rust/ch-1.rs b/challenge-190/ulrich-rieke/rust/ch-1.rs new file mode 100644 index 0000000000..449e0350d1 --- /dev/null +++ b/challenge-190/ulrich-rieke/rust/ch-1.rs @@ -0,0 +1,19 @@ +use std::io ; + +fn main() { + println!("Enter a single word!") ; + let mut inline : String = String::new( ) ; + io::stdin( ).read_line( & mut inline ).unwrap( ) ; + let mut entered_line : &str = &*inline ; + entered_line = entered_line.trim( ) ; + let tailstring : &str = &entered_line[1..] ; + if (entered_line.chars( ).nth( 0 ).unwrap( ).is_uppercase( ) && + tailstring.chars( ).all( | c | c.is_lowercase( ))) || + entered_line.chars( ).all( | c | c.is_lowercase( ) ) || + entered_line.chars( ).all( | c | c.is_uppercase( )) { + println!("1") ; + } + else { + println!("0") ; + } +} -- cgit From 6820ca60cd19b1148ac5eef495b0a172d0426f32 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 9 Nov 2022 20:26:45 +0000 Subject: - Added guest contributions by Eric Cheung. --- challenge-190/eric-cheung/python/ch-1.py | 15 +++++++++ challenge-190/eric-cheung/python/ch-2.py | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 challenge-190/eric-cheung/python/ch-1.py create mode 100755 challenge-190/eric-cheung/python/ch-2.py (limited to 'challenge-190') diff --git a/challenge-190/eric-cheung/python/ch-1.py b/challenge-190/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..0f32352a2d --- /dev/null +++ b/challenge-190/eric-cheung/python/ch-1.py @@ -0,0 +1,15 @@ + +def IsApproCapital (strFuncInput): + + if strFuncInput.islower() or strFuncInput.isupper() or strFuncInput[0].isupper() and strFuncInput[1:].islower(): + return True + + return False + + +## strInput = "Perl" ## Example 1 +## strInput = "TPF" ## Example 2 +## strInput = "PyThon" ## Example 3 +strInput = "raku" ## Example 4 + +print ("1" if IsApproCapital(strInput) else "0") diff --git a/challenge-190/eric-cheung/python/ch-2.py b/challenge-190/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..cc9f934746 --- /dev/null +++ b/challenge-190/eric-cheung/python/ch-2.py @@ -0,0 +1,54 @@ + +## Credit: +## https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-190/roger-bell-west/python/ch-2.py + +from collections import deque + +def GetMap(strFuncInput): + return chr(int(strFuncInput) + 64) + +def GetStack(stackLeft, stackLeftTail, nLastPos): + + stackCopy = stackLeft.copy() + stackCopy.append(stackLeftTail[0:nLastPos]) + stackCopy.append(stackLeftTail[nLastPos:]) + + return stackCopy + +def decodedList(strFuncInput): + stackTemp = deque() + stackTemp.append([strFuncInput]) + arrTempOutput = set() + + while len(stackTemp) > 0: + + stackTempPopLeft = stackTemp.popleft() + stackTempPopLeftTail = stackTempPopLeft.pop() + + if len(stackTempPopLeftTail) == 0: + arrTempOutput.add(tuple(stackTempPopLeft)) + continue + + if stackTempPopLeftTail[0] != "0": + stackTemp.append(GetStack(stackTempPopLeft, stackTempPopLeftTail, 1)) + + if len(stackTempPopLeftTail) >= 2: + nCheckVal = int(stackTempPopLeftTail[0:2]) + if nCheckVal >= 1 and nCheckVal <= 26: + stackTemp.append(GetStack(stackTempPopLeft, stackTempPopLeftTail, 2)) + + arrOuput = [] + + for elemLoop in arrTempOutput: + arrOuput.append("".join(GetMap(charLoop) for charLoop in elemLoop)) + + arrOuput.sort() + + return arrOuput + + +## strInput = "11" ## Example 1 +## strInput = "1115" ## Example 2 +strInput = "127" ## Example 3 + +print (decodedList(strInput)) -- cgit From 0acbe0a181985d08a3f21ee4b57dee92b103833f Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 9 Nov 2022 20:40:37 +0000 Subject: - Added solutions by Laurent Rosenfeld. --- challenge-190/laurent-rosenfeld/blog.txt | 1 + challenge-190/laurent-rosenfeld/perl/ch-1.pl | 15 ++++++++++++++ challenge-190/laurent-rosenfeld/perl/ch-2.pl | 27 ++++++++++++++++++++++++++ challenge-190/laurent-rosenfeld/raku/ch-1.raku | 10 ++++++++++ challenge-190/laurent-rosenfeld/raku/ch-2.raku | 24 +++++++++++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 challenge-190/laurent-rosenfeld/blog.txt create mode 100644 challenge-190/laurent-rosenfeld/perl/ch-1.pl create mode 100644 challenge-190/laurent-rosenfeld/perl/ch-2.pl create mode 100644 challenge-190/laurent-rosenfeld/raku/ch-1.raku create mode 100644 challenge-190/laurent-rosenfeld/raku/ch-2.raku (limited to 'challenge-190') diff --git a/challenge-190/laurent-rosenfeld/blog.txt b/challenge-190/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..80e1343c19 --- /dev/null +++ b/challenge-190/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2022/11/perl-weekly-challenge-190-capital-detection-and-decoded-list.html diff --git a/challenge-190/laurent-rosenfeld/perl/ch-1.pl b/challenge-190/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..9ff13ce98a --- /dev/null +++ b/challenge-190/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,15 @@ +use strict; +use warnings; +use feature qw/say/; + +sub is_correct_case { + my $str = shift; + # All lowercase or all uppercase: + return 1 if $str =~ /^[a-z]+$|^[A-Z]+$/; + # One uppercase followed by only lowercase + return 1 if $str =~ /^[A-Z][a-z]+$/; + return 0; +} +for my $str () { + printf "% -8s -> %d\n", $str, is_correct_case $str; +} diff --git a/challenge-190/laurent-rosenfeld/perl/ch-2.pl b/challenge-190/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..a32bc06e22 --- /dev/null +++ b/challenge-190/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,27 @@ +use strict; +use warnings; +use feature qw/say/; + +my @result; +my $i = 1; +my %map = map { $i++ => $_ } 'A'..'Z'; + +sub decode { + my @list = @{$_[0]}; + my $out = $_[1]; + push @result, $out and return if scalar @list == 0; + if ($list[0] != 0) { + decode ([@list[1..$#list]], $out . $map{$list[0]}); + return if scalar @list == 1; + if ($list[0] == 1 or ($list[0] == 2 and $list[1] <= 6)) { + decode ([@list[2..$#list]], $out . $map{$list[0] . $list[1]}); + } + } +} + +for my $num (11, 1115, 5115, 127, 1207) { + my @digits = split //, $num; + @result = (); + decode [@digits], ""; + say "$num \t -> ", join ", ", @result; +} diff --git a/challenge-190/laurent-rosenfeld/raku/ch-1.raku b/challenge-190/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..04a2412759 --- /dev/null +++ b/challenge-190/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,10 @@ +sub is-correct-case ($str) { + # All lowercase or all uppercase: + return 1 if $str ~~ /^<:Ll>+$ | ^<:Lu>+$ /; + # One uppercase followed by only lowercase + return 1 if $str ~~ /^<:Lu><:Ll>+$/; + return 0; +} +for < Perl TPF PyThon raku Raku RAKU RaKu raKu > -> $str { + printf "% -8s -> %d\n", $str, is-correct-case $str; +} diff --git a/challenge-190/laurent-rosenfeld/raku/ch-2.raku b/challenge-190/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..493e6d4461 --- /dev/null +++ b/challenge-190/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,24 @@ +my %map = (1..26 Z 'A'..'Z').flat; +my @result; +# say %map; # {1 => A, 10 => J, 11 => K, 12 => L,... + +sub decode (@list, $out) { + if @list.elems == 0 { + push @result, $out; + return; + } + if @list[0] != 0 { + decode @list[1..@list.end], $out ~ %map{@list[0]}; + return if @list.elems == 1; + if @list[0] == 1 or (@list[0] == 2 and @list[1] <= 6) { + decode @list[2..@list.end], $out ~ %map{@list[0] ~ @list[1]}; + } + } +} + +for 11, 1115, 5115, 127, 1207 -> $num { + my @digits = $num.comb; + @result = (); + decode @digits, ""; + say "$num \t -> ", join ", ", sort @result; +} -- cgit From da31de5f73fca31c8f8d18697c979eb5e844139c Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Thu, 10 Nov 2022 00:54:03 +0100 Subject: Add polettix's solution to challenge-190 --- challenge-190/polettix/blog.txt | 1 + challenge-190/polettix/blog1.txt | 1 + challenge-190/polettix/perl/ch-1.pl | 11 ++++++ challenge-190/polettix/perl/ch-2.pl | 74 +++++++++++++++++++++++++++++++++++ challenge-190/polettix/raku/ch-1.raku | 11 ++++++ challenge-190/polettix/raku/ch-2.raku | 39 ++++++++++++++++++ 6 files changed, 137 insertions(+) create mode 100644 challenge-190/polettix/blog.txt create mode 100644 challenge-190/polettix/blog1.txt create mode 100644 challenge-190/polettix/perl/ch-1.pl create mode 100644 challenge-190/polettix/perl/ch-2.pl create mode 100644 challenge-190/polettix/raku/ch-1.raku create mode 100644 challenge-190/polettix/raku/ch-2.raku (limited to 'challenge-190') diff --git a/challenge-190/polettix/blog.txt b/challenge-190/polettix/blog.txt new file mode 100644 index 0000000000..8072af5931 --- /dev/null +++ b/challenge-190/polettix/blog.txt @@ -0,0 +1 @@ +https://etoobusy.polettix.it/2022/11/10/pwc190-capital-detection/ diff --git a/challenge-190/polettix/blog1.txt b/challenge-190/polettix/blog1.txt new file mode 100644 index 0000000000..671f6953b0 --- /dev/null +++ b/challenge-190/polettix/blog1.txt @@ -0,0 +1 @@ +https://etoobusy.polettix.it/2022/11/11/pwc190-decoded-list/ diff --git a/challenge-190/polettix/perl/ch-1.pl b/challenge-190/polettix/perl/ch-1.pl new file mode 100644 index 0000000000..417611dec7 --- /dev/null +++ b/challenge-190/polettix/perl/ch-1.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl +use v5.24; +use warnings; +use experimental 'signatures'; +no warnings 'experimental::signatures'; + +say capital_detection(shift // 'whatever'); + +sub capital_detection ($string) { + 0 + $string =~ m{\A(?:[a-z]*|[a-zA-Z][a-z]*|[A-Z]*)\z}mxs; +} diff --git a/challenge-190/polettix/perl/ch-2.pl b/challenge-190/polettix/perl/ch-2.pl new file mode 100644 index 0000000000..8a4e72e28d --- /dev/null +++ b/challenge-190/polettix/perl/ch-2.pl @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +use v5.24; +use warnings; +use experimental 'signatures'; +no warnings 'experimental::signatures'; + +# finds all ways of getting items close or separated. Each run of the +# iterator provides an array reference with a grouping. +my $groups_it = all_consecutive_groupings_iterator(shift // '1115'); + +# filters and transforms groupings into a target string. Each run of the +# iterator provides back a valid target decoded string. +my $dl_it = decoded_list_iterator($groups_it); + +# expands an iterator in an array reference with all items +my $decoded_list = iterator_to_arrayref($dl_it); + +# print it out +say join ', ', $decoded_list->@*; + +sub iterator_to_arrayref ($it) { + my @retval; + while (my @stuff = $it->()) { push @retval, @stuff } + return \@retval; +} + +sub decoded_list_iterator ($groups_it) { + state $letter_at = [undef, 'A' .. 'Z']; # starting at 1 + return sub { + ARRANGEMENT: + while (my $arrangement = $groups_it->()) { + my @candidate = map { + next ARRANGEMENT if m{\A 0 }mxs; # nothing starting with 0 + next ARRANGEMENT if $_ > $letter_at->$#*; + $letter_at->[$_]; + } $arrangement->@*; + return join '', @candidate; + } + return; + } +} + +sub all_consecutive_groupings_iterator ($string) { + my @items = split m{}mxs, $string; + my $n = 2 ** $#items; + return sub { + return if --$n < 0; + my $code = sprintf '%b', $n; # decide which gets tied and which not + + # turn into spaces or empty strings (ties) + my @code = map { $_ ? ' ' : '' } split m{}mxs, $code; + unshift @code, '' while @code < $#items; + + # well... this can be enhanced a bit!!! + return [ split m{\s+}mxs, join '', zip_loose(\@items, \@code)->@* ]; + }; +} + +# merge two lists together, until *both* have been used completely +sub zip_loose ($As, $Bs) { + my ($Ai, $Bi) = (0, 0); + my @retval; + while ('necessary') { + my $Aok = ($Ai <= $As->$#*) ? 1 : 0; + my $Bok = ($Bi <= $Bs->$#*) ? 1 : 0; + last unless $Aok || $Bok; + my @chunk = ( + ($Aok ? $As->[$Ai++] : ()), + ($Bok ? $Bs->[$Bi++] : ()), + ); + push @retval, @chunk; + } + return \@retval; +} diff --git a/challenge-190/polettix/raku/ch-1.raku b/challenge-190/polettix/raku/ch-1.raku new file mode 100644 index 0000000000..828088d45c --- /dev/null +++ b/challenge-190/polettix/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku +use v6; +sub MAIN ($s) { put capital-detection($s) } + +sub capital-detection ($string) { + ($string ~~ / + ^<[a..z]>*$ # lc + | ^<[a..z A..Z]><[a..z]>*$ # ucfirst + | ^<[A..Z]>*$/ # uc + ) ?? 1 !! 0; +} diff --git a/challenge-190/polettix/raku/ch-2.raku b/challenge-190/polettix/raku/ch-2.raku new file mode 100644 index 0000000000..d71141b599 --- /dev/null +++ b/challenge-190/polettix/raku/ch-2.raku @@ -0,0 +1,39 @@ +#!/usr/bin/env raku +use v6; +sub MAIN ($input = '1115') { decoded-list($input).join(', ').put } + +sub decoded-list ($encoded) { + my @atoms = $encoded.comb; + my $first = @atoms.shift; + my $n = 2 ** @atoms; + return gather while --$n >= 0 { + my @code = '%b'.sprintf($n).comb; + @code.unshift(0) while @code < @atoms; + @code.push(1); # final separator to close stuff + my @sequence; + my $current = $first; + for ^@code -> $i { + if @code[$i].Int > 0 { # separate, close and reopen if applicable + my $decoded = decode-item($current) or last; + @sequence.push: $decoded; + if $i <= @atoms.end { + $current = @atoms[$i]; + } + else { + take @sequence.join(''); + last; + } + } + else { # merge with previous + $current ~= @atoms[$i]; + } + } + }; +} + +sub decode-item ($item) { + state @letter-at = (Nil, 'A' .. 'Z').flat; + return if $item ~~ /^ 0/; # we consider this invalid + return if $item.Int > @letter-at.end; + return @letter-at[$item.Int]; +} -- cgit From d9fed1f448ed726c4dc25b3471a4ebd30b791dc9 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Thu, 10 Nov 2022 19:56:11 +0000 Subject: - Added more guest contribution by Ulrich Rieke. --- challenge-190/ulrich-rieke/cpp/ch-2.cpp | 86 +++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 challenge-190/ulrich-rieke/cpp/ch-2.cpp (limited to 'challenge-190') diff --git a/challenge-190/ulrich-rieke/cpp/ch-2.cpp b/challenge-190/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..16b1055105 --- /dev/null +++ b/challenge-190/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +//find all combinations of 1 and 2 that add up to the given length +std::vector> findAllCombinations( int len ) { + std::vector> allCombinations ; + std::vector currentCombi ; + std::vector> thePermus ; + for ( int twos = 0 ; twos < len / 2 + 1 ; twos++ ) { + int ones = len - twos * 2 ; + for ( int i = 0 ; i < ones ; i++ ) { + currentCombi.push_back( 1 ) ; + } + for ( int i = 0 ; i < twos ; i++ ) { + currentCombi.push_back( 2 ) ; + } + allCombinations.push_back( currentCombi ) ; + currentCombi.clear( ) ; + } + //permute the combinations that contain both 1 and 2 + for ( auto combi : allCombinations ) { + if ( std::find( combi.begin( ) , combi.end( ) , 1 ) != combi.end( ) + && ( std::find( combi.begin( ) , combi.end( ) , 2 ) != + combi.end( ))) { + std::vector aCombi { combi } ; + while (std::next_permutation( aCombi.begin( ) , aCombi.end( ) )) { + thePermus.push_back( aCombi ) ; + } + } + } + //push the permutations to the existing combinations + for ( auto combi : thePermus ) { + allCombinations.push_back( combi ) ; + } + return allCombinations ; +} + +//take the given number string apart according to the combination of +//1's an 2's +std::vector findNumbers( const std::string & st , const + std::vector & nums ) { + std::vector numbers ; + int pos = 0 ; + for ( int i : nums ) { + numbers.push_back( std::stoi( st.substr( pos , i ))) ; + pos += i ; + } + return numbers ; +} + +//transform every number into a letter +std::string createWord( const std::vector & numbers ) { + std::string word ; + if ( std::any_of( numbers.begin( ) , numbers.end( ) , []( int i ) { + return i > 26 ; })) { + return "" ; + } + else { + for ( int n : numbers ) { + word += static_cast( n + 64 ) ; + } + return word ; + } +} + +int main( ) { + std::cout << "Please enter a string consisting only of digits!\n" ; + std::string line ; + std::cin >> line ; + std::vector allWords ; + std::vector> allCombinations ( findAllCombinations( + line.length( ))) ; + for ( auto & comb : allCombinations ) { + std::string word ( createWord( findNumbers( line , comb ))) ; + if ( word.length( ) > 0 ) + allWords.push_back( word ) ; + } + std::sort( allWords.begin( ) , allWords.end( ) ) ; + for ( const auto & w : allWords ) { + std::cout << w << ' ' ; + } + std::cout << std::endl ; + return 0 ; +} -- cgit From d593f2d4b92fb1111b08d747dbdd5f3d2990174b Mon Sep 17 00:00:00 2001 From: drbaggy Date: Fri, 11 Nov 2022 07:16:49 +0000 Subject: new pointer --- challenge-190/jame