diff options
| author | Abigail <abigail@abigail.be> | 2021-09-13 19:31:56 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-09-13 19:31:56 +0200 |
| commit | 766d218d02e39554413a8c5658722376b3b58345 (patch) | |
| tree | 2758980c719d445a5483f7b9324a76de0d898889 | |
| parent | 5fe7e8d9b300f39513818f3ef65908de1784926c (diff) | |
| download | perlweeklychallenge-club-766d218d02e39554413a8c5658722376b3b58345.tar.gz perlweeklychallenge-club-766d218d02e39554413a8c5658722376b3b58345.tar.bz2 perlweeklychallenge-club-766d218d02e39554413a8c5658722376b3b58345.zip | |
AWK and Perl solutions for week 130, part 1
| -rw-r--r-- | challenge-130/abigail/awk/ch-1.awk | 21 | ||||
| -rw-r--r-- | challenge-130/abigail/perl/ch-1.pl | 28 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-130/abigail/awk/ch-1.awk b/challenge-130/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..d9673b698b --- /dev/null +++ b/challenge-130/abigail/awk/ch-1.awk @@ -0,0 +1,21 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# + +{ + delete numbers + for (i = 1; i <= NF; i ++) { + numbers [$i] ++ + } + for (n in numbers) { + if (numbers [n] % 2) { + print n + } + } +} diff --git a/challenge-130/abigail/perl/ch-1.pl b/challenge-130/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..880d163861 --- /dev/null +++ b/challenge-130/abigail/perl/ch-1.pl @@ -0,0 +1,28 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See ../README.md +# + +# +# Run as: perl ch-1.pl < input-file +# +# We treat each line of input as a different case. Each line contains +# a set of integers, separated by non-digits. +# + +while (<>) { + my %numbers; + $numbers {$_} ++ for /[1-9][0-9]*/g; # Read in data + say grep {$numbers {$_} % 2} keys %numbers; # Print the one occuring + # an odd number of times +} |
