From 2ac65e50b1f8c7ee19e2c6e9ce0ffd7d042bb1bd Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Sun, 14 Feb 2021 02:36:14 +0000 Subject: Add Awk solution to challenge 003 --- challenge-001/paulo-custodio/awk/ch-1.awk | 10 ++-- challenge-001/paulo-custodio/test.pl | 1 + challenge-003/paulo-custodio/awk/ch-1.awk | 65 ++++++++++++++++++++++++ challenge-003/paulo-custodio/awk/ch-2.awk | 65 ++++++++++++++++++++++++ challenge-003/paulo-custodio/t/test-1.yaml | 25 ++++++++++ challenge-003/paulo-custodio/t/test-2.yaml | 15 ++++++ challenge-003/paulo-custodio/test.pl | 80 +----------------------------- 7 files changed, 177 insertions(+), 84 deletions(-) create mode 100644 challenge-003/paulo-custodio/awk/ch-1.awk create mode 100644 challenge-003/paulo-custodio/awk/ch-2.awk create mode 100644 challenge-003/paulo-custodio/t/test-1.yaml create mode 100644 challenge-003/paulo-custodio/t/test-2.yaml diff --git a/challenge-001/paulo-custodio/awk/ch-1.awk b/challenge-001/paulo-custodio/awk/ch-1.awk index c954b16d73..da8e38182a 100644 --- a/challenge-001/paulo-custodio/awk/ch-1.awk +++ b/challenge-001/paulo-custodio/awk/ch-1.awk @@ -7,8 +7,7 @@ # ‘Perl Weekly Challenge’. Also print the number of times the character ‘e’ # is found in the string. -function join(array, start, end, sep, result, i) -{ +function join(array, start, end, sep, result, i) { if (sep == "") sep = " " else if (sep == SUBSEP) # magic value @@ -19,9 +18,10 @@ function join(array, start, end, sep, result, i) return result } -function alen(a, i) { - for(i in a); - return i +function alen(a, i, k) { + k = 0 + for(i in a) k++ + return k } BEGIN { diff --git a/challenge-001/paulo-custodio/test.pl b/challenge-001/paulo-custodio/test.pl index 2feb090a1e..41c54fdb5e 100644 --- a/challenge-001/paulo-custodio/test.pl +++ b/challenge-001/paulo-custodio/test.pl @@ -62,6 +62,7 @@ for my $lang (grep {-d} sort keys %LANG) { $cmd .= " < in.txt"; } if (defined($spec->{output})) { + $spec->{output} =~ s/^\|//mg; # delete initial bar path("out_exp.txt")->spew($spec->{output}); $cmd .= " > out.txt"; } diff --git a/challenge-003/paulo-custodio/awk/ch-1.awk b/challenge-003/paulo-custodio/awk/ch-1.awk new file mode 100644 index 0000000000..12c7cea74a --- /dev/null +++ b/challenge-003/paulo-custodio/awk/ch-1.awk @@ -0,0 +1,65 @@ +#!/usr/bin/gawk + +# Challenge 003 +# +# Challenge #1 +# Create a script to generate 5-smooth numbers, whose prime divisors are less +# or equal to 5. They are also called Hamming/Regular/Ugly numbers. For more +# information, please check this wikipedia. + +function min(a, b) { + return (a < <