aboutsummaryrefslogtreecommitdiff
path: root/challenge-206/duncan-c-white/README
blob: 7fd1e708585f3369e8f8796cdbbf3ba1115ff62a (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
67
68
Task 1: Shortest Time

You are given a list of time points, at least 2, in the 24-hour clock
format HH:MM.  Write a script to find out the shortest time in minutes
between any two time points.

Example 1

  Input: @time = ("00:00", "23:55", "20:00")
  Output: 5

  Since the difference between "00:00" and "23:55" is the shortest (5 minutes).

Example 2

  Input: @array = ("01:01", "00:50", "00:57")
  Output: 4

Example 3

  Input: @array = ("10:10", "09:30", "09:00", "09:55")
  Output: 15

MY NOTES: reasonably easy, although of course wraparound has to taken
into account.  Might convert each hh:mm time into a number of minutes,
then sort the array.. then check every adjacant pair (including the
wraparound pair, i.e the last and the first)..

GUEST LANGUAGE: As a bonus (but a day after the challenge finished), I also
had a go at translating ch-1.pl into C (look in the C directory for that)


Task 2: Array Pairings

You are given an array of integers having even number of elements..
Write a script to find the maximum sum of the minimum of each pairs.

Example 1

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

  Possible Pairings are as below:
  a) (1,2) and (3,4). So min(1,2) + min(3,4) => 1 + 3 => 4
  b) (1,3) and (2,4). So min(1,3) + min(2,4) => 1 + 2 => 3
  c) (1,4) and (2,3). So min(1,4) + min(2,3) => 2 + 1 => 3

  So the maxium sum is 4.

Example 2

  Input: @array = (0,2,1,3)
  Output: 2

  Possible Pairings are as below:
  a) (0,2) and (1,3). So min(0,2) + min(1,3) => 0 + 1 => 1
  b) (0,1) and (2,3). So min(0,1) + min(2,3) => 0 + 2 => 2
  c) (0,3) and (2,1). So min(0,3) + min(2,1) => 0 + 1 => 1
  
  So the maximum sum is 2.

MY NOTES: hmm. I wish one of the examples had 6 elements.  It seems
to me that this sounds like a recursive solution..  Pick each possible
pair involving the first element and each of the others (in turn),
remove them, calculate and total up the minimum, then recurse.

GUEST LANGUAGE: As a bonus (but a day after the challenge finished), I also
had a go at translating ch-2.pl into C (look in the C directory for that)