aboutsummaryrefslogtreecommitdiff
path: root/challenge-163/duncan-c-white/README
blob: 8a87ed6df01ade9b5b44fe883ee04503b66b90ba (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
TASK #1 - Sum Bitwise Operator

You are given list positive numbers, @n.

Write script to calculate the sum of bitwise & operator for all unique pairs.

Example 1

	Input: @n = (1, 2, 3)
	Output: 3

	Since (1 & 2) + (2 & 3) + (1 & 3) => 0 + 2 + 1 =>  3.

Example 2

	Input: @n = (2, 3, 4)
	Output: 2

	Since (2 & 3) + (2 & 4) + (3 & 4) => 2 + 0 + 0 =>  2.

MY NOTES: ok.  Pretty easy.  Identify all pairs, xor each, sum results.
	I did ch-1.pl and an optimized ch-1a.pl

GUEST LANGUAGE: As a bonus, I also had a go at translating ch-1a.pl
into C (look in the C directory for that), and then into Pascal
(look in the pascal directory for that).


TASK #2 - Summations

You are given a list of positive numbers, @n.

Write a script to find out the summations as described below.

Example 1

Input: @n = (1, 2, 3, 4, 5)
Output: 42

    1 2 3  4  5
      2 5  9 14
        5 14 28
          14 42
             42

The nth Row starts with the second element of the (n-1)th row.
The following element is sum of all elements except first element of previous row.
You stop once you have just one element in the row.

Example 2

Input: @n = (1, 3, 5, 7, 9)
Output: 70

    1 3  5  7  9
      3  8 15 24
         8 23 47
           23 70
              70

MY NOTES: hmmm.  Terrible explanation, but I think the examples show what
it means, which is quite easy.  Could do that in different languages too:-)

GUEST LANGUAGE: As a bonus, I also had a go at translating ch-2.pl
into C (look in the C directory for that), and then into Pascal
(look in the pascal directory for that).