diff options
| author | Abigail <abigail@abigail.be> | 2021-05-04 12:33:07 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-05-04 12:33:07 +0200 |
| commit | 57ec29ba5148345cc41835591e77f567d70aa348 (patch) | |
| tree | 9201d23b9fd39bbc8d33e9325e93aca7673c8d3e /challenge-111/abigail/ruby | |
| parent | e674b457aa9a8912365f1ac52a1eaf4e3d386ddc (diff) | |
| download | perlweeklychallenge-club-57ec29ba5148345cc41835591e77f567d70aa348.tar.gz perlweeklychallenge-club-57ec29ba5148345cc41835591e77f567d70aa348.tar.bz2 perlweeklychallenge-club-57ec29ba5148345cc41835591e77f567d70aa348.zip | |
Ruby solution for week 111, part 2
Diffstat (limited to 'challenge-111/abigail/ruby')
| -rw-r--r-- | challenge-111/abigail/ruby/ch-2.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-111/abigail/ruby/ch-2.rb b/challenge-111/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..afe0361969 --- /dev/null +++ b/challenge-111/abigail/ruby/ch-2.rb @@ -0,0 +1,34 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-2.rb < input-file +# + +# +# Create a pattern to match words with their characters in +# lexicographical order. +# +pat = "^" +("a" .. "z") . each do + |letter| + pat += letter + "*" +end +pat += "$" + + +# +# Find matching words, and remember the longest. +# +longest = "" +ARGF . each_line do + |line| + if line . downcase =~ /#{pat}/ && line . length > longest . length + longest = line + end +end + +puts (longest) |
