aboutsummaryrefslogtreecommitdiff
path: root/challenge-160/duncan-c-white/README
blob: b73af0151fd80659515d7ed21b5d4b411b3f409c (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
TASK #1 - Four Is Magic

You are given a positive number, $n < 10.

Write a script to generate english text sequence starting with the English
cardinal representation of the given number, the word 'is' and then
the English cardinal representation of the count of characters that made
up the first word, followed by a comma. Continue until you reach four.

Example 1:

	Input: $n = 5
	Output: Five is four, four is magic.

Example 2:

	Input: $n = 7
	Output: Seven is five, five is four, four is magic.

Example 3:

	Input: $n = 6
	Output: Six is three, three is five, five is four, four is magic.

MY NOTES: ok.  Pretty easy.

GUEST LANGUAGE: As a bonus, I'd also have a go at translating ch-1.pl into C,
look in the C directory.


TASK #2 - Equilibrium Index

You are give an array of integers, @n.

Write a script to find out the Equilibrium Index of the given array, if found.

For an array A consisting n elements, index i is an equilibrium index
if the sum of elements of subarray A[0..i-1] is equal to the sum of
elements of subarray A[i+1..n-1].

Example 1:

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

Example 2:

	Input: @n = (1, 2, 3, 4, 5)
	Output: -1 as no Equilibrium Index found.

Example 3:

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

MY NOTES: ok.  Pretty easy.  Rather than recomputing sums each time,
let's keep track of "the sum before i" and "the sum after i" and
adjust them each pass..