aboutsummaryrefslogtreecommitdiff
path: root/challenge-196/duncan-c-white/README
blob: bce30687f25554619714ebe1c66cc2ee6ab12653 (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
Task 1: Pattern 132

You are given a list of integers, @list.

Write a script to find out subsequence that respect Pattern 132. Return
empty array if none found.

Pattern 132 in a sequence (a[i], a[j], a[k]) such that i < j < k
and a[i] < a[k] < a[j].

Example 1

Input:  @list = (3, 1, 4, 2)
Output: (1, 4, 2) respect the Pattern 132.

Example 2

Input: @list = (1, 2, 3, 4)
Output: () since no subsequence can be found.

Example 3

Input: @list = (1, 3, 2, 4, 6, 5)
Output: (1, 3, 2) if more than one subsequence found then return the first.

Example 4

Input: @list = (1, 3, 4, 2)
Output: (1, 3, 2)

MY NOTES: very easy; straightforward "non-clever" code.

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: Range List

You are given a sorted unique integer array, @array.

Write a script to find all possible Number Range i.e [x, y] represent
range all integers from x and y (both inclusive).  Each subsequence
must be of two or more contiguous integers.

Example 1

Input: @array = (1,3,4,5,7)
Output: [3,5]

Example 2

Input: @array = (1,2,3,6,7,9)
Output: [1,3], [6,7]

Example 3

Input: @array = (0,1,2,4,5,6,8,9)
Output: [0,2], [4,6], [8,9]

MY NOTES: simple enough state machine while we walk over the array in 1-pass.

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)