aboutsummaryrefslogtreecommitdiff
path: root/challenge-130/andinus/README.org
blob: b8ce1afbfa7c91ef255b20805c5fe10bde8464f8 (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
#+title: Challenge 130
#+date: 2021-09-14
#+html_link_up: ../index.html
#+export_file_name: index
#+setupfile: ~/.emacs.d/org-templates/level-2.org

* Task 1 - Odd Number

You are given an array of positive integers, such that all the numbers
appear even number of times except one number.

Write a script to find that integer.

Examples:
#+begin_src
Input: @N = (2, 5, 4, 4, 5, 5, 2)
Output: 5 as it appears 3 times in the array where as all other numbers 2 and 4 appears exactly twice.

Input: @N = (1, 2, 3, 4, 3, 2, 1, 4, 4)
Output: 4
#+end_src

** Raku

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

~@nums~ holds the input and ~%seen~ is True if it's seen odd number of
times. We loop over ~@nums~ and invert the value of that number in ~%seen~.

#+begin_src raku
my Bool %seen;
%seen{$_} = !%seen{$_} for @nums;
put %seen.grep(*.value).map(*.key);
#+end_src