aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/andinus/README.org
blob: 07b7278cbf5aa4420f669cab9c90a72982cf1ca4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#+title: Challenge 115
#+date: 2021-06-02
#+html_link_up: ../index.html
#+export_file_name: index
#+setupfile: ~/.emacs.d/org-templates/level-2.org

* Task 2 - Largest Multiple

You are given a list of positive integers (0-9), single digit.

Write a script to find the largest multiple of 2 that can be formed from
the list.

#+begin_src
Input: @N = (1, 0, 2, 6)
Output: 6210

Input: @N = (1, 4, 2, 8)
Output: 8412

Input: @N = (4, 1, 7, 6)
Output: 7614
#+end_src

** Raku

- Program: [[file:raku/ch-2.raku]]

~@nums~ stores user entered numbers. The program terminates if there are
no even numbers in ~@nums~. We get the least even number & then just
reverse the rest of the sorted list & join them.

#+begin_src raku
@nums = @nums>>.Int.sort;
die "No even number!" unless @nums.grep(* %% 2);

my Int $least-even = @nums.splice(@nums.first(* %% 2, :k), 1).first;
say (|@nums.reverse, $least-even).join;
#+end_src