From 3727157cf5707c0573bbfc73dae82cae7232fd34 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 8 Feb 2022 22:54:23 +0100 Subject: Solution to task 2 --- challenge-151/jo-37/perl/ch-2.pl | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 challenge-151/jo-37/perl/ch-2.pl diff --git a/challenge-151/jo-37/perl/ch-2.pl b/challenge-151/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..e038b43513 --- /dev/null +++ b/challenge-151/jo-37/perl/ch-2.pl @@ -0,0 +1,69 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use List::Util 'max'; +use experimental 'signatures'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <= 0; $house--) { + $booties[$house] = $valuables[$house] + + max 0, @booties[$house + 2 .. $#booties]; + } + + $booties[0]; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + is grand_raid(2, 4, 5), 7, 'example 1'; + is grand_raid(4, 2, 3, 6, 5, 3), 13, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + is grand_raid(1), 1, 'only one house'; + is grand_raid(2, 1), 2, 'two houses, first is best'; + is grand_raid(1, 2), 1, 'two houses, second is best'; + } + + done_testing; + exit; +} -- cgit