diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-01-25 20:07:40 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-01-26 00:06:54 +0000 |
| commit | 3fa58628535d4041c7cc648c005080ca88f18c18 (patch) | |
| tree | 336fe3cc14f518f05e871ab974cc86a09a2fd8f6 /challenge-014 | |
| parent | 3d3900a2f0f69c54a34683e4e1b5da007b4af9d9 (diff) | |
| download | perlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.tar.gz perlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.tar.bz2 perlweeklychallenge-club-3fa58628535d4041c7cc648c005080ca88f18c18.zip | |
Replace tabs by spaces so that indentation looks correct
Diffstat (limited to 'challenge-014')
| -rw-r--r-- | challenge-014/paulo-custodio/perl/ch-1.pl | 42 | ||||
| -rw-r--r-- | challenge-014/paulo-custodio/perl/ch-2.pl | 28 | ||||
| -rw-r--r-- | challenge-014/paulo-custodio/test.pl | 8 |
3 files changed, 39 insertions, 39 deletions
diff --git a/challenge-014/paulo-custodio/perl/ch-1.pl b/challenge-014/paulo-custodio/perl/ch-1.pl index ef4247a791..302717d8f3 100644 --- a/challenge-014/paulo-custodio/perl/ch-1.pl +++ b/challenge-014/paulo-custodio/perl/ch-1.pl @@ -4,7 +4,7 @@ # # Challenge #1 # Write a script to generate Van Eck’s sequence starts with 0. For more -# information, please check out wikipedia page. This challenge was proposed by +# information, please check out wikipedia page. This challenge was proposed by # team member Andrezgz. use strict; @@ -12,30 +12,30 @@ use warnings; use 5.030; sub van_eck_iter { - my @hist; - my @init = (0, 0); # first two terms - return sub { - if (@init) { - push @hist, shift @init; - return $hist[-1]; - } - else { - for my $m (reverse 0 .. $#hist-1) { - if ($hist[$m]==$hist[-1]) { - push @hist, $#hist - $m; - return $hist[-1]; - } - } - push @hist, 0; - return $hist[-1]; - } - }; + my @hist; + my @init = (0, 0); # first two terms + return sub { + if (@init) { + push @hist, shift @init; + return $hist[-1]; + } + else { + for my $m (reverse 0 .. $#hist-1) { + if ($hist[$m]==$hist[-1]) { + push @hist, $#hist - $m; + return $hist[-1]; + } + } + push @hist, 0; + return $hist[-1]; + } + }; } my $iter = van_eck_iter(); my $sep = ""; for (0..96) { - print $sep, $iter->(); - $sep = ", "; + print $sep, $iter->(); + $sep = ", "; } print "\n"; diff --git a/challenge-014/paulo-custodio/perl/ch-2.pl b/challenge-014/paulo-custodio/perl/ch-2.pl index f006f9cd09..0586bf1282 100644 --- a/challenge-014/paulo-custodio/perl/ch-2.pl +++ b/challenge-014/paulo-custodio/perl/ch-2.pl @@ -7,7 +7,7 @@ # states, write a script to find the longest English word you can spell? Here # is the list of U.S. states abbreviations as per wikipedia page. This challenge # was proposed by team member Neil Bowers. -# +# # For example, # Pennsylvania + Connecticut = PACT # Wisconsin + North Dakota = WIND @@ -22,26 +22,26 @@ use Locale::US; use Data::Dump 'dump'; my $u = Locale::US->new; -my @codes = $u->all_state_codes; # all states two letter codes -my $codes = join("|", @codes); # regex to match any codes -my $regex = qr/^($codes)+$/i; # regex to match word composed of codes +my @codes = $u->all_state_codes; # all states two letter codes +my $codes = join("|", @codes); # regex to match any codes +my $regex = qr/^($codes)+$/i; # regex to match word composed of codes # find all words that match, save longest ones my @longest; open(my $fh, "<", "words.txt") or die "open words.txt: $!\n"; while (<$fh>) { - chomp; - next unless /$regex/; # filter words that match state codes - if (!@longest || length($_) > length($longest[0])) { - @longest = ($_); - } - elsif (length($_) == length($longest[0])) { - push @longest, $_; - } + chomp; + next unless /$regex/; # filter words that match state codes + if (!@longest || length($_) > length($longest[0])) { + @longest = ($_); + } + elsif (length($_) == length($longest[0])) { + push @longest, $_; + } } # show longest words in form: word = state + state + ... for my $word (@longest) { - my @states = map {$_ = $u->{code2state}{uc($_)}} grep {$_} split /(..)/, $word; - say $word, " = ", join(" + ", @states); + my @states = map {$_ = $u->{code2state}{uc($_)}} grep {$_} split /(..)/, $word; + say $word, " = ", join(" + ", @states); } diff --git a/challenge-014/paulo-custodio/test.pl b/challenge-014/paulo-custodio/test.pl index 4d173dfe89..eb6af874b6 100644 --- a/challenge-014/paulo-custodio/test.pl +++ b/challenge-014/paulo-custodio/test.pl @@ -43,8 +43,8 @@ done_testing; sub capture { - my($cmd) = @_; - my $out = `$cmd`; - $out =~ s/[ \r\t]*\n/\n/g; - return $out; + my($cmd) = @_; + my $out = `$cmd`; + $out =~ s/[ \r\t]*\n/\n/g; + return $out; } |
