diff options
| author | Abigail <abigail@abigail.be> | 2021-06-09 18:03:02 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-06-09 20:15:02 +0200 |
| commit | 3fe9fba9c9d2ec298020988b59ddf16dade7285f (patch) | |
| tree | 2c95969649117c985d1a5cc9c753be01abf32f29 /challenge-116/abigail/ruby | |
| parent | ef7ce9bd5bf986bd4f2d99e082013e5f895f0d9e (diff) | |
| download | perlweeklychallenge-club-3fe9fba9c9d2ec298020988b59ddf16dade7285f.tar.gz perlweeklychallenge-club-3fe9fba9c9d2ec298020988b59ddf16dade7285f.tar.bz2 perlweeklychallenge-club-3fe9fba9c9d2ec298020988b59ddf16dade7285f.zip | |
AWK, Bash, Lua, Node.js, Perl, Python, Ruby solutions for week 116, part 1
Diffstat (limited to 'challenge-116/abigail/ruby')
| -rw-r--r-- | challenge-116/abigail/ruby/ch-1.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-116/abigail/ruby/ch-1.rb b/challenge-116/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..a8e5c0d824 --- /dev/null +++ b/challenge-116/abigail/ruby/ch-1.rb @@ -0,0 +1,38 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb < input-file +# + +def make_chain (string, start) + if string == start + then return [start] + end + if 0 == string . index(start) + then tail = string [start . length, string . length] + result = make_chain(tail, (start . to_i + 1) . to_s) || + make_chain(tail, (start . to_i - 1) . to_s) + if result + then return result . unshift (start) + end + end + return nil + +end + +ARGF . each_line do + |line| + line . strip! + for i in 1 .. line . length do + start = line [0, i] + result = make_chain(line, start) + if result + then puts (result . join (",")) + break + end + end +end |
