diff options
| author | andrezgz <andrezgz@gmail.com> | 2019-11-05 18:36:31 -0300 |
|---|---|---|
| committer | andrezgz <andrezgz@gmail.com> | 2019-11-05 18:36:31 -0300 |
| commit | 8e03d167d311a83d610693d1ddb2d3c02025212e (patch) | |
| tree | c0554f88289c481373ab60b17aaad41e176e44e8 | |
| parent | 97582c23d3570df49f9d86f3a9bd6e53e72ae5ea (diff) | |
| parent | 45dce1b2facdf04e982d0fd265a1c7e6db3247ad (diff) | |
| download | perlweeklychallenge-club-8e03d167d311a83d610693d1ddb2d3c02025212e.tar.gz perlweeklychallenge-club-8e03d167d311a83d610693d1ddb2d3c02025212e.tar.bz2 perlweeklychallenge-club-8e03d167d311a83d610693d1ddb2d3c02025212e.zip | |
Merge remote-tracking branch 'upstream/master'
35 files changed, 1708 insertions, 977 deletions
diff --git a/challenge-033/andrezgz/perl5/ch-1.pl b/challenge-033/andrezgz/perl5/ch-1.pl new file mode 100644 index 0000000000..b883cb69d5 --- /dev/null +++ b/challenge-033/andrezgz/perl5/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-033/ +# Task #1 +# Count Letters (A..Z) +# +# Create a script that accepts one or more files specified on the command-line +# and count the number of times letters appeared in the files. +# +# So with the following input file sample.txt +# The quick brown fox jumps over the lazy dog. +# the script would display something like: +# +# a: 1 +# b: 1 +# c: 1 +# ... +# y: 1 +# z: 1 + +use strict; +use warnings; + +my %times; +while (<>) { + chomp; + my @letters = grep { /[a-z]/i } split //; # retain only letters from each line + $times{lc $_}++ for @letters; # count case-insensitive letter repetition +} + +for ('a' .. 'z') { + print $_,': ', $times{$_} || 0, "\n"; +} diff --git a/challenge-033/andrezgz/perl5/ch-2.pl b/challenge-033/andrezgz/perl5/ch-2.pl new file mode 100644 index 0000000000..a0481b622d --- /dev/null +++ b/challenge-033/andrezgz/perl5/ch-2.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-033/ +# Task #2 +# Formatted Multiplication Table +# +# Write a script to print 11x11 multiplication table, only the top half triangle. +# +# x| 1 2 3 4 5 6 7 8 9 10 11 +# ---+-------------------------------------------- +# 1| 1 2 3 4 5 6 7 8 9 10 11 +# 2| 4 6 8 10 12 14 16 18 20 22 +# 3| 9 12 15 18 21 24 27 30 33 +# 4| 16 20 24 28 32 36 40 44 +# 5| 25 30 35 40 45 50 55 +# 6| 36 42 48 54 60 66 +# 7| 49 56 63 70 77 +# 8| 64 72 80 88 +# 9| 81 90 99 +# 10| 100 110 +# 11| 121 + + +use strict; +use warnings; + +my $max = shift || 11; # multiplication table size +my $width = length($max**2) + 1; # control spacing +my $cell = "%${width}s"; # cell format + +print sprintf $cell,$_ for ('x|', 1 .. $max), "\n"; # column headers +print '-' x ($width-1), '+', '-' x ($width*$max), "\n"; # separation line +for my $row (1 .. $max) { # row + printf $cell, $row.'|'; ## row header + for my $col (1 .. $max) { ## column + printf $cell, $col >= $row ? $row * $col : ''; ### cell value + } + print "\n"; +} + +__END__ + +./ch-2.pl + x| 1 2 3 4 5 6 7 8 9 10 11 +---+-------------------------------------------- + 1| 1 2 3 4 5 6 7 8 9 10 11 + 2| 4 6 8 10 12 14 16 18 20 22 + 3| 9 12 15 18 21 24 27 30 33 + 4| 16 20 24 28 32 36 40 44 + 5| 25 30 35 40 45 50 55 + 6| 36 42 48 54 60 66 + 7| 49 56 63 70 77 + 8| 64 72 80 88 + 9| 81 90 99 + 10| 100 110 + 11| 121 + + +./ch-2.pl 32 + x| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 +---+---------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 + 2| 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 + 3| 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 + 4| 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 + 5| 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 + 6| 36 42 48 54 60 66 72 78 84 90 96 102 108 114 120 126 132 138 144 150 156 162 168 174 180 186 192 + 7| 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 + 8| 64 72 80 88 96 104 112 120 128 136 144 152 160 168 176 184 192 200 208 216 224 232 240 248 256 + 9| 81 90 99 108 117 126 135 144 153 162 171 180 189 198 207 216 225 234 243 252 261 270 279 288 + 10| 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 + 11| 121 132 143 154 165 176 187 198 209 220 231 242 253 264 275 286 297 308 319 330 341 352 + 12| 144 156 168 180 192 204 216 228 240 252 264 276 288 300 312 324 336 348 360 372 384 + 13| 169 182 195 208 221 234 247 260 273 286 299 312 325 338 351 364 377 390 403 416 + 14| 196 210 224 238 252 266 280 294 308 322 336 350 364 378 392 406 420 434 448 + 15| 225 240 255 270 285 300 315 330 345 360 375 390 405 420 435 450 465 480 + 16| 256 272 288 304 320 336 352 368 384 400 416 432 448 464 480 496 512 + 17| 289 306 323 340 357 374 391 408 425 442 459 476 493 510 527 544 + 18| 324 342 360 378 396 414 432 450 468 486 504 522 540 558 576 + 19| 361 380 399 418 437 456 475 494 513 532 551 570 589 608 + 20| 400 420 440 460 480 500 520 540 560 580 600 620 640 + 21| 441 462 483 504 525 546 567 588 609 630 651 672 + 22| 484 506 528 550 572 594 616 638 660 682 704 + 23| 529 552 575 598 621 644 667 690 713 736 + 24| 576 600 624 648 672 696 720 744 768 + 25| 625 650 675 700 725 750 775 800 + 26| 676 702 728 754 780 806 832 + 27| 729 756 783 810 837 864 + 28| 784 812 840 868 896 + 29| 841 870 899 928 + 30| 900 930 960 + 31| 961 992 + 32| 1024 diff --git a/challenge-033/dave-cross/perl5/ch-1.pl b/challenge-033/dave-cross/perl5/ch-1.pl new file mode 100644 index 0000000000..5ad6146ce9 --- /dev/null +++ b/challenge-033/dave-cross/perl5/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +my %letters; + +while (<>) { + $_ = lc $_; + tr/a-z//cd; + + $letters{$_}++ for split //; +} + +say "$_: $letters{$_}" for sort keys %letters; diff --git a/challenge-033/dave-cross/perl5/ch-2.pl b/challenge-033/dave-cross/perl5/ch-2.pl new file mode 100644 index 0000000000..15ab4aa136 --- /dev/null +++ b/challenge-033/dave-cross/perl5/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +say ' x|', map { sprintf '%4s', $_ } 1 .. 11; +say '---+', '-' x 44; + +for my $x (1 .. 11) { + printf '%3s|', $x; + for my $y (1 .. 11) { + printf '%4s', ($x > $y ? '' : $x * $y); + } + print "\n"; +} diff --git a/challenge-033/dave-cross/perl5/lazy.txt b/challenge-033/dave-cross/perl5/lazy.txt new file mode 100644 index 0000000000..2fe6575e76 --- /dev/null +++ b/challenge-033/dave-cross/perl5/lazy.txt @@ -0,0 +1 @@ +The quick brown fox jumps over the lazy dog. diff --git a/challenge-033/javier-luque/blog.txt b/challenge-033/javier-luque/blog.txt new file mode 100644 index 0000000000..5532f1354d --- /dev/null +++ b/challenge-033/javier-luque/blog.txt @@ -0,0 +1 @@ +https://perlchallenges.wordpress.com/2019/11/05/perl-weekly-challenge-033/ diff --git a/challenge-033/javier-luque/perl5/ch-1.pl b/challenge-033/javier-luque/perl5/ch-1.pl new file mode 100644 index 0000000000..5e9feb3786 --- /dev/null +++ b/challenge-033/javier-luque/perl5/ch-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +# Test: ./ch1.pl example1.txt example2.txt +use strict; +use warnings; +binmode STDOUT, ':utf8'; +my %counts; + +# Loop through each file +for my $file (@ARGV) { + open my $fh, "<:encoding(UTF-8)", $file or die "$file: $! \n"; + + # Increment count for each word char + while (my $char = getc($fh)) { + $counts{lc($char)}++ if (lc($char) =~ /[\w]/); + } +} + +# Print each char and count +for my $char (sort keys %counts) { + printf("%2s %5i\n", $char, $counts{$char}); +} diff --git a/challenge-033/javier-luque/perl5/ch-2.pl b/challenge-033/javier-luque/perl5/ch-2.pl new file mode 100644 index 0000000000..845213050f --- /dev/null +++ b/challenge-033/javier-luque/perl5/ch-2.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl +# Test: ./ch2.pl +use strict; +use warnings; + +generate_x_table(11); + +# Generates the multiplication table +sub generate_x_table { + my $num = shift; + + for my $i (0..$num) { + my $line = ($i == 0) ? + _table_head($num) : + _table_body($i, $num); + print $line; + } +} + +# Returns the table head string +sub _table_head { + my $num = shift; + my $line = sprintf ("%4s|", 'x'); + + for my $i (1..$num) { + $line .= sprintf("%4i", $i); + } + + return $line . "\n" . '----+' . '----' x $num . "\n"; +} + +# Returns the table row string for $i +sub _table_body { + my ($current, $num) = @_; + my $line = sprintf ("%4i|", $current); + + for my $i (1..$num) { + $line .= ($current <= $i) ? + sprintf("%4i", $i * $current) : ' ' x 4; + } + + $line .= "\n"; + + return $line; +} diff --git a/challenge-033/javier-luque/perl6/ch-1.p6 b/challenge-033/javier-luque/perl6/ch-1.p6 new file mode 100644 index 0000000000..eca4c5fc42 --- /dev/null +++ b/challenge-033/javier-luque/perl6/ch-1.p6 @@ -0,0 +1,21 @@ +# Test: perl6 ch1.p6 example1.txt example2.txt +use v6.d; + +sub MAIN (*@filenames) { + my %counts; + + # Loop through each file + for @filenames -> $filename { + my $fh = $filename.IO.open orelse .die; + + # Increment count for each word char + while (my $char = $fh.getc) { + %counts{$char.lc}++ if ($char.lc ~~ /\w/); + } + } + + # Print each char and count + for %counts.keys.sort -> $item { + "%2s %5i\n".printf($item, %counts{$item}); + } +} diff --git a/challenge-033/javier-luque/perl6/ch-2.p6 b/challenge-033/javier-luque/perl6/ch-2.p6 new file mode 100644 index 0000000000..4ea4b715b5 --- /dev/null +++ b/challenge-033/javier-luque/perl6/ch-2.p6 @@ -0,0 +1,30 @@ +# Test: perl6 ch2.p6 +use v6.d; + +sub MAIN () { + generate-x-table(11); +} + +# Generates the multiplication table +sub generate-x-table (Int $num) { + table-content($_, $num).say for (0..$num); +} + +# Returns the table head string +multi table-content(Int $current where { $current == 0}, Int $num) { + my $line = "%4s|".sprintf("x"); + $line ~= "%4i".sprintf($_) for (1..$num); + return $line ~ "\n" ~ '----+' ~ '----' x $num; +} + +# Returns the table row string for $i +multi table-content(Int $current, Int $num) { + my $line = "%4i|".sprintf($current); + + for (1..$num) -> $i { + $line ~= ($current <= $i) ?? + "%4i".sprintf($i * $current) !! ' ' x 4; + } + + return $line; +} diff --git a/challenge-033/petr-roubicek/README b/challenge-033/petr-roubicek/README new file mode 100644 index 0000000000..c846fe0f55 --- /dev/null +++ b/challenge-033/petr-roubicek/README @@ -0,0 +1 @@ +Solutions by Petr Roubicek. diff --git a/challenge-033/ruben-westerberg/README b/challenge-033/ruben-westerberg/README index 967735670b..042d724fa7 100644 --- a/challenge-033/ruben-westerberg/README +++ b/challenge-033/ruben-westerberg/README @@ -1,16 +1,16 @@ Solution by Ruben Westerberg -Challenge 1 and 2 contained in ch1.pl and ch1.p6 files. -Output is a histogram listing of repeated values. Numeric values and a graph are output -Usage examples: - ch-1_and_2.p6 INPUTFILE - ch-1_and_2.pl INPUT FILE +ch-1.pl and ch-1.p6 +================== +Run the program with either standard input of a list of file paths as command line arguments. +Outpus the count of all letters in the files. - ch-1_and_2.p6 -vsort INPUTFILE - ch-1_and_2.pl -v INPUTFILE --v/-vsort will sort the entries by count value not key value +ch-2.pl and ch-2.p6 +================== +Generates a formated multiplication table. Upper half only. +Defaults to a limit of 11. Use a command line argument to set the limit of the table size. diff --git a/challenge-033/ruben-westerberg/perl5/ch-1.pl b/challenge-033/ruben-westerberg/perl5/ch-1.pl new file mode 100755 index 0000000000..eea6c6738a --- /dev/null +++ b/challenge-033/ruben-westerberg/perl5/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::Util; + +my %letters; +while (<>) { + chomp; + for (split "") { + $letters{$_}++ if /[a-zA-Z]/; + } +} + +my $m=List::Util::max map {length $letters{$_}} keys %letters; +for (sort keys %letters) { + printf "%s: %".$m."s\n", $_, $letters{$_}; +} + diff --git a/challenge-033/ruben-westerberg/perl5/ch-2.pl b/challenge-033/ruben-westerberg/perl5/ch-2.pl new file mode 100755 index 0000000000..dfdef93a30 --- /dev/null +++ b/challenge-033/ruben-westerberg/perl5/ch-2.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +my $limit=$ARGV[0]//11; +my $maxWidth=1+length $limit**2; +printRow("",[1..$limit],$maxWidth); +print "-" x (($limit+2)*$maxWidth),"\n"; +for (1..$limit) { + my $i=$_; + my @row; + my $header=$_; + for (1..$limit) { + if ($_ >= $i) { + push @row, $i * $_; + } + else { + push @row, ""; + } + } + printRow( $header,\@row, $maxWidth); +} + +sub printRow { + my ($header,$data,$minWidth)=@_; + my $output=""; + for (@$data) { + $output.=sprintf "%".$minWidth."s",$_; + } + printf "%".$minWidth."s|%s\n",$header,$output; +} + diff --git a/challenge-033/ruben-westerberg/perl6/ch-1.p6 b/challenge-033/ruben-westerberg/perl6/ch-1.p6 new file mode 100755 index 0000000000..a2685cff85 --- /dev/null +++ b/challenge-033/ruben-westerberg/perl6/ch-1.p6 @@ -0,0 +1,12 @@ +#!/usr/bin/env perl6 +my %letters; +for lines() { + for $_.split("",:skip-empty) { + %letters{$_}++ if /<[a..zA..Z]>/; + } +} + +my $m=max map {chars %letters{$_}}, keys %letters; +for sort keys %letters { + printf "%s: %"~$m~"s\n", $_, %letters{$_}; +} diff --git a/challenge-033/ruben-westerberg/perl6/ch-2.p6 b/challenge-033/ruben-westerberg/perl6/ch-2.p6 new file mode 100755 index 0000000000..223ceb192d --- /dev/null +++ b/challenge-033/ruben-westerberg/perl6/ch-2.p6 @@ -0,0 +1,28 @@ +#!/usr/bin/env perl6 +my $limit=@*ARGS[0]//11; +my $maxWidth=1+(chars $limit**2); +printRow "", (1..$limit), $maxWidth; +put "-" x (($limit+2)*$maxWidth); +for 1..$limit { + my $i=$_; + my @row; + my $header=$_; + for 1..$limit { + if $_ >= $i { + push @row, $i*$_; + } + else { + push @row, ""; + } + } + printRow($header,@row,$maxWidth); +} + +sub printRow($header, $data, $minWidth) { + my $output=""; + for @$data { + $output ~= sprintf "%"~$minWidth~"s",$_; + } + printf "%"~$minWidth~"s|%s\n",$header,$output; +} + diff --git a/challenge-033/steven-wilson/perl5/ch-1.pl b/challenge-033/steven-wilson/perl5/ch-1.pl new file mode 100644 index 0000000000..25f3117ef8 --- /dev/null +++ b/challenge-033/steven-wilson/perl5/ch-1.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +# Author: Steven Wilson +# Date: 2019-11-05 +# Week: 033 + +# Task #1 +# Count Letters (A..Z) +# Create a script that accepts one or more files specified on the command-line and count the number of times letters appeared in the files. +# So with the following input file sample.txt +# The quick brown fox jumps over the lazy dog. +# the script would display something like: +# a: 1 +# b: 1 +# c: 1 +# ... +# x: 1 +# y: 1 +# z: 1 + +use strict; +use warnings; +use feature qw/ say /; + +my @files = @ARGV; +my %letters_count; + +for my $file (@files) { + open my $fh, '<', $file or die "Can't open < $file: $!"; + while ( !eof $fh ) { + my @letters = grep {/[[:alpha:]]/} split //, readline($fh); + for my $letter (@letters) { + $letters_count{ lc $letter } += 1; + } + } + close $fh; +} + +for my $letter ( sort keys %letters_count ) { + say "$letter: $letters_count{$letter}"; +} diff --git a/challenge-033/steven-wilson/perl5/ch-2.pl b/challenge-033/steven-wilson/perl5/ch-2.pl new file mode 100644 index 0000000000..fb32afe704 --- /dev/null +++ b/challenge-033/steven-wilson/perl5/ch-2.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +# Author: Steven Wilson +# Date: 2019-11-05 +# Week: 033 + +# Task #2 +# Formatted Multiplication Table +# Write a script to print 11x11 multiplication table, only the top half triangle. + +# x| 1 2 3 4 5 6 7 8 9 10 11 +# ---+-------------------------------------------- +# 1| 1 2 3 4 5 6 7 8 9 10 11 +# 2| 4 6 8 10 12 14 16 18 20 22 +# 3| 9 12 15 18 21 24 27 30 33 +# 4| 16 20 24 28 32 36 40 44 +# 5| 25 30 35 40 45 50 55 +# 6| 36 42 48 54 60 66 +# 7| 49 56 63 70 77 +# 8| 64 72 80 88 +# 9| 81 90 99 +# 10| 100 110 +# 11| 121 + +use strict; +use warnings; + +printf( " x| %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", 1 .. 11 ); +printf("---+--------------------------------------------\n"); + +for ( 1 .. 11 ) { + my @row = get_row($_); + printf( "%3d|", $_ ); + map { $_ == 0 ? print " " : printf( " %3d", $_ ) } @row; + print "\n"; +} + +sub get_row { + my $row = shift; + my @row = map { $_ < $row ? 0 : $_ * $row } 1 .. 11; +} diff --git a/challenge-033/ulrich-rieke/cpp/ch-1.cpp b/challenge-033/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..563d91befa --- /dev/null +++ b/challenge-033/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,42 @@ +#include <iostream> +#include <map> +#include <cctype> +#include <fstream> +#include <algorithm> +#include <string> + +char myTransformer( char d ) { + if ( std::isupper( d ) ) + return std::tolower( d ) ; + else + return d ; +} + +int main( int argc, char* argv[] ) { + for ( int i = 1 ; i < argc ; i++ ) { + std::string file( argv[ i ] ) ; + std::ifstream infile( file , std::ios::binary | std::ios::in ) ; + if ( infile ) { + std::map<char, int> frequencies ; + while ( infile.good( ) ) { + std::string line ; + std::getline( infile, line ) ; + std::transform( line.begin( ) , line.end( ) , line.begin( ) , + myTransformer ) ; + for ( char c : line ) { + if ( std::isalpha( c ) ) { + frequencies[c]++ ; + } + } + } + infile.close( ) ; + std::cout << "Letter frequency for file " << file << " :\n" ; + for ( auto & p : frequencies ) { + std::cout << p.first << ": " << p.second << std::endl ; + } + } + else { + std::cout << "Can't open file " << file << " !\n" ; + } + } +} diff --git a/challenge-033/ulrich-rieke/cpp/ch-2.cpp b/challenge-033/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..a0949c0b04 --- /dev/null +++ b/challenge-033/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +int main( ) { + std::cout.width( 4 ) ; + std::cout << "x|" ; + for ( int i = 1 ; i < 12 ; i++ ) { + std::cout.width( 4 ) ; + std::cout << i ; + } + std::cout << std::endl ; + for ( int i = 0 ; i < 48 ; i++ ) + std::cout << '-' ; + std::cout << std::endl ; + for ( int i = 1 ; i < 12 ; i++ ) { + std::cout.width( 3 ) ; + std::cout << i << '|' ; + if ( i > 1 ) { + for ( int j = 0 ; j < (i - 1 ) * 4 ; j++ ) { + std::cout << ' ' ; + } + } + for ( int mult = i ; mult < 12 ; mult++ ) { + std::cout.width( 4 ) ; + std::cout << i * mult ; + } + std::cout << std::endl ; + } +} diff --git a/challenge-033/ulrich-rieke/perl5/ch-1.pl b/challenge-033/ulrich-rieke/perl5/ch-1.pl new file mode 100644 index 0000000000..ce2c083f5c --- /dev/null +++ b/challenge-033/ulrich-rieke/perl5/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; + +for my $file ( @ARGV ) { + if ( -e $file && -f $file ) { + my %lettercount ; + open ( FH , "< $file" ) ; + while ( my $line = <FH> ) { + chomp $line ; + my @words = split (/\s+/ , $line ) ; + for my $word ( @words ) { + my $lowerword = lc $word ; + $lowerword =~ s/[^a-z]//g ; + for my $letter ( split (//, $lowerword )) { + $lettercount{ $letter }++ ; + } + } + } + my @sorted = sort {$a cmp $b } keys %lettercount ; + print "letter frequency for file $file:\n" ; + for my $letter ( @sorted ) { + print "$letter: $lettercount{ $letter }\n" ; + } + close FH ; + } + else { + print "Can't open file $file!\n" ; + } +} diff --git a/challenge-033/ulrich-rieke/perl5/ch-2.pl b/challenge-033/ulrich-rieke/perl5/ch-2.pl new file mode 100644 index 0000000000..e7c16c05af --- /dev/null +++ b/challenge-033/ulrich-rieke/perl5/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl ; +use strict ; +use warnings ; + +printf("%4s" , "x|") ; +foreach my $num (1..11) { + printf("%4d", $num) ; +} +print "\n" ; +print "-" x 48 ; +print "\n" ; +for (my $i = 1 ; $i < 12 ; $i++ ) { + printf( "%4s" , "$i|" ) ; + if ( $i > 1 ) { + print " " x ( ($i - 1 ) * 4 ) ; + } + for (my $mult = $i ; $mult < 12 ; $mult++) { + printf( "%4d" , $i * $mult ) ; + } + print "\n" ; +} |
