diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-08-10 21:33:53 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-08-10 21:33:53 +0100 |
| commit | bd9eb24a17a7ed68df7e390960424e86c6a5b55d (patch) | |
| tree | b6b60f96e7627a0cacb7b8e3fb560eb975835cbb /challenge-073 | |
| parent | 8b436bbbe96c4fc03658c7f097aff7e983c92ce6 (diff) | |
| download | perlweeklychallenge-club-bd9eb24a17a7ed68df7e390960424e86c6a5b55d.tar.gz perlweeklychallenge-club-bd9eb24a17a7ed68df7e390960424e86c6a5b55d.tar.bz2 perlweeklychallenge-club-bd9eb24a17a7ed68df7e390960424e86c6a5b55d.zip | |
- Added solutions by E. Choroba.
Diffstat (limited to 'challenge-073')
| -rw-r--r-- | challenge-073/e-choroba/erlang/ch-1.erl | 24 | ||||
| -rw-r--r-- | challenge-073/e-choroba/erlang/ch-2.erl | 24 | ||||
| -rwxr-xr-x | challenge-073/e-choroba/perl/ch-1.pl (renamed from challenge-073/e-choroba/perl5/ch-1.pl) | 0 | ||||
| -rwxr-xr-x | challenge-073/e-choroba/perl/ch-2.pl (renamed from challenge-073/e-choroba/perl5/ch-2.pl) | 0 |
4 files changed, 48 insertions, 0 deletions
diff --git a/challenge-073/e-choroba/erlang/ch-1.erl b/challenge-073/e-choroba/erlang/ch-1.erl new file mode 100644 index 0000000000..fa45be6d47 --- /dev/null +++ b/challenge-073/e-choroba/erlang/ch-1.erl @@ -0,0 +1,24 @@ +-module(pwc073). +-export([min_sliding_window/2, smallest_neighbour/1]). + +min_sliding_window(List, WinSize) when length(List) < WinSize -> + []; +min_sliding_window(List, WinSize) -> + [lists:min(lists:sublist(List, WinSize)) + | min_sliding_window(lists:nthtail(1, List), WinSize)]. + +smallest_neighbour([H|T]) -> + [0 | smallest_neighbour(T, H)]. + +smallest_neighbour([], _Min) -> + []; +smallest_neighbour([H|T], Min) -> + [ case Min < H of + true -> Min; + false -> 0 + end + | smallest_neighbour(T, case H < Min of + true -> H; + false -> Min + end ) + ]. diff --git a/challenge-073/e-choroba/erlang/ch-2.erl b/challenge-073/e-choroba/erlang/ch-2.erl new file mode 100644 index 0000000000..fa45be6d47 --- /dev/null +++ b/challenge-073/e-choroba/erlang/ch-2.erl @@ -0,0 +1,24 @@ +-module(pwc073). +-export([min_sliding_window/2, smallest_neighbour/1]). + +min_sliding_window(List, WinSize) when length(List) < WinSize -> + []; +min_sliding_window(List, WinSize) -> + [lists:min(lists:sublist(List, WinSize)) + | min_sliding_window(lists:nthtail(1, List), WinSize)]. + +smallest_neighbour([H|T]) -> + [0 | smallest_neighbour(T, H)]. + +smallest_neighbour([], _Min) -> + []; +smallest_neighbour([H|T], Min) -> + [ case Min < H of + true -> Min; + false -> 0 + end + | smallest_neighbour(T, case H < Min of + true -> H; + false -> Min + end ) + ]. diff --git a/challenge-073/e-choroba/perl5/ch-1.pl b/challenge-073/e-choroba/perl/ch-1.pl index f91a18417c..f91a18417c 100755 --- a/challenge-073/e-choroba/perl5/ch-1.pl +++ b/challenge-073/e-choroba/perl/ch-1.pl diff --git a/challenge-073/e-choroba/perl5/ch-2.pl b/challenge-073/e-choroba/perl/ch-2.pl index 17ccef9fe3..17ccef9fe3 100755 --- a/challenge-073/e-choroba/perl5/ch-2.pl +++ b/challenge-073/e-choroba/perl/ch-2.pl |
