diff options
| author | Abigail <abigail@abigail.freedom.nl> | 2022-02-08 20:41:01 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.freedom.nl> | 2022-02-08 20:41:01 +0100 |
| commit | c505ea725b0c148e1c8017b282d7f6b48a8236d8 (patch) | |
| tree | 7bc69674d9ea5b645f8d9353d1482f64072110d0 /challenge-151 | |
| parent | d77e2b954262d6a2299587cc83d572caa879b3de (diff) | |
| download | perlweeklychallenge-club-c505ea725b0c148e1c8017b282d7f6b48a8236d8.tar.gz perlweeklychallenge-club-c505ea725b0c148e1c8017b282d7f6b48a8236d8.tar.bz2 perlweeklychallenge-club-c505ea725b0c148e1c8017b282d7f6b48a8236d8.zip | |
Week 151: R solution for part 2
Diffstat (limited to 'challenge-151')
| -rw-r--r-- | challenge-151/abigail/r/ch-2.r | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-151/abigail/r/ch-2.r b/challenge-151/abigail/r/ch-2.r new file mode 100644 index 0000000000..5d2e166d4a --- /dev/null +++ b/challenge-151/abigail/r/ch-2.r @@ -0,0 +1,22 @@ +#!/usr/local/bin/Rscript + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151 +# + +# +# Run as: Rscript ch-2.r < input-file +# + +stdin <- file ('stdin', 'r') +repeat { + line <- readLines (stdin, n = 1) + if (length (line) == 0) { + break + } + h <- c (as.numeric (strsplit (line, " ") [[1]]), 0, 0) + for (i in seq (length (h) - 2, 3, -1)) { + h [[i]] <- max (c (h [[i]] + h [[i + 2]], h [[i + 1]])) + } + cat (h [[1]] + h [[3]], "\n") +} |
