From d8ae12d13bdb74b6f9ce88dd3c8732dfe3984e18 Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Wed, 24 Apr 2024 01:10:11 -0400 Subject: Challenge 266 solutions by Packy Anderson * Raku that looks like Perl * Perl * Python that looks like Perl 1 Blog post --- challenge-266/packy-anderson/README.md | 2 +- challenge-266/packy-anderson/blog.txt | 1 + challenge-266/packy-anderson/perl/ch-1.pl | 32 ++++++++++ challenge-266/packy-anderson/perl/ch-2.pl | 93 +++++++++++++++++++++++++++++ challenge-266/packy-anderson/python/ch-1.py | 32 ++++++++++ challenge-266/packy-anderson/python/ch-2.py | 85 ++++++++++++++++++++++++++ challenge-266/packy-anderson/raku/ch-1.raku | 32 ++++++++++ challenge-266/packy-anderson/raku/ch-2.raku | 92 ++++++++++++++++++++++++++++ 8 files changed, 368 insertions(+), 1 deletion(-) create mode 100644 challenge-266/packy-anderson/blog.txt create mode 100755 challenge-266/packy-anderson/perl/ch-1.pl create mode 100755 challenge-266/packy-anderson/perl/ch-2.pl create mode 100755 challenge-266/packy-anderson/python/ch-1.py create mode 100755 challenge-266/packy-anderson/python/ch-2.py create mode 100755 challenge-266/packy-anderson/raku/ch-1.raku create mode 100755 challenge-266/packy-anderson/raku/ch-2.raku diff --git a/challenge-266/packy-anderson/README.md b/challenge-266/packy-anderson/README.md index 784366b854..3f4d321553 100644 --- a/challenge-266/packy-anderson/README.md +++ b/challenge-266/packy-anderson/README.md @@ -16,4 +16,4 @@ ## Blog Post -[Completing a Third of an Appearance](https://packy.dardan.com/b/KV) +[A Matrix of Uncommon X Words](https://packy.dardan.com/b/KX) diff --git a/challenge-266/packy-anderson/blog.txt b/challenge-266/packy-anderson/blog.txt new file mode 100644 index 0000000000..c77f728725 --- /dev/null +++ b/challenge-266/packy-anderson/blog.txt @@ -0,0 +1 @@ +https://packy.dardan.com/b/KX \ No newline at end of file diff --git a/challenge-266/packy-anderson/perl/ch-1.pl b/challenge-266/packy-anderson/perl/ch-1.pl new file mode 100755 index 0000000000..e3b3995bc1 --- /dev/null +++ b/challenge-266/packy-anderson/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +use v5.38; + +sub occursOnce($line) { + # create a hash counting the words + my %all; + $all{$_}++ for split(/\s+/, $line); + # create a list of words that occur once in the hash + return grep { $all{$_} == 1 } keys %all; +} + +sub uncommonWords($line1, $line2) { + return occursOnce( + join(' ', occursOnce($line1), occursOnce($line2)) + ); +} + +sub solution($line1, $line2) { + say "Input: \$line1 = '$line1'"; + say " \$line2 = '$line2'"; + my @results = uncommonWords($line1, $line2); + say "Output: ('" . join("', '",@results) . "')"; +} + +say "Example 1:"; +solution('Mango is sweet', 'Mango is sour'); + +say "\nExample 2:"; +solution('Mango Mango', 'Orange'); + +say "\nExample 3:"; +solution('Mango is Mango', 'Orange is Orange'); \ No newline at end of file diff --git a/challenge-266/packy-anderson/perl/ch-2.pl b/challenge-266/packy-anderson/perl/ch-2.pl new file mode 100755 index 0000000000..475e95ac9a --- /dev/null +++ b/challenge-266/packy-anderson/perl/ch-2.pl @@ -0,0 +1,93 @@ +#!/usr/bin/env perl +use v5.38; + +sub isDiagonal($x, $y, $N) { + return ( + $N == 1 || $N == 2 || $x == $y || $x + $y == $N - 1 + ); +} + +sub isXMatrix(@matrix) { + my $N = scalar @matrix; + foreach my $y ( 0 .. $#matrix ) { + my @row = @{$matrix[$y]}; + foreach my $x ( 0 .. $#row ) { + my $value = $row[$x]; + # fail if diagonal values are zero or + # non-diagonal values are non-zero + return 0 + unless isDiagonal($x, $y, $N) == ($value != 0); + } + } + return 1; +} + +sub formatMatrix($matrix, $indent=17) { + my @output; + foreach my $row (@$matrix) { + my $output_row = q{ } x $indent . " ["; + $output_row .= join(', ', map { sprintf "%1d", $_ } @$row) . ']'; + push @output, $output_row; + } + return "[\n" + . join(",\n", @output) + . "\n" + . q{ } x $indent . "]"; +} + +sub solution(@matrix) { + say 'Input: $matrix = ' . formatMatrix(\@matrix); + say 'Output: ' . (isXMatrix(@matrix) ? 'True' : 'False'); +} + +say "Example 1:"; +solution( + [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 0], + [7, 0, 0, 1], +); + +say "\nExample 2:"; +solution( + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +); + +say "\nExample 3:"; +solution( + [1, 0, 2], + [0, 3, 0], + [4, 0, 5], +); + +say "\nExample 4:"; +solution( + [1, 0, 0, 0, 1], + [0, 1, 0, 1, 0], + [0, 0, 1, 0, 0], + [0, 1, 0, 1, 0], + [1, 0, 0, 0, 1], +); + +say "\nExample 5:"; +solution( + [1, 0, 1, 0, 1], + [0, 1, 0, 1, 0], + [0, 0, 1, 0, 0], + [0, 1, 0, 1, 0], + [1, 0, 0, 0, 1], +); + +say "\nExample 6:"; +solution( + [1, 1], + [1, 1], +); + +say "\nExample 7:"; +solution( + [1, 0], + [1, 1], +); diff --git a/challenge-266/packy-anderson/python/ch-1.py b/challenge-266/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..017d8a6c12 --- /dev/null +++ b/challenge-266/packy-anderson/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +from collections import Counter + +def occursOnce(line): + # create a Counter of all words + all = Counter(line.split()) + # create a list of words that occur once in the Counter + return [ word for word in list(all) if all[word] == 1 ] + +def uncommonWords(line1, line2): + return occursOnce( + ' '.join(occursOnce(line1) + occursOnce(line2)) + ) + +def quoted_comma_join(arr): + return "'" + "', '".join(arr) + "'" + +def solution(line1, line2): + print(f"Input: $line1 = '{line1}'") + print(f" $line2 = '{line2}'") + uncommon = uncommonWords(line1, line2) + print(f'Output: ({quoted_comma_join(uncommon)})') + +print('Example 1:') +solution('Mango is sweet', 'Mango is sour') + +print('\nExample 2:') +solution('Mango Mango', 'Orange') + +print('\nExample 3:') +solution('Mango is Mango', 'Orange is Orange') \ No newline at end of file diff --git a/challenge-266/packy-anderson/python/ch-2.py b/challenge-266/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..0cefeed570 --- /dev/null +++ b/challenge-266/packy-anderson/python/ch-2.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +def isDiagonal(x, y, N): + return ( + N == 1 or N == 2 or x == y or x + y == N - 1 + ) + +def isXMatrix(matrix): + N = len(matrix) + for y, row in enumerate(matrix): + for x, value in enumerate(row): + # fail if diagonal values are zero or + # non-diagonal values are non-zero + if isDiagonal(x, y, N) != (value != 0): + return False + return True + +def formatMatrix(matrix, indent=17): + output = [] + for row in matrix: + output_row = ' ' * indent + ' [' + output_row += ', '.join(map(lambda i: str(i), row)) + output_row += ']' + output.append(output_row) + + return( + "[\n" + ",\n".join(output) + "\n" + + ' ' * indent + ']' + ) + +def solution(matrix): + print(f'Input: $matrix = {formatMatrix(matrix)}') + print(f'Output: {isXMatrix(matrix)}') + +print('Example 1:') +solution([ + [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 0], + [7, 0, 0, 1], +]) + +print('\nExample 2:') +solution([ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +]) + +print('\nExample 3:') +solution([ + [1, 0, 2], + [0, 3, 0], + [4, 0, 5], +]) + +print('\nExample 4:') +solution([ + [1, 0, 0, 0, 1], + [0, 1, 0, 1, 0], + [0, 0, 1, 0, 0], + [0, 1, 0, 1, 0], + [1, 0, 0, 0, 1], +]) + +print('\nExample 5:') +solution([ + [1, 0, 1, 0, 1], + [0, 1, 0, 1, 0], + [0, 0, 1, 0, 0], + [0, 1, 0, 1, 0], + [1, 0, 0, 0, 1], +]) + +print('\nExample 6:') +solution([ + [1, 1], + [1, 1] +]) + +print('\nExample 7:') +solution([ + [1, 0], + [1, 1] +]) diff --git a/challenge-266/packy-anderson/raku/ch-1.raku b/challenge-266/packy-anderson/raku/ch-1.raku new file mode 100755 index 0000000000..7397776d40 --- /dev/null +++ b/challenge-266/packy-anderson/raku/ch-1.raku @@ -0,0 +1,32 @@ +#!/usr/bin/env raku +use v6; + +sub occursOnce($line) { + # create a Bag of all words + my $all = $line.comb(/\w+/).Bag; + # create a list of words that occur once in the Bag + return $all.keys.grep({ $all{$_} == 1 }); +} + +sub uncommonWords($line1, $line2) { + # create a Bag of words that occur once in each line + my $all = occursOnce($line1).Bag ⊎ occursOnce($line2).Bag; + # return a list of words that occur once in that Bag + return $all.keys.grep({ $all{$_} == 1 }); +} + +sub solution($line1, $line2) { + say "Input: \$line1 = '$line1'"; + say " \$line2 = '$line2'"; + my @results = uncommonWords($line1, $line2); + say "Output: ('" ~ @results.join("', '") ~ "')"; +} + +say "Example 1:"; +solution('Mango is sweet', 'Mango is sour'); + +say "\nExample 2:"; +solution('Mango Mango', 'Orange'); + +say "\nExample 3:"; +solution('Mango is Mango', 'Orange is Orange'); \ No newline at end of file diff --git a/challenge-266/packy-anderson/raku/ch-2.raku b/challenge-266/packy-anderson/raku/ch-2.raku new file mode 100755 index 0000000000..de907e8602 --- /dev/null +++ b/challenge-266/packy-anderson/raku/ch-2.raku @@ -0,0 +1,92 @@ +#!/usr/bin/env raku +use v6; + +sub isDiagonal($x, $y, $N) { + return ( + $N == 1 || $N == 2 || $x == $y || $x + $y == $N - 1 + ); +} + +sub isXMatrix(@matrix) { + my $N = @matrix.elems; + for @matrix.kv -> $y, @row { + for @row.kv -> $x, $value { + # fail if diagonal values are zero or + # non-diagonal values are non-zero + return False + unless isDiagonal($x, $y, $N) == ($value != 0); + } + } + return True; +} + +sub formatMatrix(@matrix, $indent=17) { + my @output; + for @matrix -> @row { + my $output_row = q{ } x $indent ~ " ["; + $output_row ~= @row.map({ sprintf "%1d", $_ }) + .join(', ') ~ "]"; + @output.push($output_row); + } + return "[\n" + ~ @output.join(",\n") + ~ "\n" + ~ q{ } x $indent ~ "]"; +} + +sub solution(@matrix) { + say 'Input: $matrix = ' ~ formatMatrix(@matrix); + say 'Output: ' ~ isXMatrix(@matrix); +} + +say "Example 1:"; +solution([ + [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 0], + [7, 0, 0, 1], +]); + +say "\nExample 2:"; +solution([ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +]); + +say "\nExample 3:"; +solution([ + [1, 0, 2], + [0, 3, 0], + [4, 0, 5], +]); + +say "\nExample 4:"; +solution([ + [1, 0, 0, 0, 1], + [0, 1, 0, 1, 0], + [0, 0, 1, 0, 0], + [0, 1, 0, 1, 0], + [1, 0, 0, 0, 1], +]); + +say "\nExample 5:"; +solution([ + [1, 0, 1, 0, 1], + [0, 1, 0, 1, 0], + [0, 0, 1, 0, 0], + [0, 1, 0, 1, 0], + [1, 0, 0, 0, 1], +]); + +say "\nExample 6:"; +solution([ + [1, 1], + [1, 1], +]); + +say "\nExample 7:"; +solution([ + [1, 0], + [1, 1], +]); -- cgit From 05b3dc1c0f81ab61ae1f4f1032af69509b312aac Mon Sep 17 00:00:00 2001 From: Packy Anderson Date: Tue, 30 Apr 2024 00:42:46 -0400 Subject: Challenge 267 solutions by Packy Anderson * Raku that maybe looks like Raku * Perl * Python that definitely looks like Perl 1 Blog post --- challenge-267/packy-anderson/README.md | 19 +++++++++++ challenge-267/packy-anderson/blog.txt | 1 + challenge-267/packy-anderson/perl/ch-1.pl | 34 +++++++++++++++++++ challenge-267/packy-anderson/perl/ch-2.pl | 52 +++++++++++++++++++++++++++++ challenge-267/packy-anderson/python/ch-1.py | 33 ++++++++++++++++++ challenge-267/packy-anderson/python/ch-2.py | 48 ++++++++++++++++++++++++++ challenge-267/packy-anderson/raku/ch-1.raku | 32 ++++++++++++++++++ challenge-267/packy-anderson/raku/ch-2.raku | 50 +++++++++++++++++++++++++++ 8 files changed, 269 insertions(+) create mode 100644 challenge-267/packy-anderson/README.md create mode 100644 challenge-267/packy-anderson/blog.txt create mode 100755 challenge-267/packy-anderson/perl/ch-1.pl create mode 100755 challenge-267/packy-anderson/perl/ch-2.pl create mode 100755 challenge-267/packy-anderson/python/ch-1.py create mode 100755 challenge-267/packy-anderson/python/ch-2.py create mode 100755 challenge-267/packy-anderson/raku/ch-1.raku create mode 100755 challenge-267/packy-anderson/raku/ch-2.raku diff --git a/challenge-267/packy-anderson/README.md b/challenge-267/packy-anderson/README.md new file mode 100644 index 0000000000..3c4bbfa52c --- /dev/null +++ b/challenge-267/packy-anderson/README.md @@ -0,0 +1,19 @@ +# Solutions by Packy Anderson + +## Raku + +* [Task 1](raku/ch-1.raku) +* [Task 2](raku/ch-2.raku) + +## Perl + +* [Task 1](perl/ch-1.pl) +* [Task 2](perl/ch-2.pl) + +## Guest Language: Python +* [Task 1](python/ch-1.py) +* [Task 2](python/ch-2.py) + +## Blog Post + +[It’s the Product Line Sign that Counts](https://packy.dardan.com/b/Ko) diff --git a/challenge-267/packy-anderson/blog.txt b/challenge-267/packy-anderson/blog.txt new file mode 100644 index 0000000000..929da738b5 --- /dev/null +++ b/challenge-267/packy-anderson/blog.txt @@ -0,0 +1 @@ +https://packy.dardan.com/b/Ko \ No newline at end of file diff --git a/challenge-267/packy-anderson/perl/ch-1.pl b/challenge-267/packy-anderson/perl/ch-1.pl new file mode 100755 index 0000000000..e1a4b15eba --- /dev/null +++ b/challenge-267/packy-anderson/perl/ch-1.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +use v5.38; + +use List::Util qw( reduce ); + +sub productSign(@ints) { + my $product = reduce { $a * $b } @ints; + my $sign = $product == 0 ? 0 + : $product/abs($product); + my $explain = 'The product ' . join(' × ', @ints) + . " => $product"; + if ($sign < 0) { + $explain .= " < 0"; + } + elsif ($sign > 0) { + $explain .= " > 0"; + } + return ($sign, $explain); +} + +sub solution($ints) { + say 'Input: @ints = (' . join(', ', @$ints) . ')'; + my ($sign, $explain) = productSign(@$ints); + say "Output: $sign\n$explain"; +} + +say "Example 1:"; +solution([-1, -2, -3, -4, 3, 2, 1]); + +say "\nExample 2:"; +solution([1, 2, 0, -2, -1]); + +say "\nExample 3:"; +solution([-1, -1, 1, -1, 2]); \ No newline at end of file diff --git a/challenge-267/packy-anderson/perl/ch-2.pl b/challenge-267/packy-anderson/perl/ch-2.pl new file mode 100755 index 0000000000..66d8e74c1b --- /dev/null +++ b/challenge-267/packy-anderson/perl/ch-2.pl @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +use v5.38; + +use List::Util qw( mesh ); + +sub lineCounts($str, @widths) { + my ($lines, $last_line, $last_width, $explain) = + (0, '', 0, ''); + my %width = mesh ['a' .. 'z'], \@widths; + foreach my $c ( split //, $str ) { + if ($last_width + $width{$c} > 100) { + $lines++; + $explain .= "\nLine $lines: $last_line " + . "($last_width pixels)"; + ($last_line, $last_width) = ($c, $width{$c}); + } + else { + $last_line .= $c; + $last_width += $width{$c}; + } + } + $lines++; + $explain .= "\nLine $lines: $last_line " + . "($last_width pixels)"; + return ($lines, $last_width, $explain); +} + +sub solution($str, $widths) { + say qq{Input: \$str = "$str"}; + say qq{ \@widths = (} . join(', ', @$widths) . ')'; + my ($lines, $last_width, $explain) = + lineCounts($str, @$widths); + say qq{Output: ($lines, $last_width)$explain}; +} + +say "Example 1:"; +solution( + "abcdefghijklmnopqrstuvwxyz", + [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10] +); + +say "\nExample 2:"; +solution( + "bbbcccdddaaa", + [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10] +); + +say "\nExample 3:"; +solution( + "thequickbrownfoxjumpedoverthelazydog", + [7,8,7,8,7,5,8,8,4,4,8,4,12,8,8,8,8,5,6,4,8,8,12,8,8,7] +); \ No newline at end of file diff --git a/challenge-267/packy-anderson/python/ch-1.py b/challenge-267/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..034e7ce8fd --- /dev/null +++ b/challenge-267/packy-anderson/python/ch-1.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +from functools import reduce + +def productSign(ints): + product = reduce(lambda a, b: a * b, ints) + sign = 0 if product == 0 else int(product / abs(product)) + + explain = ( + 'The product ' + ' × '.join(map(lambda i: str(i), ints)) + + ' => ' + str(product) + ) + if (sign < 0): explain += " < 0" + if (sign > 0): explain += " > 0" + + return (sign, explain) + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def solution(ints): + print(f'Input: @arr = ({comma_join(ints)})') + sign, explain = productSign(ints) + print(f'Output: {sign}\n{explain}') + +print('Example 1:') +solution([-1, -2, -3, -4, 3, 2, 1]) + +print('\nExample 2:') +solution([1, 2, 0, -2, -1]) + +print('\nExample 3:') +solution([-1, -1, 1, -1, 2]) \ No newline at end of file diff --git a/challenge-267/packy-anderson/python/ch-2.py b/challenge-267/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..72c6903c31 --- /dev/null +++ b/challenge-267/packy-anderson/python/ch-2.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +def lineCounts(strvar, widths): + (lines, last_line, last_width, explain) = (0, '', 0, '') + # we can't do a range of characters, but we can do a range + # of the ASCII values of the characters + letters = [ chr(c) for c in range(ord('a'), ord('z')+1) ] + width = dict( zip(letters, widths) ) + for c in strvar: + if last_width + width[c] > 100: + lines += 1 + explain += f"\nLine {lines}: {last_line} " + explain += f"({last_width} pixels)" + (last_line, last_width) = (c, width[c]) + else: + last_line += c + last_width += width[c] + lines += 1 + explain += f"\nLine {lines}: {last_line} " + explain += f"({last_width} pixels)" + return (lines, last_width, explain) + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def solution(strvar, widths): + print(f'Input: $str = "{strvar}"') + print(f' @widths = ({comma_join(widths)})') + (lines, last_width, explain) = lineCounts(strvar, widths) + print(f'Output: ({lines}, {last_width}){explain}') + +print('Example 1:') +solution( + "abcdefghijklmnopqrstuvwxyz", + [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10] +) + +print('\nExample 2:') +solution( + "bbbcccdddaaa", + [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10] +) + +print('\nExample 3:') +solution( + "thequickbrownfoxjumpedoverthelazydog", + [7,8,7,8,7,5,8,8,4,4,8,4,12,8,8,8,8,5,6,4,8,8,12,8,8,7] +) \ No newline at end of file diff --git a/challenge-267/packy-anderson/raku/ch-1.raku b/challenge-267/packy-anderson/raku/ch-1.raku new file mode 100755 index 0000000000..d03830a9ab --- /dev/null +++ b/challenge-267/packy-anderson/raku/ch-1.raku @@ -0,0 +1,32 @@ +#!/usr/bin/env raku +use v6; + +sub productSign(@ints) { + my $product = [*] @ints; + my $sign = $product == 0 ?? 0 + !! $product/abs($product); + my $explain = 'The product ' ~ @ints.join(' × ') + ~ " => $product"; + if ($sign < 0) { + $explain ~= " < 0"; + } + elsif ($sign > 0) { + $explain ~= " > 0"; + } + return ($sign, $explain); +} + +sub solution(@ints) { + say 'Input: @arr = (' ~ @ints.join(', ') ~ ')'; + my ($sign, $explain) = productSign(@ints); + say "Output: $sign\n$explain"; +} + +say "Example 1:"; +solution([-1, -2, -3, -4, 3, 2, 1]); + +say "\nExample 2:"; +solution([1, 2, 0, -2, -1]); + +say "\nExample 3:"; +solution([-1, -1, 1, -1, 2]); \ No newline at end of file diff --git a/challenge-267/packy-anderson/raku/ch-2.raku b/challenge-267/packy-anderson/raku/ch-2.raku new file mode 100755 index 0000000000..cd543421cc --- /dev/null +++ b/challenge-267/packy-anderson/raku/ch-2.raku @@ -0,0 +1,50 @@ +#!/usr/bin/env raku +use v6; + +sub lineCounts($str, @widths) { + my ($lines, $last_line, $last_width, $explain) = + (0, '', 0, ''); + my %width = ('a' .. 'z' Z @widths).flat.Hash; + for $str.comb -> $c { + if ($last_width + %width{$c} > 100) { + $lines++; + $explain ~= "\nLine $lines: $last_line " + ~ "($last_width pixels)"; + ($last_line, $last_width) = ($c, %width{$c}); + } + else { + $last_line ~= $c; + $last_width += %width{$c}; + } + } + $lines++; + $explain ~= "\nLine $lines: $last_line " + ~ "($last_width pixels)"; + return ($lines, $last_width, $explain); +} + +sub solution($str, @widths) { + say qq{Input: \$str = "$str"}; + say qq{ \@widths = (} ~ @widths.join(', ') ~ ')'; + my ($lines, $last_width, $explain) = + lineCounts($str, @widths); + say qq{Output: ($lines, $last_width)$explain}; +} + +say "Example 1:"; +solution( + "abcdefghijklmnopqrstuvwxyz", + [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10] +); + +say "\nExample 2:"; +solution( + "bbbcccdddaaa", + [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10] +); + +say "\nExample 3:"; +solution( + "thequickbrownfoxjumpedoverthelazydog", + [7,8,7,8,7,5,8,8,4,4,8,4,12,8,8,8,8,5,6,4,8,8,12,8,8,7] +); \ No newline at end of file -- cgit