blob: 28f5718a9a5960fc77633aacb64675b54e68177f (
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
|
Task 1: Missing Numbers
You are given an array of unique numbers. Write a script to find out
all missing numbers in the range 0..$n where $n is the array size.
Example 1
Input: @array = (0,1,3)
Output: 2
The array size i.e. total element count is 3, so the range is 0..3.
The missing number is 2 in the given array.
Example 2
Input: @array = (0,1)
Output: 2
The array size is 2, therefore the range is 0..2.
The missing number is 2.
MY NOTES: pretty easy.
GUEST LANGUAGE: As a bonus, I also had a go at translating ch-1.pl
into C (look in the C directory for the translation)
Task 2: Penny Piles
You are given an integer, $n > 0.
Write a script to determine the number of ways of putting $n pennies in a row of piles of ascending heights from left to right.
Example
Input: $n = 5
Output: 7
Since $n=5, there are 7 ways of stacking 5 pennies in ascending piles:
1 1 1 1 1
1 1 1 2
1 2 2
1 1 3
2 3
1 4
5
MY NOTES: not quite so easy, but doable. Sounds recursive to me.
Let's produce the array of answers too..
GUEST LANGUAGE: As a bonus, I also had a go at translating ch-2.pl
into C (look in the C directory for the translation)
|